EmilianoMusso.NeuralNetwork 1.5.0

.NET Framework
dotnet add package EmilianoMusso.NeuralNetwork --version 1.5.0
NuGet\Install-Package EmilianoMusso.NeuralNetwork -Version 1.5.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="EmilianoMusso.NeuralNetwork" Version="1.5.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EmilianoMusso.NeuralNetwork --version 1.5.0
#r "nuget: EmilianoMusso.NeuralNetwork, 1.5.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install EmilianoMusso.NeuralNetwork as a Cake Addin
#addin nuget:?package=EmilianoMusso.NeuralNetwork&version=1.5.0

// Install EmilianoMusso.NeuralNetwork as a Cake Tool
#tool nuget:?package=EmilianoMusso.NeuralNetwork&version=1.5.0

Please check the following documentation for a quick overview on the library, and how to use it

Using Namespace

using emNeuralNet;


  • NeuralNetwork
  • Layer
  • Neuron
  • Dendrite
  • ActivationFunctions
  • NeuralData
  • RandomGenerator

NeuralNetwork class

Probably the only class you will directly refer into your projects, being other classes used by it. Initialize a NeuralNetwork is done by:

NeuralNetwork nw = new NeuralNetwork(1.25, new int[]{ 2, 2, 1 }, ActivationFunctions.Activation.SIGMOID, "TestNet");

The first parameter of constructor is the learning rate, the second one (an array of int) define how many layers are in our network (in the example, 3 layers) and their number indicates respectively how many neurons to create for that layer (in the example: layer 1 has 2 neurons, layer 2 has 2 neurons, and layer 3 has a single neuron). ActivationFunction can be SIGMOID, TANH, STEP. The last parameter is the network name (optional).

Networks can be trained with Train() method: NeuralData outx = new NeuralData(0); nw.Train(new NeuralData(0, 0), outx, 5);

In the above example, we'll use the NeuralData class for input feeding and output retrieving. The first line means outx will have a single value (in this case, is an expected result) of zero. While training, we use a new NeuralData with two input values of zero and zero. That means we'll execute 5 iterations with two inputs of zero value, and we expect our network to return a single value of zero.

NeuralData has also a static method to quickly convert an integer to binary representation, with leading zeros. Its useful when you want to translate a numerical value to a set of binary values. For example, lets suppose to have five input neurons, and we want to initialize the input neurons with value 10:

var ndata = new NeuralData( NeuralData.ConvertToBinary(10, 5) );

In the above line, 10 is the value we desire to translate to binary, and 5 is the number of neurons our input value must be splitted on. After that instruction, nData will be an array of double, containing the values 0 1 0 1 0, being more apt to be passed at our input layer.

A neural network can be executed with Run() method. For example:

NeuralData outp = nw.Run(new NeuralData(0, 0));

Our network will run with two input values (zero and zero), and returns its result into the outp variable.

NeuralNetwork class has at the moment two methods to give a representation of itself:

  • ToString(), which returns text informations about the network itself (number of layers, neurons, biases, delta, value, and so on)
  • SaveImage(), which will save a 1600x1200 jpg file graphically representing the network in the given location

Other usefule methods are Save() and Load(): those methods will come in handy to save to a file a trained network status, and being able to restore it later

RandomGenerator class

The class is mainly used in neuron bias and dendrite weight random initialization. It achieves a better randomness ratio than the standard .NET Random class, because it uses RNGCryptoServiceProvider class. If you wish to use it externally to the purposes of the neural network context, a typical calling for the class would be:

RandomGenerator gen = new RandomGenerator(); double rand_value = gen.RandomValue;

ActivationFunctions class

ActivationFunction is internally used to execute a different function in setting the neurons value during training. Current release allows three activation functions, being them:

  • Sigmoid
  • TanH
  • Step

NeuralNetwork class will call the Activate() method during training, passing as parameters the chosen activation function, and the input data.

The library code relies - for the part concerning the core of neural network - on what was presented in the article Basis of Neural Networks in C#, which i wrote in December 2016. Here you could read a more in-depth analysis about neural networks in general.

Product Versions
.NET Framework net net452 net46 net461 net462 net463 net47 net471 net472 net48 net481
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.5.0 1,414 11/21/2017
1.0.0 1,180 11/17/2017

Added extension methods to simplify NN-related code