Example #1
0
 /// <summary>
 /// Instanciate a new synapse. You'll hardly need to call this as the preferred way to create neurons is using the neuron, layer or even network classes.
 /// </summary>
 /// <param name="source">The source neuron feeding this synapse.</param>
 /// <param name="target">The target neuron fed by this synapse.</param>
 public Synapse(ConfigNode node, Neuron source, Neuron target)
 {
     node.AttatchToHost(this);
     _sourceNeuron = source;
     _targetNeuron = target;
     _weight = _config.RandomInitialWeight();
 }
 public SingleOutput(Neuron neuron)
 {
     InitializeComponent();
     this.neuron = neuron;
     UpdateData();
     //neuron.OnOutputChanged += new ValueChangedEventHandler(OnNeuronOutputChanged);
 }
Example #3
0
        private double _weightBuffer = 0; //Buffer for MomentumTerm Optimization

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Instanciate a new synapse. You'll hardly need to call this as the preferred way to create neurons is using the neuron, layer or even network classes.
        /// </summary>
        /// <param name="source">The source neuron feeding this synapse.</param>
        /// <param name="target">The target neuron fed by this synapse.</param>
        /// <param name="weight">The weight of the synapse.</param>
        public Synapse(ConfigNode node, Neuron source, Neuron target, double weight)
        {
            node.AttatchToHost(this);
            _sourceNeuron = source;
            _targetNeuron = target;
            _weight = weight;
        }
Example #4
0
 /// <summary>
 /// Instanciate new event arguments.
 /// </summary>
 /// <param name="neuron">The refering neuron.</param>
 public NeuronEventArgs(Neuron neuron)
 {
     this.neuron = neuron;
 }
 protected void AddOutputNeuron(Neuron neuron)
 {
     SingleOutput so = new SingleOutput(neuron);
     so.Location = new Point(0,17*items.Count);
     items.Add(so);
     Controls.Add(so);
 }
 protected void RemoveOutputNeuron(Neuron neuron)
 {
 }
 /// <summary>
 /// Connect input neurons of a specified 'ring' to a given neuron.
 /// </summary>
 /// <param name="input">The input layer.</param>
 /// <param name="neuron">The neuron to connect to.</param>
 /// <param name="width">The width of the input grid (needed for transforming (x,y) to linear position).</param>
 /// <param name="height">The height of the input grid (needed for transforming (x,y) to linear position).</param>
 /// <param name="shift">The radial shift. 0 means the biggest radius, 1 the second biggest etc.</param>
 protected void ConnectRing(Layer input, Neuron neuron, int width, int height, int shift)
 {
     ConnectVerticalLine(input,neuron,width,shift,shift,height-1-shift);
     ConnectVerticalLine(input,neuron,width,width-1-shift,shift,height-1-shift);
     ConnectHorizontalLine(input,neuron,width,shift,shift+1,width-2-shift);
     ConnectHorizontalLine(input,neuron,width,height-1-shift,shift+1,width-2-shift);
 }
 /// <summary>
 /// Connect input neurons in horizontal lines to new hidden neurons.
 /// </summary>
 /// <param name="input">The input layer.</param>
 /// <param name="hidden">The neuron to connect to.</param>
 /// <returns>The set of new hidden neurons.</returns>
 protected Neuron[] AddHorizontalLines(Layer input, Layer hidden)
 {
     Neuron[] horizontal = new Neuron[_height];
     for(int i=0;i<_height;i++)
     {
         horizontal[i] = new Neuron(_network.Node, hidden);
         ConnectHorizontalLine(input,horizontal[i],_width,i,0,_width-1);
     }
     return horizontal;
 }
 /// <summary>
 /// Connect input neurons of a specified oblong to a given neuron.
 /// </summary>
 /// <param name="input">The input layer.</param>
 /// <param name="neuron">The neuron to connect to.</param>
 /// <param name="width">The width of the input grid (needed for transforming (x,y) to linear position).</param>
 /// <param name="x">X-Coordinate of the top left cornet.</param>
 /// <param name="y">Y-Coordinate of the top left cornet.</param>
 /// <param name="dx">Width of the oblong.</param>
 /// <param name="dy">Height of the oblong.</param>
 protected void ConnectArea(Layer input, Neuron neuron, int width, int x, int y, int dx, int dy)
 {
     for(int i=x;i<x+dx;i++)
         for(int j=y;j<y+dy;j++)
             input[i+j*width].ConnectToNeuron(neuron);
 }
 /// <summary>
 /// Connect input neurons of a specified horizontal line to a given neuron.
 /// </summary>
 /// <param name="input">The input layer.</param>
 /// <param name="neuron">The neuron to connect to.</param>
 /// <param name="width">The width of the input grid (needed for transforming (x,y) to linear position).</param>
 /// <param name="y">The constant Y-Coordinate of the line.</param>
 /// <param name="xmin">The left end X-Coordinate.</param>
 /// <param name="xmax">The right end X-Coordinate.</param>
 protected void ConnectHorizontalLine(Layer input, Neuron neuron, int width, int y, int xmin, int xmax)
 {
     for(int i=xmin;i<xmax+1;i++)
         input[i+y*width].ConnectToNeuron(neuron);
 }
 /// <summary>
 /// Connect input neurons in vertical lines to new hidden neurons.
 /// </summary>
 /// <param name="input">The input layer.</param>
 /// <param name="hidden">The neuron to connect to.</param>
 /// <returns>The set of new hidden neurons.</returns>
 protected Neuron[] AddVerticalLines(Layer input, Layer hidden)
 {
     Neuron[] vertical = new Neuron[_width];
     for(int i=0;i<_width;i++)
     {
         vertical[i] = new Neuron(_network.Node, hidden);
         ConnectVerticalLine(input,vertical[i],_width,i,0,_height-1);
     }
     return vertical;
 }
 /// <summary>
 /// Connect input neurons in squares to new hidden neurons.
 /// </summary>
 /// <param name="input">The input layer.</param>
 /// <param name="hidden">The neuron to connect to.</param>
 /// <returns>The set of new hidden neurons.</returns>
 protected Neuron[] AddSquares(Layer input, Layer hidden)
 {
     if(_width < 2 || _height < 2)
         return new Neuron[] {};
     int widthhalf = (int)Math.Ceiling(_width/2d);
     int heighthalf = (int)Math.Ceiling(_height/2d);
     Neuron[] area = new Neuron[widthhalf*heighthalf];
     widthhalf -= widthhalf % 2;
     heighthalf -= heighthalf % 2;
     int item = 0;
     for(int i=0;i<=widthhalf;i+=2)
     {
         for(int j=0;j<=heighthalf;j+=2)
         {
             area[item] = new Neuron(_network.Node, hidden);
             ConnectArea(input,area[item++],_width,i,j,2,2);
         }
         for(int j=_height-2;j>heighthalf;j-=2)
         {
             area[item] = new Neuron(_network.Node, hidden);
             ConnectArea(input,area[item++],_width,i,j,2,2);
         }
     }
     for(int i=_width-2;i>widthhalf;i-=2)
     {
         for(int j=0;j<=heighthalf;j+=2)
         {
             area[item] = new Neuron(_network.Node, hidden);
             ConnectArea(input,area[item++],_width,i,j,2,2);
         }
         for(int j=_height-2;j>heighthalf;j-=2)
         {
             area[item] = new Neuron(_network.Node, hidden);
             ConnectArea(input,area[item++],_width,i,j,2,2);
         }
     }
     return area;
 }
 /// <summary>
 /// Connect input neurons in rings to new hidden neurons.
 /// </summary>
 /// <param name="input">The input layer.</param>
 /// <param name="hidden">The neuron to connect to.</param>
 /// <returns>The set of new hidden neurons.</returns>
 protected Neuron[] AddRings(Layer input, Layer hidden)
 {
     Neuron[] ring = new Neuron[Math.Min(_width,_height)/2];
     for(int i=0;i<ring.Length;i++)
     {
         ring[i] = new Neuron(_network.Node, hidden);
         ConnectRing(input,ring[i],_width,_height,i);
     }
     return ring;
 }
Example #14
0
 /// <summary>
 /// Connect this neuron forward to another (specified) neuron.
 /// </summary>
 /// <param name="target">The target neuron.</param>
 /// <param name="weight">The weight of the synapse.</param>
 /// <returns>The new connection synapse.</returns>
 public Synapse ConnectToNeuron(Neuron target, double weight)
 {
     Synapse s = new Synapse(_node.BuildSibling(), this, target, weight);
     _targetSynapses.Add(s);
     target._sourceSynapses.Add(s);
     if(TargetSynapseAdded != null)
         TargetSynapseAdded(this,new SynapseEventArgs(s));
     return s;
 }
 /// <summary>
 /// Connect input neurons of a specified vertical line to a given neuron.
 /// </summary>
 /// <param name="input">The input layer.</param>
 /// <param name="neuron">The neuron to connect to.</param>
 /// <param name="width">The width of the input grid (needed for transforming (x,y) to linear position).</param>
 /// <param name="x">The constant X-Coordinate of the line.</param>
 /// <param name="ymin">The top end Y-Coordinate.</param>
 /// <param name="ymax">The bottom end Y-Coordinate.</param>
 protected void ConnectVerticalLine(Layer input, Neuron neuron, int width, int x, int ymin, int ymax)
 {
     for(int i=ymin;i<ymax+1;i++)
         input[x+i*width].ConnectToNeuron(neuron);
 }
Example #16
0
 /// <summary>
 /// Remove all connections from this neuron forward to another (specified) neuron.
 /// </summary>
 /// <param name="source">The neuron feeding this neuron.</param>
 public void DisconnectToNeuron(Neuron source)
 {
     for(int i=0;i<_targetSynapses.Count;i++)
     {
         Synapse s = _targetSynapses[i];
         if(s.TargetNeuron == source)
         {
             _targetSynapses.Remove(s);
             s.TargetNeuron._sourceSynapses.Remove(s);
             if(TargetSynapseRemoved != null)
                 TargetSynapseRemoved(this,new SynapseEventArgs(s));
             i--;
         }
     }
 }
Example #17
0
 /// <summary>
 /// Instanciate new event arguments.
 /// </summary>
 /// <param name="neuron">The refering neuron.</param>
 public NeuronEventArgs(Neuron neuron)
 {
     this.neuron = neuron;
 }