/// <summary> /// Create a feedforward freeform neural network. /// </summary> /// <param name="input">The input count.</param> /// <param name="hidden1">The first hidden layer count, zero if none.</param> /// <param name="hidden2">The second hidden layer count, zero if none.</param> /// <param name="output">The output count.</param> /// <param name="af">The activation function.</param> /// <returns>The newly crated network.</returns> public static FreeformNetwork CreateFeedforward(int input, int hidden1, int hidden2, int output, IActivationFunction af) { var network = new FreeformNetwork(); IFreeformLayer lastLayer = network.CreateInputLayer(input); IFreeformLayer currentLayer; if (hidden1 > 0) { currentLayer = network.CreateLayer(hidden1); network.ConnectLayers(lastLayer, currentLayer, af, 1.0, false); lastLayer = currentLayer; } if (hidden2 > 0) { currentLayer = network.CreateLayer(hidden2); network.ConnectLayers(lastLayer, currentLayer, af, 1.0, false); lastLayer = currentLayer; } currentLayer = network.CreateOutputLayer(output); network.ConnectLayers(lastLayer, currentLayer, af, 1.0, false); network.Reset(); return(network); }
/// <summary> /// Construct an Elmann recurrent neural network. /// </summary> /// <param name="input">The input count.</param> /// <param name="hidden1">The hidden count.</param> /// <param name="output">The output count.</param> /// <param name="af">The activation function.</param> /// <returns>The newly created network.</returns> public static FreeformNetwork CreateElman(int input, int hidden1, int output, IActivationFunction af) { var network = new FreeformNetwork(); IFreeformLayer inputLayer = network.CreateInputLayer(input); IFreeformLayer hiddenLayer1 = network.CreateLayer(hidden1); IFreeformLayer outputLayer = network.CreateOutputLayer(output); network.ConnectLayers(inputLayer, hiddenLayer1, af, 1.0, false); network.ConnectLayers(hiddenLayer1, outputLayer, af, 1.0, false); network.CreateContext(hiddenLayer1, hiddenLayer1); network.Reset(); return(network); }
public static double TrainNetwork(String what, FreeformNetwork network, IMLDataSet trainingSet) { ICalculateScore score = new TrainingSetScore(trainingSet); IMLTrain trainAlt = new NeuralSimulatedAnnealing( network, score, 10, 2, 100); IMLTrain trainMain = new FreeformBackPropagation(network, trainingSet,0.00001, 0.0); StopTrainingStrategy stop = new StopTrainingStrategy(); trainMain.AddStrategy(new Greedy()); trainMain.AddStrategy(new HybridStrategy(trainAlt)); trainMain.AddStrategy(stop); EncogUtility.TrainToError(trainMain, 0.01); return trainMain.Error; }
public void Execute(IExampleInterface app) { // create a neural network, without using a factory var network = new BasicNetwork(); network.AddLayer(new BasicLayer(null, true, 2)); network.AddLayer(new BasicLayer(new ActivationSigmoid(), true, 3)); network.AddLayer(new BasicLayer(new ActivationSigmoid(), false, 1)); network.Structure.FinalizeStructure(); network.Reset(); // create training data var trainingSet = new BasicMLDataSet(XORInput, XORIdeal); EncogUtility.TrainToError(network, trainingSet, 0.01); EncogUtility.Evaluate(network, trainingSet); var ff = new FreeformNetwork(network); EncogUtility.Evaluate(ff, trainingSet); EncogFramework.Instance.Shutdown(); }
public void Execute(IExampleInterface app) { // create a neural network, without using a factory var network = new FreeformNetwork(); IFreeformLayer inputLayer = network.CreateInputLayer(2); IFreeformLayer hiddenLayer1 = network.CreateLayer(3); IFreeformLayer outputLayer = network.CreateOutputLayer(1); network.ConnectLayers(inputLayer, hiddenLayer1, new ActivationSigmoid(), 1.0, false); network.ConnectLayers(hiddenLayer1, outputLayer, new ActivationSigmoid(), 1.0, false); network.Reset(); // create training data IMLDataSet trainingSet = new BasicMLDataSet(XORInput, XORIdeal); EncogUtility.TrainToError(network, trainingSet, 0.01); EncogUtility.Evaluate(network, trainingSet); EncogFramework.Instance.Shutdown(); }
public void Validate(FreeformNetwork network) { network.ClearContext(); XOR.VerifyXOR(network, 0.1); }
/// <summary> /// Create a feedforward freeform neural network. /// </summary> /// <param name="input">The input count.</param> /// <param name="hidden1">The first hidden layer count, zero if none.</param> /// <param name="hidden2">The second hidden layer count, zero if none.</param> /// <param name="output">The output count.</param> /// <param name="af">The activation function.</param> /// <returns>The newly crated network.</returns> public static FreeformNetwork CreateFeedforward(int input, int hidden1, int hidden2, int output, IActivationFunction af) { var network = new FreeformNetwork(); IFreeformLayer lastLayer = network.CreateInputLayer(input); IFreeformLayer currentLayer; if (hidden1 > 0) { currentLayer = network.CreateLayer(hidden1); network.ConnectLayers(lastLayer, currentLayer, af, 1.0, false); lastLayer = currentLayer; } if (hidden2 > 0) { currentLayer = network.CreateLayer(hidden2); network.ConnectLayers(lastLayer, currentLayer, af, 1.0, false); lastLayer = currentLayer; } currentLayer = network.CreateOutputLayer(output); network.ConnectLayers(lastLayer, currentLayer, af, 1.0, false); network.Reset(); return network; }
/// <summary> /// Construct an Elmann recurrent neural network. /// </summary> /// <param name="input">The input count.</param> /// <param name="hidden1">The hidden count.</param> /// <param name="output">The output count.</param> /// <param name="af">The activation function.</param> /// <returns>The newly created network.</returns> public static FreeformNetwork CreateElman(int input, int hidden1, int output, IActivationFunction af) { var network = new FreeformNetwork(); IFreeformLayer inputLayer = network.CreateInputLayer(input); IFreeformLayer hiddenLayer1 = network.CreateLayer(hidden1); IFreeformLayer outputLayer = network.CreateOutputLayer(output); network.ConnectLayers(inputLayer, hiddenLayer1, af, 1.0, false); network.ConnectLayers(hiddenLayer1, outputLayer, af, 1.0, false); network.CreateContext(hiddenLayer1, hiddenLayer1); network.Reset(); return network; }