Synapses 7.0.2
See the version list below for details.
dotnet add package Synapses --version 7.0.2
NuGet\Install-Package Synapses -Version 7.0.2
<PackageReference Include="Synapses" Version="7.0.2" />
paket add Synapses --version 7.0.2
#r "nuget: Synapses, 7.0.2"
// Install Synapses as a Cake Addin #addin nuget:?package=Synapses&version=7.0.2 // Install Synapses as a Cake Tool #tool nuget:?package=Synapses&version=7.0.2
Synapses
Lightweight cross-platform Neural Network library
Installation
- JavaScript
Run npm i synapses
in the directory of your node project.
- Scala
Add this line to the list of sbt libraryDependencies
.
"synapses" % "scala_2.13" % "0.2" from "https://github.com/mrdimosthenis/Synapses/releases/download/0.2/synapses-assembly-0.2.jar"
- F#
Run dotnet add package Synapses --version 7.0.2
in the directory of your project.
Usage
Create a neural network
Import Synapses
, call NeuralNetwork.init
and provide the size of each layer:
- JavaScript
require('synapses');
let layers = [4, 6, 5, 3];
let neuralNetwork = NeuralNetwork.init(layers);
- Scala
import synapses.Library._
val layers = List(4, 6, 5, 3)
val neuralNetwork = NeuralNetwork.init(layers)
- F#
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
- JavaScript
let inputValues = [1.0, 0.5625, 0.511111, 0.47619];
let prediction = NeuralNetwork.prediction(neuralNetwork, inputValues);
- Scala
val inputValues = List(1.0, 0.5625, 0.511111, 0.47619)
val prediction = NeuralNetwork.prediction(neuralNetwork, inputValues)
- F#
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
- JavaScript
let learningRate = 0.5;
let expectedOutput = [0.0, 1.0, 0.0];
let fitNetwork = NeuralNetwork.fit(neuralNetwork, learningRate, inputValues, expectedOutput);
- Scala
val learningRate = 0.5
val expectedOutput = List(0.0, 1.0, 0.0)
val fitNetwork = NeuralNetwork.fit(neuralNetwork, learningRate, inputValues, expectedOutput)
- F#
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
- JavaScript
let json = NeuralNetwork.toJson(fitNetwork);
- Scala
val json = NeuralNetwork.toJson(fitNetwork)
- F#
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.
JSON instances are compatible across platforms! We can generate, train and save a neural network in Scala and then load and make predictions in Javascript!
- JavaScript
let loadedNetwork = NeuralNetwork.ofJson(json);
- Scala
val loadedNetwork = NeuralNetwork.ofJson(json)
- F#
let loadedNetwork = NeuralNetwork.ofJson(json)
As the name suggests, NeuralNetwork.ofJson
turns a json string into a neural network.
Customize a neural network
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
.
- JavaScript
function activationF(layerIndex) {
switch (layerIndex) {
case 0:
return ActivationFunction.sigmoid;
case 1:
return ActivationFunction.identity;
case 2:
return ActivationFunction.leakyReLU;
case 3:
return ActivationFunction.tanh;
}
}
function weightInitF(_layerIndex) {
return 1.0 - 2.0 * Math.random();
}
let customizedNetwork = NeuralNetwork.customizedInit(layers, activationF, weightInitF);
- Scala
def activationF(layerIndex: Int): ActivationFunction =
layerIndex match {
case 0 => ActivationFunction.sigmoid
case 1 => ActivationFunction.identity
case 2 => ActivationFunction.leakyReLU
case 3 => ActivationFunction.tanh
}
def weightInitF(_layerIndex: Int): Double = 1.0 - 2.0 * new Random().nextDouble()
val customizedNetwork = NeuralNetwork.customizedInit(layers, activationF, weightInitF)
- F#
let activationF (layerIndex: int)
: ActivationFunction =
match layerIndex with
| 0 -> ActivationFunction.sigmoid
| 1 -> ActivationFunction.tanh
| 2 -> ActivationFunction.leakyReLU
| _ -> ActivationFunction.identity
let weightInitF (_layerIndex: int): float = 1.0 - 2.0 * System.Random().NextDouble()
let customizedNetwork = NeuralNetwork.customizedInit(layers, activationF, weightInitF)
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 | 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. |
.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.1.1)
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 | 603 | 2/21/2021 |
7.3.1 | 654 | 4/12/2020 |
7.3.0 | 633 | 3/8/2020 |
7.2.1 | 628 | 2/2/2020 |
7.1.1 | 660 | 1/12/2020 |
7.1.0 | 487 | 1/5/2020 |
7.0.2 | 490 | 12/28/2019 |
7.0.0 | 470 | 12/25/2019 |
6.0.0 | 460 | 12/25/2019 |
5.0.0 | 471 | 12/14/2019 |
4.1.0 | 488 | 12/8/2019 |
4.0.1 | 492 | 12/1/2019 |
4.0.0 | 483 | 11/29/2019 |
3.0.1 | 515 | 11/27/2019 |
3.0.0 | 492 | 11/27/2019 |
2.0.0 | 513 | 11/26/2019 |
1.0.1 | 498 | 11/25/2019 |
1.0.0 | 512 | 11/24/2019 |