⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 model - ann_data.cs

📁 Handwriting recognition
💻 CS
字号:
using System;

/* NOTES
 * 
 * Only works for a TWO Layer perceptron (one Hidden Layer)
 * 
 */

namespace XOR_ANN.DataStructures
{
	/// <summary>
	/// Summary description for ANN_Data.
	/// </summary>
	public class ANN_Data
	{
		public	float[,] hiddenWeight;		// [hidden node][weight]
		public	float[,] outputWeight;		// [output node][weight]
		public	float[,] sampleInput;		// [s][j]
		public	float[,] expectedOutput;	// [s][j]

		public  int inputNodes;
		public  int hiddenNodes;
		public  int outputNodes;
		public  int sampleCount;

		private	Random	randomNumberGenerator = new Random(3242);	// xyzzy Seed from System clock

		// Constructor
		public ANN_Data(int pInputNodes, int pHiddenNodes, int pOutputNodes, int pSampleCount)
		{
			//
			// TODO: Add constructor logic here
			//
			this.inputNodes			= pInputNodes;
			this.hiddenNodes		= pHiddenNodes;
			this.outputNodes		= pOutputNodes;
			this.sampleCount		= pSampleCount;

			// Each hidden unit has an array of size: number of Inputs + 1 (for bias)
			// Note: pHiddenNodes is usually equal to pInputCount
			this.hiddenWeight		= new float[this.hiddenNodes, this.inputNodes + 1];
			// Each output unit has an array of size: number of Hidden Units + 1 (for bias)
			this.outputWeight		= new float[this.outputNodes, this.hiddenNodes + 1];

			// Initialise space for sample and expected outputs
			this.sampleInput		= new float[this.sampleCount, this.inputNodes];
			this.expectedOutput		= new float[this.sampleCount, this.outputNodes];
			
			// Randomize the weights
			this.randomizeWeights();
		}

		public void loadSampleData(float[,] pSampleData) 
		{
			this.sampleInput = pSampleData;
		}

		public void loadExpectedOutputData(float[,] pOuputData) 
		{
			this.expectedOutput	= pOuputData;
		}

		private void randomizeWeights() 
		{
			// Hidden Layer
			for (int layerNode=0; layerNode<this.hiddenNodes; layerNode++)
			{
				// Loop for all the input nodes
				for (int arrayIndex=0; arrayIndex<=this.inputNodes; arrayIndex++) //<= because we need to add a bias weight
				{
					this.hiddenWeight[layerNode,arrayIndex] = this.randomNumber();
				}
			}

			// Output Layer
			for (int layerNode=0; layerNode<this.outputNodes; layerNode++)
			{
				// Loop for all the input nodes
				for (int arrayIndex=0; arrayIndex<=this.hiddenNodes; arrayIndex++) //<= because we need to add a bias weight
				{
					this.outputWeight[layerNode,arrayIndex] = this.randomNumber();
				}
			}
		}

		private float randomNumber() 
		{
			float max	= 0.3F;	// Will generate a number from >-max and <+max
			float range = 2F * max;
			float random = (float)(randomNumberGenerator.NextDouble()*range) - max;
			return (random);
		}

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -