[译]C#中的基本人工神经网络
By robot-v1.0
本文链接 https://www.kyfws.com/ai/basic-artificial-neural-network-in-csharp-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 6 分钟阅读 - 2727 个词 阅读量 0C#中的基本人工神经网络(译文)
原文地址:https://www.codeproject.com/Articles/1200214/Basic-Artificial-Neural-Network-in-Csharp
原文作者:Bhairav Thakkar
译文由本站 robot-v1.0 翻译
前言
A basic artificial neural network code for experimenting
用于实验的基本人工神经网络代码
介绍(Introduction)
本文介绍了使用C#编写的基本人工神经网络程序.该程序提供了一个在人工神经网络上进行实验的平台.(This article presents a basic Artificial Neural Network program in C#. The program offers a platform for experimenting on Artificial Neural Networks.)
背景(Background)
可以将人类大脑视为数百万个相互连接的神经元的复杂集合.大脑接收到的信息由这些微小的神经元处理.神经元通过树突接收信号,并通过突触进一步传递信号.突触将信号传递到相邻的神经元,或者不传递,取决于信号的强度.随着人类大脑获取信息,神经元之间会建立新的连接,而现有连接也会被修改.(The human brain can be viewed as a complex assemby of millions of neurons interconnected with each other. The information received by the brain is processed by these tiny neurons. Signals received by a neuron via dendrites and are further relayed by synapse. The synapses either pass a signal to adjoining neuron or not depending on the strength of the signal. As the human brain acquires information, new connections are developed between neurons and existing connections are modified.)
人工神经网络试图(在非常基本的水平上)模拟人脑的功能.创建了一组相互连接的神经元.这些相互连接的神经元分层组织,以便于处理.神经元之间的信号传递通过树突发生.神经元向邻近的连接神经元"发射"信号的潜力由激活电位决定.通常,这种射击倾向(也称为动作电位)是通过S形函数建模的.的(Artificial Neural Network attempts to simulate (to a very basic level) the functioning of a human brain. A set of interconnected neurons are created. These interconnected neurons are organized in layers for easier handling. The signal transfer between neurons happen via dendrites. The potential of a neuron to “fire” a signal to the adjoining connected neuron is decided by an activation potential. Usually, this firing tendancy (also known as action potential) is modeled by a sigmoidal function. The) 乙状结肠功能(sigmoidal function) 看起来像:(looks like:)
$ S(x)=\ frac {1} {1 + e ^ {-x}} $($ S(x) = \frac{1}{1+e^{-x}} $)
对于x的任何输入,S型函数将返回0到1之间的值.它是(The sigmoidal function returns a value between 0 and 1 for any input of x. It is)强烈推荐(highly recommended)读者会通过S型函数的特性进行研究,以了解其作为激活函数的用途.本文不尝试讨论人工神经网络的基础.相反,建议读者参考有关该主题的更多权威文章.(that the reader studies through the properties of sigmoid function in order to appreciate its use as activation function. This article does not attempt to discuss the fundamentals of Artificial Neural Network. Instead, the readers are recommended to refer to more authorative texts on the subject.)
使用代码(Using the code)
人工神经网络包含以下主要类别:(The Artificial Neural Network contains the following major classes:)
Dendrite
:这是将信号从一个神经元传递到另一个神经元的基本单位.加权通过树枝状晶体传输的信号,以模拟通过的信号的强度.应当注意,此类仅公开一个属性-权重.(: This is the fundamental unit which transfers signal from one neuron to another. The signal transmitted through the dendrite is weighted to simulate the intensity of the signal being passed. It should be noted that this class exposes only one property - Weight.)
public class Dendrite
{
private double wt;
public double Weight
{
get { return wt; }
set { wt = value; }
}
//Provide a constructor for the class.
//It is always better to provide a constructor instead of using
//the compiler provided constructor
public Dendrite()
{
wt = getRandom(0.00000001, 1.0);
}
private double getRandom(double MinValue, double MaxValue)
{
return Util.GetRandomD() * (MaxValue - MinValue) + MinValue;
}
}
Neuron
:神经元是人工神经网络的基本组成部分.神经元暴露了其中的价值以及偏见.神经元还包含表示预期解决方案中的错误的属性.连同最重要的参数,树突.每个神经元将具有与上一层神经元数量一样多的树突.(: The neurons are the basic building blocks of the Artificial Neural Network. The neurons expose the value in it along with a bias. The neurons also contain properties representing the errors in the expected solutions. along with the most important parameter, the dendrites. Each neuron will have as many dendrites as the number of neurons in previous layer.)
class Neuron
{
private List<Dendrite> dendrites;
private double bias, delta, _value;
public double Bias
{
get
{ return bias; }
set
{ bias = value; }
}
public double Delta
{
get
{ return delta; }
set
{ delta = value; }
}
public double Value
{
get
{ return _value; }
set
{ _value = value; }
}
public void AddDendrites(int nDendrites)
{
int i;
//Dendrite d;
for(i=0;i<nDendrites;i++)
{
//d = new Dendrite();
dendrites.Add(new Dendrite());
}
}
public int nDendrites()
{
return dendrites.Count;
}
public Dendrite getDendrite(int index)
{
return dendrites[index];
}
public Neuron()
{
bias = Util.GetRandomD();
dendrites = new List<Dendrite>();
}
}
Layer
:图层类包含该图层中神经元的列表.(: The layer class contains a list of neurons in the layer.)
class Layer
{
private List<Neuron> neurons;
public void Clear()
{
neurons.Clear();
}
public void Initialize(int nNeurons)
{
int i;
for(i=0;i<nNeurons;i++)
{
neurons.Add(new Neuron());
}
}
public Neuron getNeuron(int index)
{
return neurons[index];
}
public void setNeuron(int index, ref Neuron neuron)
{
neurons[index] = neuron;
}
public void setNeuron(int index, Double value)
{
Neuron n = new Neuron();
n.Value = value;
neurons[index] = n;
}
public void AddDendritesToEachNeuron(int nDendrites)
{
int i;
for(i=0;i<neurons.Count;i++)
{
neurons[i].AddDendrites(nDendrites);
}
}
public int nNeurons()
{
return neurons.Count;
}
/// <summary>
/// Constructor of the class
/// </summary>
public Layer()
{
neurons = new List<Neuron>();
}
}
Network
:网络类包含一个层列表.因此,类层次结构可以显示为:(: The network class contains a list of layers. Thus, the class hierarchy can be shown as:)
网络->图层->神经元->树突(Network -> Layer -> Neuron -> Dendrite)
网络初始化后,将为树突分配随机权重.由于这些权重是随机的,因此生成的网络几乎无用.与相关的权重(Once the network is initialized, the dendrites are assigned random weights. As these weights are random, the generated network is hardly of any use. The weights associated with)每(each)为了获得有意义的结果,必须对枝晶进行微调.这就是所谓的培训.神经网络需要针对给定的一组输入和相应的输出数据进行训练.可用数据集称为训练集.训练集通常占可用数据总数的大约80-85%.剩余的可用数据用于确认训练.训练主要涉及确定输出节点处的误差,并以枝晶权重变化的形式分布.这种方法被称为(dendrite must be fine tuned in order to obtain meaningful results. This is known as training. A neural network requires to be trained for a given set of input and corresponding output data. The set of available data is known as Training Set. The training set usually forms approximately 80 - 85% of the total available data. The remaining available data is used to confirm the training. The training primarily involves determining the error at output node and distributing it in the form of change in dendrite weights. This method is known as)反向传播(Back Propagation).反向传播在数学上执行为(. Back propagation is mathematically performed as) 梯度下降法(gradient descent method) .建议读者参考对梯度下降法的描述性处理,并且不属于本文的讨论范围.(. Readers are recommended to refer to a descriptive treatment of gradient descent method and is considered to be out of scope for this article.)
- 网络的训练按以下方式进行:(The training of a network is performed in the following way:)
- 运行输入(Run the input)
- 计算输出神经元的误差(Calculate the error on the output neurons)
- 根据输出神经元上计算出的误差,调整树突的权重.(From the error computed on output neurons, adjust the weights in dendrites.)
- 对所有图层都这样做(Do this for all layers)
- 重复(Repeat) 当错误范数减少到阈值以下时,可以终止训练,也可以在一定数量的循环后终止训练.此代码运行一定数量的周期.(The training may be terminated when the error norm reduces below threshold or may be terminated after a definite number of cycles. This code runs for a definite number of cycles.)
一旦训练了网络(并确认了正确性),就可以输入输出未知的输入以获得输出.请注意,人工神经网络可能不会返回100%准确的结果.结果通常在可接受的精度范围内.(Once the network is trained (and correctness confirmed), inputs with unknown outputs may be entered to obtain the output. Note that Artificial Neural Networks may NOT return 100% accurate results. The results are usually within acceptable accuracy limits.)
兴趣点(Points of Interest)
各种启发式参数(例如学习率)需要大量经验,然后才能以良好的速度成功训练网络.此代码允许实验隐藏层的数量以及每个隐藏层中神经元的数量.该代码已通过正弦函数(介于0和1之间)和其他函数(例如加法,减法等)进行了测试,并且可以非常精确地工作.(Various heuristic parameters such as learning rate requires significant experience before the the network may successfully be trained at a good speed. This code allows experimenting with number of hidden layers and number of neurons in each hidden layer. The code has been tested with sinusoidal function (between 0 and 1) and other functions such as addition, substraction, etc and has been found to work with significant accuracy.)
历史(History)
这是代码的第一个版本.(This is the first version of the code.)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C# .NET Windows VS2013 Visual-Studio Architect Dev CEO artificial network 新闻 翻译