Beispiel #1
0
        static void Main(string[] args)
        {
            var a = new WiredNeuralArchitecture(
                InputLength,
                OutputLength,
                NodeCount,
                new Factory<OperationNode<double>>(() => new ActivationNeuron(new SigmoidActivationFunction { Alpha = 1.05 })),
                new Factory<OperationNode<double>>(() => new ActivationNeuron(new LinearActivationFunction(1.05))),
                new Factory<ComputationConnection<double>>(() => new Synapse()));

            Console.WriteLine("Creating Wired Network ...");
            var net = a.CreateNetwork();
            Console.WriteLine("Done.");

            Console.WriteLine();
            Console.WriteLine("Begin test, number of iterations: {0}", TestIterationCount);
            var sw = new Stopwatch();

            var t = new UnorderedTraining(net);

            t.EnsureScriptRun();

            sw.Start();

            lock (net.SyncRoot)
            {
                for (int i = 0; i < TestIterationCount; i++)
                {
                    //net.Iteration();
                    t.BackwardIteration();
                }
            }

            sw.Stop();

            Console.WriteLine("Total Millisec: {0}", sw.ElapsedMilliseconds);

            Console.WriteLine("Press any ...");
            Console.ReadKey();
        }
Beispiel #2
0
        static NeuralNetwork CreateNetwork(ISupervisedFeatureMatrixProvider matrixProv, params ILearningRule[] rules)
        {
            Contract.Requires(matrixProv != null);
            Contract.Requires(rules != null);
            Contract.Requires(rules.Length > 0);

            IFactory<Synapse> synapseFactory = new Factory<Synapse>(() => new Synapse(rules));
            IFactory<ActivationNeuron> neuronFactorySig = new Factory<ActivationNeuron>(() => new ActivationNeuron(new SigmoidActivationFunction(1.05), rules));
            IFactory<ActivationNeuron> neuronFactoryLin = new Factory<ActivationNeuron>(() => new ActivationNeuron(new LinearActivationFunction(1.05), rules));

            //INeuralArchitecture arch = new LayeredNeuralArchitecture(
            //    new NeuralMLABuilder(
            //        false,
            //        new ConnectionLayerDefinition<double>(synapseFactory),
            //        matrixProv.MatrixWidth,
            //        new OperationNodeLayerDefinition<double>(neuronFactorySig, 20),
            //        new OperationNodeLayerDefinition<double>(neuronFactorySig, 10),
            //        new OperationNodeLayerDefinition<double>(neuronFactoryLin, matrixProv.OutputMatrixWidth)));

            INeuralArchitecture arch = new WiredNeuralArchitecture(matrixProv.MatrixWidth, matrixProv.OutputMatrixWidth, Properties.Settings.Default.NeuronCount, neuronFactorySig, neuronFactoryLin, synapseFactory);

            return arch.CreateNetwork();
        }
Beispiel #3
0
        static NeuralNetwork CreateNetwork(bool recurrent, params ILearningRule[] rules)
        {
            Contract.Requires(rules != null);
            Contract.Requires(rules.Length > 0);

            int inputSize;
            
            if (!recurrent)
            {
                inputSize = Properties.Settings.Default.SampleSize * Properties.Settings.Default.SampleSize + 1;
            }
            else
            {
                inputSize = Properties.Settings.Default.SampleSize + 1;
            }

            IFactory<Synapse> synapseFactory = new Factory<Synapse>(() => new Synapse(rules));
            IFactory<ActivationNeuron> neuronFactorySig = new Factory<ActivationNeuron>(() => new ActivationNeuron(new SigmoidActivationFunction(1.05), rules));
            IFactory<ActivationNeuron> neuronFactoryLin = new Factory<ActivationNeuron>(() => new ActivationNeuron(new LinearActivationFunction(1.05), rules));

            //INeuralArchitecture arch = new LayeredNeuralArchitecture(
            //    new NeuralMLABuilder(
            //        false,
            //        new ConnectionLayerDefinition<double>(synapseFactory),
            //        inputSize,
            //        new OperationNodeLayerDefinition<double>(neuronFactorySig, 20),
            //        new OperationNodeLayerDefinition<double>(neuronFactorySig, 10),
            //        new OperationNodeLayerDefinition<double>(neuronFactoryLin, 1)));

            INeuralArchitecture arch = new WiredNeuralArchitecture(inputSize, 1, Properties.Settings.Default.NeuronCount, neuronFactorySig, neuronFactoryLin, synapseFactory, recurrent);

            //INeuralArchitecture arch = new WiredNeuralArchitecture(3, 1, 2, neuronFactorySig, neuronFactoryLin, synapseFactory, recurrent);

            return arch.CreateNetwork();
        }
Beispiel #4
0
        static NeuralNetwork CreateNetwork(int inputSize, int outputSize, params ILearningRule[] rules)
        {
            IFactory<Synapse> synapseFactory = new Factory<Synapse>(() => new Synapse(rules));
            IFactory<ActivationNeuron> neuronFactorySig = new Factory<ActivationNeuron>(() => new ActivationNeuron(new SigmoidActivationFunction(1.05), rules));
            IFactory<ActivationNeuron> neuronFactoryLin = new Factory<ActivationNeuron>(() => new ActivationNeuron(new LinearActivationFunction(1.05), rules));

            //INeuralArchitecture arch = new LayeredNeuralArchitecture(
            //    new NeuralMLABuilder(
            //        false,
            //        new ConnectionLayerDefinition<double>(synapseFactory),
            //        inputSize,
            //        new OperationNodeLayerDefinition<double>(neuronFactorySig, 10),
            //        new OperationNodeLayerDefinition<double>(neuronFactorySig, 6),
            //        new OperationNodeLayerDefinition<double>(neuronFactoryLin, outputSize)));

            INeuralArchitecture arch = new WiredNeuralArchitecture(
                inputSize,
                outputSize,
                Properties.Settings.Default.NeuronCount,
                neuronFactorySig,
                neuronFactoryLin,
                synapseFactory,
                Properties.Settings.Default.NumberOfIterations != 1);

            return arch.CreateNetwork();
        }