Skip to content

Constructing the Artificial Neural Network

MarcoMeter edited this page Apr 21, 2016 · 5 revisions

This page describes how to construct an Artificial Neural Network using the Machine Learning Framework Encog.

Encog C# API References

Encog C# User Guide

Network Structure

Several imports need to be done:

using Encog.Engine.Network.Activation;
using Encog.Neural.Networks;
using Encog.Neural.Networks.Layers;

After that, a BasicNetwork can be instantiated and configured:

BasicNetwork network = new BasicNetwork();
// Add the Input layer, which doesn't need an activation function, but provides bias weights and a certain amount of perceptrons
network.AddLayer(new BasicLayer(null, true, 9));
// Add the Hidden Layer, which makes use of some activation function with a specific amount of perceptrons holding a bias weight
network.AddLayer(new BasicLayer(new ActivationSigmoid(), true, 32));
// Add the Output Layer, which perceptrons use an activation function without using bias weights
network.AddLayer(new BasicLayer(new ActivationSigmoid(), false, 8));
// Build the synapse and layer structure of the ANN using FinalizeStructure()
network.Structure.FinalizeStructure();
// Calling Reset() will initialize random weights on each synapse
network.Reset();

Persistence

using Encog.Persist;

In order to save the ANN to a file call:

EncogDirectoryPersistence.SaveObject(new System.IO.FileInfo("testNetwork.ann"), network);

Loading is done using:

BasicNetwork network = (BasicNetwork)EncogDirectoryPersistence.LoadObject(new FileInfo("testNetwork.ann"));

Feedforward

First of all the Input object for the neural net if os type IMLData, which can be instantiated based on a double[].

IMLData input = new BasicMLData(inputData);

There are quite some options in order to feed the input forward like Classify(), Compute() and Winner():

CombatUnitState currentState = (CombatUnitState)network.Classify(input);