예제 #1
0
파일: Program.cs 프로젝트: Puzer/TWEANN
        static double FitFunc(NeuralNetwork nn)
        {
            const double step = 0.01d;
            const double start = -1;
            const double end = 1;

            var iterationCount = Math.Abs(start - end) / step;

            double errorRate = 0d;
            for (double i = start; i <= end; i += step)
            {
                errorRate += Math.Abs(nn.Solve(i) - func(i));
            }
            return 1d / (1 + errorRate / iterationCount);
        }
예제 #2
0
 public Species(Func <NeuralNetwork, double> fitnessFunc, NeuralNetwork network)
     : this(fitnessFunc, network, null)
 {
 }
예제 #3
0
 internal static IComputingNode GetRandomNode(this NeuralNetwork network)
 {
     return(network.Synapses[Rnd.Next(0, network.Synapses.Count)]._input);
 }
예제 #4
0
 internal static Neuron GetRandomNeuron(this NeuralNetwork network)
 {
     return(network.Neurons[Rnd.Next(0, network.Neurons.Count)]);
 }
예제 #5
0
 internal static Synapse GetRandomSynapse(this NeuralNetwork network)
 {
     return(network.Synapses[Rnd.Next(0, network.Synapses.Count)]);
 }
예제 #6
0
 public static NeuralNetwork ConnectMoreToOne(NeuralNetwork outNetwork, params NeuralNetwork[] networks)
 {
     /*
      * //TODO: пофиксить Id нейронов
      * if (networks.Sum(n => n.Effectors.Count) != outNetwork.Receptors.Count(r => typeof(Receptor)==r.GetType()))
      *  throw new Exception("Количество входов выходной сети должно равняться сумме всех выходов входных");
      *
      * if (networks.Max(n => n.Receptors.Count(r => typeof(Receptor) == r.GetType())) != networks.Min(n => n.Receptors.Count(r => typeof(Receptor) == r.GetType())))
      *  throw new Exception("Должно быть одинаковое число входов выходной сети (для объединения в один)");
      *
      * Receptor alphaReceptor = new Receptor(); //TODO: входных рецепторов может быть много
      *
      *
      *
      * List<Neuron> neuronsOnLatLayer = new List<Neuron>();
      * var maxOfAllLayer = 0;
      *
      * List<Receptor> receptors = new List<Receptor>();
      * List<Neuron> neurons = new List<Neuron>();
      * List<Synapse> synapses = new List<Synapse>();
      *
      * foreach (var network in networks)
      * {
      *  var maxLayer = network.Neurons.Max(n => n.LayerId);
      *  neuronsOnLatLayer.AddRange(network.Neurons.Where(n => n.LayerId == maxLayer).ToList());
      *
      *  maxOfAllLayer = maxLayer > maxOfAllLayer ? maxLayer : maxOfAllLayer;
      *
      *  foreach (var receptor in network.Receptors)
      *  {
      *      receptor.RecurrentCallback = alphaReceptor.Compute;
      *      receptor.Recurrent = true;
      *  }
      *
      *  receptors.AddRange(network.Receptors);
      *  neurons.AddRange(network.Neurons);
      *  synapses.AddRange(network.Synapses);
      * }
      *
      * for (int i = 0; i < outNetwork.ReceptorCount; i++)
      * {
      *  var receptor = outNetwork.Receptors[i];
      *  receptor.RecurrentCallback = neuronsOnLatLayer[i].Compute;
      *  receptor.Recurrent = true;
      * }
      *
      * foreach (var neuron in outNetwork.Neurons)
      *  neuron.LayerId += maxOfAllLayer + 1;
      *
      *
      * receptors.Add(alphaReceptor);
      * receptors.AddRange(outNetwork.Receptors);
      *
      * neurons.AddRange(outNetwork.Neurons);
      * synapses.AddRange(outNetwork.Synapses);
      *
      * return new NeuralNetwork(receptors, neurons, synapses);
      *
      */
     return(null);
 }