Inheritance: IActivationFunction, ICloneable
Esempio n. 1
0
        /// <summary>
        /// Clone the object.
        /// </summary>
        /// <returns>The cloned object.</returns>
        public object Clone()
        {
            ActivationStep result = new ActivationStep(Low, Center,
                                                       High);

            return(result);
        }
        private NEATPopulation Generate()
        {
            IMLDataSet trainingSet = new BasicMLDataSet(XOR.XORInput, XOR.XORIdeal);

            ICalculateScore score = new TrainingSetScore(trainingSet);
            // train the neural network
            ActivationStep step = new ActivationStep();
            step.Center = 0.5;

            NEATTraining train = new NEATTraining(
                    score, 2, 1, 10);

            return (NEATPopulation)train.Population;
        }
Esempio n. 3
0
        /// <summary>
        /// Program entry point.
        /// </summary>
        /// <param name="app">Holds arguments and other info.</param>
        public void Execute(IExampleInterface app)
        {
            IMLDataSet trainingSet = new BasicMLDataSet(XORInput, XORIdeal);
            var pop = new NEATPopulation(2, 1, 1000);
            ICalculateScore score = new TrainingSetScore(trainingSet);
            // train the neural network
            var step = new ActivationStep();
            step.Center = 0.5;
            pop.OutputActivationFunction = step;

            var train = new NEATTraining(score, pop);

            EncogUtility.TrainToError(train, 0.01);

            var network = (NEATNetwork) train.Method;

            network.ClearContext();
            // test the neural network
            Console.WriteLine(@"Neural Network Results:");
            EncogUtility.Evaluate(network, trainingSet);
        }
        private void trainNetworkBackprop()
        {
            // IMLTrain train = new Backpropagation(this.network, this.input,this.ideal, 0.000001, 0.1);

            IMLDataSet aset = new BasicMLDataSet(input, ideal);
            int epoch = 1;
            // train the neural network
            ICalculateScore score = new TrainingSetScore(aset);
            IMLTrain trainAlt = new NeuralSimulatedAnnealing(network, score, 10, 2, 100);
            IMLTrain trainMain = new Backpropagation(network, aset, 0.001, 0.0);
            StopTrainingStrategy stop = new StopTrainingStrategy();
            var pop = new NEATPopulation(INPUT_SIZE, OUTPUT_SIZE, 1000);
            // train the neural network
            var step = new ActivationStep();
            step.Center = 0.5;
            pop.OutputActivationFunction = step;
            var train = new NEATTraining(score, pop);
            trainMain.AddStrategy(new Greedy());
            trainMain.AddStrategy(new HybridStrategy(trainAlt));
            trainMain.AddStrategy(stop);
            trainMain.AddStrategy(new HybridStrategy(train));

            network.ClearContext();

            while (!stop.ShouldStop())
            {
                trainMain.Iteration();
                train.Iteration();
                Console.WriteLine(@"Training " + @"Epoch #" + epoch + @" Error:" + trainMain.Error+ @" Genetic iteration:"+trainAlt.IterationNumber+ @"neat iteration:"+train.IterationNumber );
                epoch++;
            }
        }
        private NEATPopulation Generate()
        {
            IMLDataSet trainingSet = new BasicMLDataSet(XOR.XORInput, XOR.XORIdeal);

            ICalculateScore score = new TrainingSetScore(trainingSet);
            // train the neural network
            ActivationStep step = new ActivationStep();
            step.Center = 0.5;

            IEvolutionaryAlgorithm train = NEATUtil.ConstructNEATTrainer(
                    score, 2, 1, 10);

            return (NEATPopulation)train.Population;
        }
Esempio n. 6
0
 /// <summary>
 /// Clone the object.
 /// </summary>
 /// <returns>The cloned object.</returns>
 public object Clone()
 {
     var result = new ActivationStep(Low, Center,
                                     High);
     return result;
 }
        private NEATNetwork Create()
        {
            IList<NEATNeuron> neurons = new List<NEATNeuron>();
            IActivationFunction afSigmoid = new ActivationSigmoid();
            IActivationFunction afStep = new ActivationStep();

            // create the neurons
            NEATNeuron input1 = new NEATNeuron(
                    NEATNeuronType.Input,
                    1,
                    0.1,
                    0.2,
                    0.3);

            NEATNeuron input2 = new NEATNeuron(
                    NEATNeuronType.Input,
                    2,
                    0.1,
                    0.2,
                    0.3);

            NEATNeuron bias = new NEATNeuron(
                    NEATNeuronType.Bias,
                    3,
                    0.1,
                    0.2,
                    0.3);

            NEATNeuron hidden1 = new NEATNeuron(
                    NEATNeuronType.Hidden,
                    4,
                    0.1,
                    0.2,
                    0.3);

            NEATNeuron output = new NEATNeuron(
                    NEATNeuronType.Output,
                    5,
                    0.1,
                    0.2,
                    0.3);

            // add the neurons
            neurons.Add(input1);
            neurons.Add(input2);
            neurons.Add(hidden1);
            neurons.Add(bias);
            neurons.Add(output);

            // connect everything
            Link(0.01, input1, hidden1, false);
            Link(0.01, input2, hidden1, false);
            Link(0.01, bias, hidden1, false);
            Link(0.01, hidden1, output, false);

            // create the network
            NEATNetwork result = new NEATNetwork(2,
                    1,
                    neurons,
                    afSigmoid,
                    afStep,
                    3);

            return result;
        }
 /// <summary>
 /// Builds and trains a neat network.
 /// </summary>
 /// <param name="aset">The IMLDataset.</param>
 /// <param name="inputcounts">The inputcounts.</param>
 /// <param name="outputcounts">The outputcounts.</param>
 /// <param name="populationsize">The populationsize.</param>
 /// <param name="ToErrorTraining">To error rate you want to train too.</param>
 /// <returns>a trained netnetwork.</returns>
 public static NEATNetwork BuildTrainNeatNetwork(IMLDataSet aset, int inputcounts, int outputcounts, int populationsize, double ToErrorTraining)
 {
     NEATPopulation pop = new NEATPopulation(inputcounts, outputcounts, populationsize);
     ICalculateScore score = new TrainingSetScore(aset);
     // train the neural network
     ActivationStep step = new ActivationStep();
     step.Center = 0.5;
     pop.OutputActivationFunction = step;
     NEATTraining train = new NEATTraining(score, pop);
     EncogUtility.TrainToError(train, ToErrorTraining);
     NEATNetwork network = (NEATNetwork)train.Method;
     return network;
 }
Esempio n. 9
0
 void AddLayers(List<LayerConfig> gen)
 {
     foreach (var g in gen)
     {
         IActivationFunction act;
         if (g.ActivationType == 0)
         {
             act = new ActivationBiPolar();
         }
         switch (g.ActivationType )
         {
             case 0:
                 act = new ActivationBiPolar();
                 break;
             case 1:
                 act = new ActivationBipolarSteepenedSigmoid ();
                 break;
             case 2:
                 act = new ActivationClippedLinear();
                 break;
             case 3:
                 act = new ActivationCompetitive();
                 break;
             case 4:
                 act = new ActivationElliott();
                 break;
             case 5:
                 act = new ActivationElliottSymmetric();
                 break;
             case 6:
                 act = new ActivationGaussian();
                 break;
             case 7:
                 act = new ActivationLinear();
                 break;
             case 8:
                 act = new ActivationLOG();
                 break;
             case 9:
                 act = new ActivationRamp();
                 break;
             case 10:
                 act = new ActivationRamp();
                 break;
             case 11:
                 act = new ActivationSigmoid();
                 break;
             case 12:
                 act = new ActivationSIN();
                 break;
             case 13:
                 act = new ActivationSoftMax();
                 break;
             case 14:
                 act = new ActivationSteepenedSigmoid();
                 break;
             case 15:
                 act = new ActivationStep();
                 break;
             case 16:
                 act = new ActivationTANH();
                 break;
             default:
                 act = new ActivationSoftMax();
                 break;
         }
         network.AddLayer(new BasicLayer(act, g.hasBias, g.neurons));
     }
 }