欢迎来到虫虫下载站 | 资源下载 资源专辑 关于我们
虫虫下载站

predefinedtestdata (xor tests).cs

Handwriting recognition
CS
字号:
using System;

namespace XOR_ANN.DataStructures
{
	/// <summary>
	/// Summary description for XORData.
	/// </summary>
	public class PredefinedTestData
	{
		public float[][]		sampleData		= new float[4][];
		public float[]			expectedResults = new float[4];
		public float[][]		hiddenWeights	= new float[2][];
		public float[][]		outputWeights	= new float[1][];
	
		public static ANN_Data createXOR(int pHiddenNodes)
		{
			// initialise
			ANN_Data	xorData	= new ANN_Data(2,pHiddenNodes,1,4); // 2 Inputs, 2 hidden Nodes, 1 Output, 4 samples
			
			// randomised weights
			//			setTrainedXORWeights(ref xorData);

			// load sample and expected output data
			float[,] sampleData		= {{0, 0},{0, 1},{1, 0},{1, 1}};	//new float[4,2];
			float[,] expectedOutput = {{0},   {1},   {1},   {0}};		//new float[4,1];

			xorData.loadSampleData(sampleData);
			xorData.loadExpectedOutputData(expectedOutput);
			
			// return a point to the predefined test data
			return (xorData);
		}

		public static ANN_Data createXOR2Outputs(int pHiddenNodes)
		{
			// initialise
			ANN_Data	xorData	= new ANN_Data(2,pHiddenNodes,2,4); // 2 Inputs, 2 hidden Nodes, 2 Output, 4 samples
			
			// randomised weights
			//			setTrainedXORWeights(ref xorData);

			// load sample and expected output data
			float[,] sampleData		= {{0, 0},{0, 1},{1, 0},{1, 1}};	//new float[4,2];
			float[,] expectedOutput = {{0,1}, {1,0}, {1,0}, {0,1}};

			xorData.loadSampleData(sampleData);
			xorData.loadExpectedOutputData(expectedOutput);
			
			// return a point to the predefined test data
			return (xorData);
		}

		public static ANN_Data createBinary10Outputs(int pHiddenNodes)
		{
			// initialise
			ANN_Data	binaryData	= new ANN_Data(4,pHiddenNodes,10,10); // 4 Inputs, hidden Nodes, 10 Output, 10 samples
			
			// randomised weights
			// load sample and expected output data
			float[,] sampleData		= { {0, 0, 0, 0}, /* 0 */
										{0, 0, 0, 1}, /* 1 */
										{0, 0, 1, 0}, /* 2 */
										{0, 0, 1, 1}, /* 3 */
										{0, 1, 0, 0}, /* 4 */
										{0, 1, 0, 1}, /* 5 */
										{0, 1, 1, 0}, /* 6 */
										{0, 1, 1, 1}, /* 7 */
										{1, 0, 0, 0}, /* 8 */
										{1, 0, 0, 1}, /* 9 */
										{1, 0, 1, 0}}; /* 10 */
			float[,] expectedOutput = { {1,0,0,0,0,0,0,0,0,0},
										{0,1,0,0,0,0,0,0,0,0},
										{0,0,1,0,0,0,0,0,0,0},
										{0,0,0,1,0,0,0,0,0,0},
										{0,0,0,0,1,0,0,0,0,0},
										{0,0,0,0,0,1,0,0,0,0},
										{0,0,0,0,0,0,1,0,0,0},
										{0,0,0,0,0,0,0,1,0,0},
										{0,0,0,0,0,0,0,0,1,0},
										{0,0,0,0,0,0,0,0,0,1}};

			binaryData.loadSampleData(sampleData);
			binaryData.loadExpectedOutputData(expectedOutput);
			
			// return a point to the predefined test data
			return (binaryData);
		}

		private static void setTrainedXORWeights(ref ANN_Data pAnn_Data) 
		{

			// set the weights
			pAnn_Data.hiddenWeight[0,0] = -4.06935F;
			pAnn_Data.hiddenWeight[0,1] = -4.06755F;
			pAnn_Data.hiddenWeight[0,2] = 6.09254F;	// bias
			
			pAnn_Data.hiddenWeight[1,0] = -4.51654F;
			pAnn_Data.hiddenWeight[1,1] = -4.51325F;
			pAnn_Data.hiddenWeight[1,2] = 1.62724F;	// bias
			
			pAnn_Data.outputWeight[0,0] = 6.0503F;
			pAnn_Data.outputWeight[0,1] = -6.70904F;
			pAnn_Data.outputWeight[0,2] = -2.73463F;// bias
		}
	}
}

⌨️ 快捷键说明

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