Click here to Skip to main content
15,879,184 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.1K   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 AdalineOneOptions.
	/// </summary>
	public class AdalineOneOptions : System.Windows.Forms.Form
	{
		private System.Windows.Forms.NumericUpDown numericUpDown1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;

		private int nNumberOfItems;
		private double dLearningRate;
		private bool bUseBias;

		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.CheckBox checkBox1;

		private Icon icon;


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

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

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

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

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


			this.Icon = icon;

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

			nNumberOfItems = 0;
		}

		public AdalineOneOptions( int nNumberOfItems, double dLearningRate, bool bUseBias )
		{
			InitializeComponent();

			this.nNumberOfItems = nNumberOfItems;
			numericUpDown1.Value = nNumberOfItems;
			textBox1.Text = dLearningRate.ToString();
			LearningRate = dLearningRate;
			this.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(AdalineOneOptions));
			this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
			this.label1 = new System.Windows.Forms.Label();
			this.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.label2 = new System.Windows.Forms.Label();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.checkBox1 = new System.Windows.Forms.CheckBox();
			((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
			this.SuspendLayout();
			// 
			// 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 = 0;
			// 
			// 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 = 1;
			this.label1.Text = "Number Of Items In File";
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(24, 120);
			this.button1.Name = "button1";
			this.button1.TabIndex = 2;
			this.button1.Text = "O.K.";
			this.button1.Click += new System.EventHandler(this.OnDialogOK);
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(176, 120);
			this.button2.Name = "button2";
			this.button2.TabIndex = 3;
			this.button2.Text = "Cancel";
			this.button2.Click += new System.EventHandler(this.OnDialogCancel);
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(16, 64);
			this.label2.Name = "label2";
			this.label2.TabIndex = 4;
			this.label2.Text = "Learning Rate";
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(152, 64);
			this.textBox1.Name = "textBox1";
			this.textBox1.TabIndex = 5;
			this.textBox1.Text = "textBox1";
			// 
			// checkBox1
			// 
			this.checkBox1.Location = new System.Drawing.Point(16, 88);
			this.checkBox1.Name = "checkBox1";
			this.checkBox1.TabIndex = 6;
			this.checkBox1.Text = "Use Bias";
			this.checkBox1.CheckedChanged += new System.EventHandler(this.OnUseBias);
			// 
			// AdalineOneOptions
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(292, 158);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.checkBox1,
																		  this.textBox1,
																		  this.label2,
																		  this.button2,
																		  this.button1,
																		  this.label1,
																		  this.numericUpDown1});
			
			this.Name = "AdalineOneOptions";
			this.Text = "AdalineOneOptions";
			((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion


		private void OnDialogOK(object sender, System.EventArgs e)
		{
			NumberOfItems = ( 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 OnDialogCancel(object sender, System.EventArgs e)
		{
			this.Close();
		}

		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