Synapses 7.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Synapses --version 7.0.0
NuGet\Install-Package Synapses -Version 7.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Synapses" Version="7.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Synapses --version 7.0.0
#r "nuget: Synapses, 7.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Synapses as a Cake Addin
#addin nuget:?package=Synapses&version=7.0.0

// Install Synapses as a Cake Tool
#tool nuget:?package=Synapses&version=7.0.0

Synapses

Neural network library in F#

Installation

Run dotnet add package Synapses --version 7.0.0 in the directory of your project.

Usage

Create a neural network

Open Synapses, call NeuralNetwork.init and provide the size of each layer:

open Synapses

let layers = [4; 6; 5; 3]

let neuralNetwork = NeuralNetwork.init(layers)

neuralNetwork has 4 layers. The first layer has 4 input nodes and the last layer has 3 output nodes. There are 2 hidden layers with 6 and 5 neurons respectively.

Get a prediction

let inputValues = [ 1.0; 0.5625; 0.511111; 0.47619 ]

let prediction = NeuralNetwork.prediction(neuralNetwork, inputValues)

prediction should be something like [ 0.829634; 0.699651; 0.454185 ]. Note that the lengths of inputValues and prediction equal to the sizes of input and output layers respectively.

Fit network

let learningRate = 0.5

let expectedOutput = [ 0.0; 1.0; 0.0 ]

let fitNetwork =
        NeuralNetwork.fit(neuralNetwork, learningRate, inputValues, expectedOutput)

fitNetwork is a new neural network trained with a single observation.

Save and load a neural network

let json = NeuralNetwork.toJson(fitNetwork)

Call NeuralNetwork.toJson on a neural network and get a string representation of it. Use it as you like. Save json in the file system or insert into a database table.

let loadedNetwork = NeuralNetwork.ofJson(json)

As the name suggests, NeuralNetwork.ofJson turns a json string into a neural network.

Customize a neural network

let activationF (layerIndex: int)
        : ActivationFunction =
        match layerIndex with
        | 0 -> ActivationFunction.sigmoid
        | 1 -> ActivationFunction.tanh
        | 2 -> ActivationFunction.leakyReLU
        | _ -> ActivationFunction.identity

let weightInitF (_layerIndex: int): float =
        System.Random().NextDouble()

let customizedNetwork =
        NeuralNetwork.customizedInit(layers, activationF, weightInitF)

The activation function of the neurons created with NeuralNetwork.init, is a sigmoid one. If you want to customize the activation functions and the weight distribution, call NeuralNetwork.customizedInit.

Encoding and decoding

One hot encoding is a process that turns discrete attributes into a list of 0.0 and 1.0. Minmax normalization scales continuous attributes into values between 0.0 and 1.0. You can use DataPreprocessor for datapoint encoding and decoding.

The first parameter of DataPreprocessor.init is a list of tuples (attributeName, discreteOrNot).

let setosaDatapoint =
        Map.ofList
            [ ("petal_length", "1.5")
              ("petal_width", "0.1")
              ("sepal_length", "4.9")
              ("sepal_width", "3.1")
              ("species", "setosa") ]

let versicolorDatapoint =
        Map.ofList
            [ ("petal_length", "3.8")
              ("petal_width", "1.1")
              ("sepal_length", "5.5")
              ("sepal_width", "2.4")
              ("species", "versicolor") ]

let virginicaDatapoint =
        Map.ofList
            [ ("petal_length", "6.0")
              ("petal_width", "2.2")
              ("sepal_length", "5.0")
              ("sepal_width", "1.5")
              ("species", "virginica") ]

let dataset = Seq.ofList
                [ setosaDatapoint
                  versicolorDatapoint
                  virginicaDatapoint ]
                
let dataPreprocessor = DataPreprocessor.init(
                            [ ("sepal_length", false)
                              ("sepal_width", false)
                              ("petal_length", false)
                              ("petal_width", false)
                              ("species", true) ],
                            dataset
                       )

let encodedDatapoints =
        Seq.map (fun datapoint -> DataPreprocessor.encodedDatapoint(dataPreprocessor, datapoint))
                dataset

encodedDatapoints equals to

[ [ 0.0     ; 1.0     ; 0.0     ; 0.0     ; 0.0; 0.0; 1.0 ]
  [ 1.0     ; 0.562500; 0.511111; 0.476190; 0.0; 1.0; 0.0 ]
  [ 0.166667; 0.0     ; 1.0     ; 1.0     ; 1.0; 0.0; 0.0 ] ]

Save and load the preprocessor by calling DataPreprocessor.toJson and DataPreprocessor.ofJson.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Synapses:

Package Downloads
SynapsesCSharp

A lightweight library for neural networks that runs anywhere

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
7.4.1 543 2/21/2021
7.3.1 616 4/12/2020
7.3.0 596 3/8/2020
7.2.1 596 2/2/2020
7.1.1 616 1/12/2020
7.1.0 465 1/5/2020
7.0.2 463 12/28/2019
7.0.0 443 12/25/2019
6.0.0 432 12/25/2019
5.0.0 450 12/14/2019
4.1.0 458 12/8/2019
4.0.1 464 12/1/2019
4.0.0 460 11/29/2019
3.0.1 490 11/27/2019
3.0.0 465 11/27/2019
2.0.0 489 11/26/2019
1.0.1 475 11/25/2019
1.0.0 492 11/24/2019