I have been looking at Neural Network Design (Chinese version) for the past two days. I don't know much about it in some places. Therefore, you can write your own code to deepen your understanding.
By the way, paste the code. Let's take a look. C. The Code has been explained in detail.
Pay one
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Namespace neuralnetworks
{
/// <Summary>
// Reference: Neural Network Design-Chinese Version chapter 4th
/// Fun:
/// </Summary>
Class singleperceptron
{
//
Int r, s; // R is the dimension of the input vector, and s is the dimension of the output vector. Here S = 1;
Public double [,] W; // weight matrix = int [s, R]
Public double [,] B; // offset vector B = [s, 1]
Public singleperceptron (INT inputdimension, int outputdimension)
{
R = inputdimension;
S = outputdimension;
Init ();
}
Private void Init ()
{
// Initialize the Sensor
W = new double [s, R];
B = new double [s, 1];
// W [0, 0] = 0.5;
// W [0, 1] =-1;
// W [0, 2] =-0.5;
// B [0, 0] = 0.5;
}
Public void train (double [,] inputs, int [] outputs)
{
// Train the sensor. For more information, see p42.
Int samplecount = inputs. getlength (0); // number of samples in the training set
Bool error = true; // The calculation result is inconsistent with the target
Double sum;
Int E;
While (error)
{
// Update W, B iteratively using the training set
Error = false;
For (Int J = 0; j <samplecount; j ++)
{
For (INT I = 0; I <s; I ++)
{
// W [I] * inputs [J] + B [I], W [I] is r-dimensional, and B [I] is 1-dimensional
// A matrix operation function will be written here for Standardization. Use the for statement directly.
Sum = 0;
For (INT h = 0; H <r; H ++)
{
Sum = sum + W [I, H] * inputs [J, H];
}
Sum = sum + B [I, 0];
// Transfer Functions
// Calculate the e value
E = outputs [J]-transmissionfun. hardlim (sum, 0 );
// Modify the weight
If (E! = 0)
{
Error = true;
For (INT h = 0; H <r; H ++)
{
W [I, H] = W [I, H] + E * inputs [J, H];
}
B [I, 0] = B [I, 0] + E;
}
//
}
}
}
}
Public int SIM (double [] input)
{
Double sum = 0;
For (INT I = 0; I <s; I ++)
{
For (INT h = 0; H <r; H ++)
{
Sum = sum + W [I, H] * input [H];
}
Sum = sum + B [I, 0];
}
Return transmissionfun. hardlim (sum, 0 );
}
Public void tostring ()
{
}
}
Static class transmissionfun
{
Static public int hardlim (Double V, double thresh)
{
If (V> = thresh)
Return 1;
Return 0;
}
}
}