Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

Neural Dot Net Pt 11 A Conclusion Of Sorts

, 9 Dec 2003
A neural network library in C#.
neural_dot_net_2002.zip
Neural Dot Net 2002
App.ico
bin
Debug
AdalineWordFile.dat
adalinewordWorkingFile.wrk
adword.trn
App.ico
BackpropagationWorkingFile.wrk
Lin2Var.trn
Neural Dot Net 2002.exe
Neural Net Library.dll
SelfOrganizingNetworkOne.trn
SelfOrganizingNetworkOne.wrk
SelfOrganizingNetworkOneTest.tst
SharpUtils.dll
equations.Bak
Neural Dot Net 2002.csproj.user
Neural Net Library
bin
Debug
Neural Net Library.csproj.user
obj
Debug
temp
TempPE
SharpUtils
bin
Debug
obj
Debug
temp
TempPE
SharpUtils.csproj.user

using System;
using System.Collections;
using SharpUtils;
using System.Xml.Serialization;

namespace Neural_Net_Library
{
	/// <summary>
	/// Summary description for Pattern.
	/// </summary>
	public class Pattern
	{
		private ArrayList arrayInSet;
		private ArrayList arrayOutSet;
		private static int nPatternID = 0;
		private int nCurrentID;


		private DebugLevel debugLevel;
		private Logger log;

		/// <summary>
		/// get the in set array
		/// </summary>
		public ArrayList InSet
		{
			get
			{
				return arrayInSet;
			}
		}

		/// <summary>
		/// get the out set array
		/// </summary>
		public ArrayList OutSet
		{
			get
			{
				return arrayOutSet;
			}
		}

		/// <summary>
		/// get the pattern id
		/// </summary>
		public int PatternID
		{
			get
			{
				return nCurrentID;
			}
		}

		/// <summary>
		/// base constructor
		/// </summary>
		public Pattern( Logger log )
		{


			arrayInSet = new ArrayList();
			arrayOutSet = new ArrayList();
			nPatternID++;
			nCurrentID = nPatternID;

			debugLevel = new DebugLevel( DebugLevel.currentLevel );
			this.log = log;
		}

		/// <summary>
		/// constructor taking the array sizes
		/// </summary>
		/// <param name="nInSize"></param>
		/// <param name="nOutSize"></param>
		public Pattern( Logger log, int nInSize, int nOutSize )
		{
			arrayInSet = new ArrayList( nInSize );
			for( int i=0; i<nInSize; i++ )
				arrayInSet.Add( 0.0 );
			arrayOutSet = new ArrayList( nOutSize );
			for( int i=0; i<nOutSize; i++ )
				arrayOutSet.Add( 0.0 );
			nPatternID++;
			nCurrentID = nPatternID;

			debugLevel = new DebugLevel( DebugLevel.currentLevel );
			this.log = log;
		}

		/// <summary>
		/// constructor taking array lists
		/// </summary>
		/// <param name="arrayInSet"></param>
		/// <param name="arrayOutSet"></param>
		public Pattern( Logger log, ArrayList arrayInSet, ArrayList arrayOutSet )
		{
			arrayInSet = arrayInSet;
			arrayOutSet = arrayOutSet;
			nPatternID++;
			nCurrentID = nPatternID;

			debugLevel = new DebugLevel( DebugLevel.currentLevel );
			this.log = log;
		}


		public Pattern( Logger log, double inputOne, double inputTwo, double output )
		{
			debugLevel = new DebugLevel( DebugLevel.currentLevel );
			this.log = log;

			arrayInSet = new ArrayList();
			arrayInSet.Add( inputOne );
			arrayInSet.Add( inputTwo );
			arrayOutSet = new ArrayList();
			arrayOutSet.Add( output );

			nPatternID++;
			nCurrentID = nPatternID;

		}

		/// <summary>
		/// save the pattern
		/// </summary>
		public virtual void Save()
		{
			if( debugLevel.TestDebugLevel( DebugLevelSet.Progress ) == true )
			{
				log.Log( DebugLevelSet.Progress, "Save called on Pattern", ClassName );
			}
		
		}

		/// <summary>
		/// load the pattern
		/// </summary>
		public virtual void Load()
		{
			if( debugLevel.TestDebugLevel( DebugLevelSet.Progress ) == true )
			{
				log.Log( DebugLevelSet.Progress, "Load called on pattern", ClassName );
			}
		}

		/// <summary>
		/// make a copy of the pattern
		/// </summary>
		/// <param name="pattern"></param>
		public void Copy( Pattern pattern )
		{
			if( debugLevel.TestDebugLevel( DebugLevelSet.Progress ) == true )
			{
				log.Log( DebugLevelSet.Progress, "Copying the pattern", ClassName );
			}

			arrayInSet = ( ArrayList )pattern.InSet.Clone();
			arrayOutSet = ( ArrayList )pattern.OutSet.Clone();
			nPatternID = pattern.PatternID;
		}


		/// <summary>
		/// set the input value
		/// </summary>
		/// <param name="nIndex"></param>
		/// <param name="dValue"></param>
		public void SetInValue( int nIndex, double dValue )
		{
			if( debugLevel.TestDebugLevel( DebugLevelSet.Progress ) == true )
			{
				log.Log( DebugLevelSet.Progress, "setting the input value at " + nIndex.ToString() + " to " + dValue.ToString(), ClassName );
			}

			try
			{
				arrayInSet[ nIndex ] = dValue;
			}
			catch( ArgumentOutOfRangeException argorExp )
			{
				arrayInSet.Add( dValue );
				if( debugLevel.TestDebugLevel( DebugLevelSet.Warning ) == true )
				{
					log.Log( DebugLevelSet.Warning, "The index the array in set in value is greater than the array count, adding it, reason " + argorExp.Message, ClassName );
				}
			}
		}


		/// <summary>
		/// set the output value
		/// </summary>
		/// <param name="nIndex"></param>
		/// <param name="dValue"></param>
		public void SetOutValue( int nIndex, double dValue )
		{
			if( debugLevel.TestDebugLevel( DebugLevelSet.Progress ) == true )
			{
				log.Log( DebugLevelSet.Progress, "Setting the out value at " + nIndex.ToString() + " to " + dValue.ToString(), ClassName );
			}

			try
			{
				arrayOutSet[ nIndex ] = dValue;
			}
			catch( ArgumentOutOfRangeException argorExp )
			{
				arrayOutSet.Add( dValue );
				if( debugLevel.TestDebugLevel( DebugLevelSet.Warning ) == true )
				{
					log.Log( DebugLevelSet.Warning, "The index for the array set out value is greater than the array count, adding it, reason " + argorExp.Message, ClassName );
				}
			}
		}

		/// <summary>
		/// get the input value at the given index
		/// </summary>
		/// <param name="nIndex"></param>
		/// <returns></returns>
		public double InputValue( int nIndex )
		{
			if( debugLevel.TestDebugLevel( DebugLevelSet.Progress ) == true )
			{
				log.Log( DebugLevelSet.Progress, "Getting the input value at " + nIndex.ToString(), ClassName );
			}

			if( nIndex < arrayInSet.Count )
				return ( double )arrayInSet[ nIndex ];
			else
			{
				if( debugLevel.TestDebugLevel( DebugLevelSet.Warning ) == true )
				{
					log.Log( DebugLevelSet.Warning, "The index value to get the input value is greater than the array count", ClassName );
				}

				return 0.0;
			}
		}

		/// <summary>
		/// get the output value at the given index
		/// </summary>
		/// <param name="nIndex"></param>
		/// <returns></returns>
		public double OutputValue( int nIndex )
		{
			if( debugLevel.TestDebugLevel( DebugLevelSet.Progress ) == true )
			{
				log.Log( DebugLevelSet.Progress, "Getting the output value at " + nIndex.ToString(), ClassName );
			}

			if( nIndex < arrayOutSet.Count )
				return ( double )arrayOutSet[ nIndex ];
			else
			{
				if( debugLevel.TestDebugLevel( DebugLevelSet.Warning ) == true )
				{
					log.Log( DebugLevelSet.Warning, "the index value to get the output value is greater than the array count", ClassName );
				}

				return 0.0;
			}
		}

		public int InputSize()
		{
			return arrayInSet.Count;
		}

		public int OutputSize()
		{
			return arrayOutSet.Count;
		}


		public string ClassName
		{
			get
			{
				return this.ToString();
			}
		}
			
	}
}

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

Share

About the Author

pseudonym67

United Kingdom United Kingdom
No Biography provided

| Advertise | Privacy | Mobile
Web03 | 2.8.140926.1 | Last Updated 10 Dec 2003
Article Copyright 2003 by pseudonym67
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid