Click here to Skip to main content
15,886,362 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.2K   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 AdalineTwoOptions.
	/// </summary>
	public class AdalineTwoOptions : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Button button3;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.NumericUpDown numericUpDown1;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		private double dLearningRate;
		private System.Windows.Forms.CheckBox checkBox1;
		private int nNumberOfItems;
		private bool bUseBias = false;

		private Icon icon;

		public int NumberOfWords
		{
			get
			{
				return nNumberOfItems;
			}
			set
			{
				nNumberOfItems = value;
			}
		}

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

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


		public AdalineTwoOptions()
		{
			icon = new Icon( "App.ico" );
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			this.Icon = icon; 

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

		public AdalineTwoOptions( int nNumberOfWords, double dLearningRate, bool bUseBias )
		{
			InitializeComponent();

			LearningRate = dLearningRate;
			NumberOfWords = nNumberOfWords;

			numericUpDown1.Value = NumberOfWords;
			
			textBox1.Text = LearningRate.ToString();
			checkBox1.Checked = bUseBias;
		}

		/// <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(AdalineTwoOptions));
			this.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.button3 = new System.Windows.Forms.Button();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
			this.checkBox1 = new System.Windows.Forms.CheckBox();
			((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
			this.SuspendLayout();
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(56, 144);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(168, 23);
			this.button1.TabIndex = 0;
			this.button1.Text = "Add Word To Words File";
			this.button1.Click += new System.EventHandler(this.OnAddWordsToAdalineTwoFile);
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(16, 184);
			this.button2.Name = "button2";
			this.button2.TabIndex = 1;
			this.button2.Text = "OK";
			this.button2.Click += new System.EventHandler(this.OnOK);
			// 
			// button3
			// 
			this.button3.Location = new System.Drawing.Point(176, 184);
			this.button3.Name = "button3";
			this.button3.TabIndex = 2;
			this.button3.Text = "Cancel";
			this.button3.Click += new System.EventHandler(this.OnCancel);
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(152, 64);
			this.textBox1.Name = "textBox1";
			this.textBox1.TabIndex = 9;
			this.textBox1.Text = "textBox1";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(16, 64);
			this.label2.Name = "label2";
			this.label2.TabIndex = 8;
			this.label2.Text = "Learning Rate";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(16, 24);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(128, 23);
			this.label1.TabIndex = 7;
			this.label1.Text = "Number Of Items In File";
			// 
			// numericUpDown1
			// 
			this.numericUpDown1.Location = new System.Drawing.Point(152, 24);
			this.numericUpDown1.Maximum = new System.Decimal(new int[] {
																		   500,
																		   0,
																		   0,
																		   0});
			this.numericUpDown1.Name = "numericUpDown1";
			this.numericUpDown1.TabIndex = 6;
			// 
			// checkBox1
			// 
			this.checkBox1.Location = new System.Drawing.Point(16, 104);
			this.checkBox1.Name = "checkBox1";
			this.checkBox1.TabIndex = 10;
			this.checkBox1.Text = "Use Bias";
			this.checkBox1.CheckedChanged += new System.EventHandler(this.OnUseBias);
			// 
			// AdalineTwoOptions
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(292, 230);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.checkBox1,
																		  this.textBox1,
																		  this.label2,
																		  this.label1,
																		  this.numericUpDown1,
																		  this.button3,
																		  this.button2,
																		  this.button1});

			this.Name = "AdalineTwoOptions";
			this.Text = "AdalineTwoOptions";
			((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void OnOK(object sender, System.EventArgs e)
		{
			NumberOfWords = ( int )numericUpDown1.Value;
			double dTemp = 0.0;
			string strTemp = textBox1.Text;

			try
			{
				dTemp = Double.Parse( strTemp );
				LearningRate = dTemp;
			}
			catch( ArgumentNullException argNullExp )
			{
				MessageBox.Show( "Error Argument Null Exception thrown by data entered into the Learning Rate, Please try again" + argNullExp.Message );
				return;
			}
			catch( FormatException formExp )
			{
				MessageBox.Show( "Error the Learning rate has to be in double format ie default is 0.45 you entered " + strTemp + formExp.Message );
				return;
			}
			catch( OverflowException overExp )
			{
				MessageBox.Show( "Error the number you entered for the Learning rate is too large or too small " + overExp.Message );
				return;
			}

			this.Close();
		
		}

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

		private void OnAddWordsToAdalineTwoFile(object sender, System.EventArgs e)
		{
			AddWordToAdalineWordFile dialog = new AddWordToAdalineWordFile();

			dialog.ShowDialog();			  
		
		}

		private void OnUseBias(object sender, System.EventArgs e)
		{
			if( checkBox1.Checked == true )
				UseBias = true;
			else
				UseBias = false;
		}
		
	}
}

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