Encog create simple network

Hello everybody,

today I want to share how to create simple neural network in Encog. It's very simple process:

var network = BasicNetwork();

Each neural network have layer. 

Example of layer creating: 

network.AddLayer(new BasicLayer(new ActivationSigmoid(), true, 5));

The first paramether of BasicLayer is activation function, which is in our case ActivationSigmoid,

The second paramether is Bias neuron. True means that layer will have bias layer also. 

The third paramether represents number of neurons in layer. 

If you think that creating network is enough for training, you are wrong. As a lot of staff in our world, in Encog you need to call FinalizeStructure. It looks like this:

network.Structure.FinalizeStructure();
If you think, that FinalizeStructure is the last step, then one more disappointment. You also need to call:
network.Reset();

The last operator will init network with initial set of random numbers.

If to collect it all together in one function it will look like this:

public static BasicNetwork CreateNeuralNetwork()
{
    var network = new BasicNetwork();
    network.AddLayer(new BasicLayer(null, true, 2));
    network.AddLayer(new BasicLayer(new ActivationSigmoid(), true, 5));
    network.AddLayer(new BasicLayer(new ActivationSigmoid(), false, 3));
    network.Structure.FinalizeStructure();
    network.Reset();
    return network();
}

It will give you neural network with three layers. The first layer has two neurons, and doesn't use any activation function. The second layer uses sigmoid as activation function, and has bias. The third layer uses also ActivationSigmoid but doesn't have bias neuron.  FinalizeStructure can be also considered as saying to Encog that we done with NN constructing.

No Comments

Add a Comment