public AxonGuidanceForcesSumEventArgs(Neuron neuron, int refY, int refX, double[,] score)
 {
     Neuron = neuron;
     RefY = refY;
     RefX = refX;
     Score = score;
 }
Ejemplo n.º 2
0
        public double[,] GetScore(int refY, int refX, Neuron neuron)
        {
            var result = GetInitializationResult();

            int minX = Math.Max(refX - GuidanceForceRange, 0);
            int maxX = Math.Min(refX + GuidanceForceRange, Network.Width - 1);

            int minY = Math.Max(refY - GuidanceForceRange, 0);
            int maxY = Math.Min(refY + GuidanceForceRange, Network.Height - 1);

            for (int y = minY; y < maxY; y++)
            {
                for (int x = minX; x < maxX; x++)
                {
                    // only check  in the desired radius
                    if ((x == refX && y == refY)
                        /* this ensures that we only check within the range */
                        || (Extensions.GetDistance(refX, refY, x, y)) > GuidanceForceRange)
                    {
                        continue;
                    }

                    if (PreCheckLocation(x, y, neuron) == false)
                    {
                        continue;
                    }

                    result[y - minY, x - minX] = ComputeScoreAtLocation(x, y, neuron);
                }
            }

            InvokeScoreAvailableEvent(refY, refX, neuron, result);

            return result;
        }
Ejemplo n.º 3
0
 protected override bool PreCheckLocation(int x, int y, Neuron neuron)
 {
     return base.PreCheckLocation(x, y, neuron)
         && (x != neuron.PosX || y != neuron.PosY)
         && Extensions.GetNeuronAt(y, x, Network) == null
         && neuron.MovedDistance + Extensions.GetDistance(neuron.PosX, neuron.PosY, x, y) < Network.MaxNeuronMoveDistance
         && Extensions.GetDistanceToNearestNeuron(y, x, neuron, Network) > Network.MinDistanceBetweenNeurons;
 }
Ejemplo n.º 4
0
 public GuidanceForceScoreEventArgs(GuidanceForceBase guidanceForce, int refY, int refX, Neuron neuron, double[,] score)
 {
     GuidanceForce = guidanceForce;
     RefY = refY;
     RefX = refX;
     Neuron = neuron;
     Score = score;
 }
Ejemplo n.º 5
0
 public IEnumerable<Neuron> GetActiveNeurons()
 {
     var resultCount = (int)(_availableNeurons.Count * _percentActiveNeurons);
     var result = new Neuron[resultCount];
     for (int i = 0; i < resultCount; i++)
     {
         result[i] = _availableNeurons[_random.Next(_availableNeurons.Count)];
     }
     return result;
 }
Ejemplo n.º 6
0
 public void Update(int x, int y, Neuron neuron)
 {
 }
Ejemplo n.º 7
0
 protected override bool PreCheckLocation(int x, int y, Neuron neuron)
 {
     return base.PreCheckLocation(x, y, neuron)
         && GetDistanceFromOtherWayPoints(x, y) > Network.AxonMinDistanceToOtherWayPoints;
 }
 public override double ComputeScoreAtLocation(int x, int y, Neuron neuron)
 {
     return 0;
 }
Ejemplo n.º 9
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;
        }
Ejemplo n.º 10
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.º 11
0
 /// <summary>
 /// Perform VERY FAST checks here
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <param name="neuron">The neuron context to check</param>
 /// <returns></returns>
 protected virtual bool PreCheckLocation(int x, int y, Neuron neuron)
 {
     return true;
 }
Ejemplo n.º 12
0
        public NeuronChangedEventArgs(Neuron neuron)
        {
            Contract.Requires<ArgumentNullException>(neuron != null);

            Neuron = neuron;
        }
Ejemplo n.º 13
0
 public abstract double ComputeScoreAtLocation(int x, int y, Neuron neuron);
Ejemplo n.º 14
0
        private void OnViewerManagerNeuronSelectedChanged(object sender, NeuronChangedEventArgs e)
        {
            SelectedNeuron = e.Neuron;

            _viewerAxonTerminalGuidanceForces.Neuron = e.Neuron;
            _viewerSomaDesirabilityMapGuidanceForce.Neuron = e.Neuron;
        }
 protected override bool PreCheckLocation(int x, int y, Neuron neuron)
 {
     return base.PreCheckLocation(x, y, neuron)
         && Math.Abs(Network.NeuronUndesirabilityMap[y, x] - 0.0d) < 0.00001 == false;
 }
 public override double ComputeScoreAtLocation(int x, int y, Neuron neuron)
 {
     return 3 * Network.NeuronUndesirabilityMap[y, x];
 }
Ejemplo n.º 17
0
 public NeuronAxonWaypoint(int id, Neuron neuron, Point waypoint)
 {
     Id       = id;
     Neuron   = neuron;
     Waypoint = waypoint;
 }
Ejemplo n.º 18
0
 private void InvokeScoreAvailableEvent(int refY, int refX, Neuron neuron, double[,] score)
 {
     var handler = ScoreAvailableEvent;
     if (handler != null)
     {
         handler(this, new GuidanceForceScoreEventArgs(this, refY, refX, neuron, score));
     }
 }
Ejemplo n.º 19
0
 public bool GetWasActive(Neuron exclusiveNeuron)
 {
     return Network.NeuronActivityHistory.Any(item => item.Contains(this)
                                                      && item.Contains(exclusiveNeuron) == false);
 }
Ejemplo n.º 20
0
        private void UpdateHoverAndSelectedNeuron(int mousePosX, int mousePosY, bool leftButtonPressed)
        {
            NeuronHover = Extensions.GetClosestNeuronsWithinRange(mousePosX, mousePosY, _network, 10);

            if (NeuronHover != null)
            {
                if (leftButtonPressed)
                {
                    NeuronSelected = NeuronHover;
                }
            }
        }
Ejemplo n.º 21
0
 private void OnNeuronHoverChanged(Neuron value)
 {
     var handler = NeuronHoverChanged;
     if (handler != null)
     {
         handler(this, new NeuronChangedEventArgs(value));
     }
 }
Ejemplo n.º 22
0
 public bool GetWasActive(Neuron exclusiveNeuron)
 {
     return(Network.NeuronActivityHistory.Any(item => item.Contains(this) &&
                                              item.Contains(exclusiveNeuron) == false));
 }
Ejemplo n.º 23
0
 public NeuronAxonWaypoint(int id, Neuron neuron, Point waypoint)
 {
     Id = id;
     Neuron = neuron;
     Waypoint = waypoint;
 }