|
using System;
using System.Collections.Generic;
using System.Text;
namespace HopfieldNeuralNetwork
{
/// <summary>
/// Defines the base class of neuron.
/// </summary>
public class Neuron
{
private int state;
/// <summary>
/// Gets or sets the state of neuron
/// </summary>
/// <seealso cref="HopfieldNeuralNetwork.NeuronStates"/>
public int State
{
get { return state; }
set { state = value;}
}
/// <summary>
/// Initializes a new instance Neuron class
/// </summary>
public Neuron()
{
int r = new Random().Next(2);
switch (r)
{
case 0: state = NeuronStates.AlongField; break;
case 1: state = NeuronStates.AgainstField; break;
}
}
/// <summary>
/// Calculates necessity, and if so, changes state of neuron
/// </summary>
/// <param name="field">Local field actiong on neuron from all other neurons of network</param>
/// <returns>True if during calculations neuron chages its state, false otherwise</returns>
public bool ChangeState(Double field)
{
bool res = false;
if (field * this.State < 0)
{
this.state = -this.state;
res = true;
}
return res;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Work: HSBC (http://www.hsbc.co.uk/).
Regalia: PhD in CS, MCAD, MCPD: Web Developer, MCTS: .Net Framework 2.0., 3.5.
Interests: Programming, artificial intelligence, C#, .NET, HTML5, ASP.NET, SQL, LINQ.
Marital Status: Married, daughter
Blog:
http://www.magomedov.co.uk