Synapses 4.0.1
See the version list below for details.
dotnet add package Synapses --version 4.0.1
NuGet\Install-Package Synapses -Version 4.0.1
<PackageReference Include="Synapses" Version="4.0.1" />
paket add Synapses --version 4.0.1
#r "nuget: Synapses, 4.0.1"
// Install Synapses as a Cake Addin #addin nuget:?package=Synapses&version=4.0.1 // Install Synapses as a Cake Tool #tool nuget:?package=Synapses&version=4.0.1
Synapses
Neural network library in F#
Installation
Run dotnet add package Synapses --version 4.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
inputValues
neuralNetwork
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
learningRate
inputValues
expectedOutput
neuralNetwork
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.fromJson
json
As the name suggests, NeuralNetwork.fromJson
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 (DataPreprocessor.encodedDatapoint dataPreprocessor)
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.fromJson
.
Product | Versions 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.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. |
-
.NETStandard 2.0
- FSharp.Core (>= 4.7.0)
- FSharp.SystemTextJson (>= 0.6.2)
- FSharpx.Collections (>= 2.0.0)
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 | 624 | 2/21/2021 |
7.3.1 | 665 | 4/12/2020 |
7.3.0 | 647 | 3/8/2020 |
7.2.1 | 640 | 2/2/2020 |
7.1.1 | 672 | 1/12/2020 |
7.1.0 | 502 | 1/5/2020 |
7.0.2 | 501 | 12/28/2019 |
7.0.0 | 482 | 12/25/2019 |
6.0.0 | 474 | 12/25/2019 |
5.0.0 | 482 | 12/14/2019 |
4.1.0 | 498 | 12/8/2019 |
4.0.1 | 503 | 12/1/2019 |
4.0.0 | 494 | 11/29/2019 |
3.0.1 | 526 | 11/27/2019 |
3.0.0 | 503 | 11/27/2019 |
2.0.0 | 524 | 11/26/2019 |
1.0.1 | 510 | 11/25/2019 |
1.0.0 | 524 | 11/24/2019 |