Click here to Skip to main content
15,892,005 members
Articles / Programming Languages / C#

Neural Dot Net Pt 3 The Adaline Network

Rate me:
Please Sign up or sign in to vote.
3.71/5 (16 votes)
23 Oct 200316 min read 73.3K   379   41  
A neural network library in C#.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace Neural_Net_Test
{
	/// <summary>
	/// Summary description for BackPropagationTwoOptions.
	/// </summary>
	public class BackPropagationTwoOptions : System.Windows.Forms.Form
	{
		private bool bBackPropagationTwoUseBias;
		private double dBackPropagationWordLearningRate;
		private double dBackPropagationWordMomentum;
		private double dBackPropagationWordTolerance;
		private string strBackPropagationWordOne;
		private string strBackPropagationWordTwo;
		private string strBackPropagationWordRunFile;
		private string strBackPropagationWordTrainingFile;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.CheckBox checkBoxUseBias;
		private System.Windows.Forms.TextBox textBoxLearningRate;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.TextBox textBoxMomentum;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox textBoxTolerance;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.TextBox textBoxWordOne;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.TextBox textBoxWordTwo;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.TextBox textBoxRunFile;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.TextBox textBoxTrainingFile;

		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public bool UseBias
		{
			get
			{
				return bBackPropagationTwoUseBias;
			}
			set
			{
				bBackPropagationTwoUseBias = value;
			}
		}

		public double LearningRate
		{
			get
			{
				return dBackPropagationWordLearningRate;
			}
			set
			{
				dBackPropagationWordLearningRate = value;
			}
		}

		public double Momentum
		{
			get
			{
				return dBackPropagationWordMomentum;
			}
			set
			{
				dBackPropagationWordMomentum = value;
			}
		}

		public double Tolerance
		{
			get
			{
				return dBackPropagationWordTolerance;
			}
			set
			{
				dBackPropagationWordTolerance = value;
			}
		}

		public string WordOne
		{
			get
			{
				return strBackPropagationWordOne;
			}
			set
			{
				strBackPropagationWordOne = value;
			}
		}

		public string WordTwo
		{
			get
			{
				return strBackPropagationWordTwo;
			}
			set
			{
				strBackPropagationWordTwo = value;
			}
		}

		public string RunFile
		{
			get
			{
				return strBackPropagationWordRunFile;
			}
			set
			{
				strBackPropagationWordRunFile = value;
			}
		}

		public string TrainingFile
		{
			get
			{
				return strBackPropagationWordTrainingFile;
			}
			set
			{
				strBackPropagationWordTrainingFile = value;
			}
		}

		public BackPropagationTwoOptions()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		public BackPropagationTwoOptions( bool bBackPropagationTwoUseBias, double dBackPropagationWordLearningRate, double dBackPropagationWordMomentum, double dBackPropagationWordTolerance, string strBackPropagationWordOne, string strBackPropagationWordTwo, string strBackPropagationWordRunFile, string strBackPropagationWordTrainingFile )
		{
			InitializeComponent();

			UseBias = bBackPropagationTwoUseBias;
			LearningRate = dBackPropagationWordLearningRate;
			Momentum = dBackPropagationWordMomentum;
			Tolerance = dBackPropagationWordTolerance;
			WordOne = strBackPropagationWordOne;
			WordTwo = strBackPropagationWordTwo;
			RunFile = strBackPropagationWordRunFile;
			TrainingFile = strBackPropagationWordTrainingFile;

			checkBoxUseBias.Checked = UseBias;
			textBoxLearningRate.Text = LearningRate.ToString();
			textBoxMomentum.Text = Momentum.ToString();
			textBoxTolerance.Text = Tolerance.ToString();
			textBoxWordOne.Text = WordOne;
			textBoxWordTwo.Text = WordTwo;
			textBoxRunFile.Text = RunFile;
			textBoxTrainingFile.Text = TrainingFile;
		}


		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(BackPropagationTwoOptions));
			this.button2 = new System.Windows.Forms.Button();
			this.button1 = new System.Windows.Forms.Button();
			this.checkBoxUseBias = new System.Windows.Forms.CheckBox();
			this.textBoxLearningRate = new System.Windows.Forms.TextBox();
			this.label4 = new System.Windows.Forms.Label();
			this.textBoxMomentum = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			this.textBoxTolerance = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.textBoxWordOne = new System.Windows.Forms.TextBox();
			this.label6 = new System.Windows.Forms.Label();
			this.textBoxWordTwo = new System.Windows.Forms.TextBox();
			this.label7 = new System.Windows.Forms.Label();
			this.textBoxRunFile = new System.Windows.Forms.TextBox();
			this.label8 = new System.Windows.Forms.Label();
			this.textBoxTrainingFile = new System.Windows.Forms.TextBox();
			this.SuspendLayout();
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(192, 280);
			this.button2.Name = "button2";
			this.button2.TabIndex = 21;
			this.button2.Text = "Cancel";
			this.button2.Click += new System.EventHandler(this.OnCancel);
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(24, 280);
			this.button1.Name = "button1";
			this.button1.TabIndex = 20;
			this.button1.Text = "OK";
			this.button1.Click += new System.EventHandler(this.OnOK);
			// 
			// checkBoxUseBias
			// 
			this.checkBoxUseBias.Location = new System.Drawing.Point(128, 120);
			this.checkBoxUseBias.Name = "checkBoxUseBias";
			this.checkBoxUseBias.TabIndex = 19;
			this.checkBoxUseBias.Text = "Use Bias";
			// 
			// textBoxLearningRate
			// 
			this.textBoxLearningRate.Location = new System.Drawing.Point(128, 80);
			this.textBoxLearningRate.Name = "textBoxLearningRate";
			this.textBoxLearningRate.TabIndex = 18;
			this.textBoxLearningRate.Text = "";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(24, 80);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(88, 23);
			this.label4.TabIndex = 17;
			this.label4.Text = "Learning Rate";
			// 
			// textBoxMomentum
			// 
			this.textBoxMomentum.Location = new System.Drawing.Point(128, 48);
			this.textBoxMomentum.Name = "textBoxMomentum";
			this.textBoxMomentum.TabIndex = 16;
			this.textBoxMomentum.Text = "textBox2";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(24, 48);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(88, 23);
			this.label3.TabIndex = 15;
			this.label3.Text = "Momentum";
			// 
			// textBoxTolerance
			// 
			this.textBoxTolerance.Location = new System.Drawing.Point(128, 16);
			this.textBoxTolerance.Name = "textBoxTolerance";
			this.textBoxTolerance.TabIndex = 14;
			this.textBoxTolerance.Text = "";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(24, 16);
			this.label2.Name = "label2";
			this.label2.TabIndex = 13;
			this.label2.Text = "Tolerance";
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(24, 144);
			this.label5.Name = "label5";
			this.label5.TabIndex = 22;
			this.label5.Text = "Word One";
			// 
			// textBoxWordOne
			// 
			this.textBoxWordOne.Location = new System.Drawing.Point(128, 144);
			this.textBoxWordOne.Name = "textBoxWordOne";
			this.textBoxWordOne.TabIndex = 23;
			this.textBoxWordOne.Text = "";
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(24, 176);
			this.label6.Name = "label6";
			this.label6.TabIndex = 24;
			this.label6.Text = "Word Two";
			// 
			// textBoxWordTwo
			// 
			this.textBoxWordTwo.Location = new System.Drawing.Point(128, 176);
			this.textBoxWordTwo.Name = "textBoxWordTwo";
			this.textBoxWordTwo.TabIndex = 25;
			this.textBoxWordTwo.Text = "textBox1";
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(24, 208);
			this.label7.Name = "label7";
			this.label7.TabIndex = 26;
			this.label7.Text = "Run File";
			// 
			// textBoxRunFile
			// 
			this.textBoxRunFile.Location = new System.Drawing.Point(128, 208);
			this.textBoxRunFile.Name = "textBoxRunFile";
			this.textBoxRunFile.TabIndex = 27;
			this.textBoxRunFile.Text = "textBox1";
			// 
			// label8
			// 
			this.label8.Location = new System.Drawing.Point(24, 240);
			this.label8.Name = "label8";
			this.label8.TabIndex = 28;
			this.label8.Text = "Training File";
			// 
			// textBoxTrainingFile
			// 
			this.textBoxTrainingFile.Location = new System.Drawing.Point(128, 240);
			this.textBoxTrainingFile.Name = "textBoxTrainingFile";
			this.textBoxTrainingFile.TabIndex = 29;
			this.textBoxTrainingFile.Text = "textBox2";
			// 
			// BackPropagationTwoOptions
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(292, 318);
			this.Controls.Add(this.textBoxTrainingFile);
			this.Controls.Add(this.label8);
			this.Controls.Add(this.textBoxRunFile);
			this.Controls.Add(this.label7);
			this.Controls.Add(this.textBoxWordTwo);
			this.Controls.Add(this.label6);
			this.Controls.Add(this.textBoxWordOne);
			this.Controls.Add(this.label5);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.checkBoxUseBias);
			this.Controls.Add(this.textBoxLearningRate);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.textBoxMomentum);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.textBoxTolerance);
			this.Controls.Add(this.label2);
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "BackPropagationTwoOptions";
			this.Text = "BackPropagationTwoOptions";
			this.ResumeLayout(false);

		}
		#endregion

		private void OnOK(object sender, System.EventArgs e)
		{
			double dTemp = 0.0;
			string strTemp = "";

			try
			{
				strTemp = textBoxTolerance.Text;
				dTemp = Double.Parse( strTemp );
				Tolerance = dTemp;
				strTemp = textBoxMomentum.Text;
				dTemp = Double.Parse( strTemp );
				Momentum = dTemp;
				strTemp = textBoxLearningRate.Text;
				dTemp = Double.Parse( strTemp );
				LearningRate = dTemp;

				if( textBoxWordOne.Text.Length == 0 )
				{
					MessageBox.Show( "Error cannot have an empty word one value" );
					return;
				}
				else
				{
					WordOne = textBoxWordOne.Text;
				}

				if( textBoxWordTwo.Text.Length == 0 )
				{
					MessageBox.Show( "Error cannot have an empty word two value " );
					return;
				}
				else
				{
					WordTwo = textBoxWordTwo.Text;
				}

				if( textBoxRunFile.Text.Length == 0 )
				{
					MessageBox.Show( "Error you must name the file to run against " );
					return;
				}
				else
				{
					RunFile = textBoxRunFile.Text;
				}

				if( textBoxTrainingFile.Text.Length == 0 )
				{
					MessageBox.Show( "Error you must name the file for training " );
					return;
				}
				else
				{
					TrainingFile = textBoxTrainingFile.Text;
				}

			}
			catch( ArgumentNullException argNullExp )
			{
				MessageBox.Show( "Error Argument Null Exception thrown by data entered, Please try again" + argNullExp.Message );
				return;
			}
			catch( FormatException formExp )
			{
				MessageBox.Show( "Error the data has to be in double format, you entered " + strTemp + formExp.Message );
				return;
			}
			catch( OverflowException overExp )
			{
				MessageBox.Show( "Error the number you entered is too large or too small " + overExp.Message );
				return;
			}

			this.Close();
		
		}

		private void OnCancel(object sender, System.EventArgs e)
		{
			this.Close();
		}
	}
}

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions