Prototype for recognition of handwritten digits.
Repo includes following components:
- convolutional neural network (CNN) as a base component;
- back-propagation training algorithms;
- simple GUI app to demonstrate NN working process.
You may create your own builder with specific logic for your NN. Or simply use existing builder named NeuralNetworkBuilder.
INeuralNetworkBuilder<double> networkBuilder = new NeuralNetworkBuilder<double>();
By default the the library has already the default implementation of factory for NN.
public class SpecificNeuralNetworkFactory : INeuralNetworkFactory<double>
{
...
}
Additionally, you can configure different schemes of connections between layers in case multi-layer NN. And if you want to connect layers using any specific logic - just create a specific implementation of IConnectionScheme interface.
For example, scheme to connect each neurons with each other (fully-connected layers), specified below:
public class FullyConnectedScheme<TData>
: IConnectionScheme<INeuron<TData>, IConnectionFactory<TData, TData>>
{
private IConnectionFactory<TData, TData> connectionFactory;
public void SetConnectionFactory(IConnectionFactory<TData, TData> factory)
{
connectionFactory = factory;
}
public void Apply(
ILayer<INeuron<TData>, IConnectionFactory<TData, TData>> leftLayer,
ILayer<INeuron<TData>, IConnectionFactory<TData, TData>> rightLayer)
{
foreach (INeuron<TData> currentRightNeuron in rightLayer.Neurons)
{
foreach (INeuron<TData> currentLeftNeuron in leftLayer.Neurons)
{
currentRightNeuron.Inputs.Add(connectionFactory.Create(currentLeftNeuron));
currentLeftNeuron.Outputs.Add(connectionFactory.Create(currentRightNeuron));
}
}
}
}
The example, specified below, shows how to create a neural network with three layers which connected using FullyConnectedScheme scheme.
IMultiLayerNeuralNetwork<double> neuralNetwork = networkBuilder
.AddInputLayer(new Layer(0, 3, true, false))
.AddLayer<FullyConnectedScheme<double>>(new Layer(1, 5, false, false))
.AddLayer<FullyConnectedScheme<double>>(new Layer(2, 2, false, true))
.Build<NeuralNetworkFactory>() as IMultiLayerNeuralNetwork<double>;