Ejemplo n.º 1
0
        public void RestartNetwork()
        {
            NeuronDesirabilityMap = new double[Height, Width];
            NeuronUndesirabilityMap = new double[Height, Width];
            NeuronPositionMap = new Neuron[Height, Width];
            NeuronAxonWayPoints = new NeuronAxonWaypoint[Height, Width];

            #region Generate Random Neurons

            var oldNeurons = _neurons.ToList();

            var neurons = new List<Neuron>();
            for (int index = 0; index < oldNeurons.Count; index++)
            {
                var neuron = new Neuron(index, this, AxonGuidanceForces, SomaGuidanceForces,
                    index >= NeuronCount ? NeuronType.Input : NeuronType.Process);

                neuron.MoveTo(oldNeurons[index].PosY, oldNeurons[index].PosX);

                neuron.ResetMovedDistance();
                neurons.Add(neuron);
                NeuronPositionMap[neuron.PosY, neuron.PosX] = neuron;
            }

            _neurons = neurons.ToArray();

            #endregion Generate Random Neurons

            _neuronsInput = neurons.GetRange(NeuronCount, InputNeuronCount).ToArray();

            ActiveNeuronGenerator = new SequentialActiveInputNeuronGenerator(_neuronsInput, Math.Min(_neuronsInput.Length, 3));
            _iteration = 0;
        }
Ejemplo n.º 2
0
        public void GenerateNetwork()
        {
            NeuronDesirabilityMap = new double[Height, Width];
            NeuronUndesirabilityMap = new double[Height, Width];
            NeuronPositionMap = new Neuron[Height, Width];
            NeuronAxonWayPoints = new NeuronAxonWaypoint[Height, Width];

            AxonGuidanceForces = GetAxonGuidanceForces();
            SomaGuidanceForces = GetSomaGuidanceForces();

            #region Generate Random Neurons

            var neurons = new List<Neuron>();

            #region generate input neurons

            int generatedNeuronId = 0;

            for (int index = 0; index < InputNeuronCount; index++)
            {
                var neuron = new Neuron(generatedNeuronId++, this, AxonGuidanceForces, SomaGuidanceForces, NeuronType.Input);

                int baseIndex = NeuronInputMarginBetween * (index + 1) + 60;
                int y = (baseIndex + NeuronGenerationMargin) % Height;
                int x = baseIndex / Height + NeuronGenerationMargin;

                neuron.MoveTo(y, x);
                neuron.ResetMovedDistance();
                neurons.Add(neuron);
                NeuronPositionMap[neuron.PosY, neuron.PosX] = neuron;
            }

            #endregion

            #region generate output neurons

            for (int index = 0; index < OutputNeuronCount; index++)
            {
                var neuron = new Neuron(generatedNeuronId++, this, AxonGuidanceForces, SomaGuidanceForces, NeuronType.Output);

                int baseIndex = NeuronInputMarginBetween * (index + 1) + 60;
                int y = (baseIndex + NeuronGenerationMargin) % Height;
                int x = Width - (baseIndex / Height + NeuronGenerationMargin);

                neuron.MoveTo(y, x);
                neuron.ResetMovedDistance();
                neurons.Add(neuron);
                NeuronPositionMap[neuron.PosY, neuron.PosX] = neuron;
            }

            #endregion

            #region generate other neurons

            for (int index = 0; index < NeuronCount; index++)
            {
                var neuron = new Neuron(generatedNeuronId++, this, AxonGuidanceForces, SomaGuidanceForces, NeuronType.Process);

                do
                {
                    neuron.MoveTo(_random.Next(Height - 2 * NeuronGenerationMargin) + NeuronGenerationMargin,
                        _random.Next(Width - 2 * (NeuronGenerationMargin + NeuronProcessMarginFromInputAndOutputNeurons)) + NeuronGenerationMargin + NeuronProcessMarginFromInputAndOutputNeurons);
                }
                while (neurons.Any(n => n.PosX == neuron.PosX && n.PosY == neuron.PosY)
                    || Extensions.GetDistanceToNearestNeuron(neuron.PosY, neuron.PosX, neuron, this) <= MinDistanceBetweenNeurons);

                neuron.ResetMovedDistance();
                neurons.Add(neuron);
                NeuronPositionMap[neuron.PosY, neuron.PosX] = neuron;
            }

            #endregion

            _neurons = neurons.ToArray();

            #endregion Generate Random Neurons

            _neuronsInput = neurons.Take(InputNeuronCount).ToArray();
            _neuronsOutput = neurons.Skip(InputNeuronCount).Take(OutputNeuronCount).ToArray();

            //var inputOutputNeuronBindings = new List<Tuple<Neuron, Neuron>>();
            //for (int index = 0; index < InputNeuronCount; index++)
            //{
            //    inputOutputNeuronBindings.Add(new Tuple<Neuron,Neuron>(_neuronsInput.ElementAt(index), _neuronsOutput.ElementAt(index)));
            //}

            BindedActiveNeuronGenerator = new PushPullBoxActivityGenerator(this, _neuronsInput, _neuronsOutput);
            NormalActiveNeuronGenerator = new SequentialActiveInputNeuronGenerator(_neuronsInput, Math.Min(_neuronsInput.Length, 3));

            ActiveNeuronGenerator = NormalActiveNeuronGenerator;

            _iteration = 0;
        }