Click here to Skip to main content
15,883,901 members
Articles / Programming Languages / C#

Fuzzy Logic Vs Adaline Neural Network

Rate me:
Please Sign up or sign in to vote.
4.30/5 (8 votes)
29 Oct 20038 min read 91.5K   1.6K   33  
An experiment to see if it possible to duplicate the behavior of the Adaline Network using Fuzzy Logic.
using System;
using System.Collections;

namespace Fuzzy_Logic_Library
{
	/// <summary>
	/// Fuzzy pattern class basically a storage class for holding data
	/// completely ripped off from the pattern class in the neural network library
	/// </summary>
	public class FuzzyPattern
	{
		private ArrayList arrayInSet;
		private ArrayList arrayOutSet;
		private static int nPatternID = 0;
		private int nCurrentID;


		public FuzzyPattern()
		{
			//
			// TODO: Add constructor logic here
			//
			arrayInSet = new ArrayList();
			arrayOutSet = new ArrayList();
			nPatternID++;
			nCurrentID = nPatternID;

		}


		/// <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>
		/// constructor taking the array sizes
		/// </summary>
		/// <param name="nInSize"></param>
		/// <param name="nOutSize"></param>
		public FuzzyPattern( 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;

		}

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


		public FuzzyPattern( double inputOne, double inputTwo, double output )
		{

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

			nPatternID++;
			nCurrentID = nPatternID;

		}



		/// <summary>
		/// set the input value
		/// </summary>
		/// <param name="nIndex"></param>
		/// <param name="dValue"></param>
		public void SetInValue( int nIndex, double dValue )
		{
			if( nIndex < arrayInSet.Count )
				arrayInSet[ nIndex ] = dValue;
			else
				arrayInSet.Add( dValue );
		}

		/// <summary>
		/// set the output value
		/// </summary>
		/// <param name="nIndex"></param>
		/// <param name="dValue"></param>
		public void SetOutValue( int nIndex, double dValue )
		{

			if( nIndex < arrayOutSet.Count )
				arrayOutSet[ nIndex ] = dValue;
			else
				arrayOutSet.Add( dValue );
		}

		/// <summary>
		/// get the input value at the given index
		/// </summary>
		/// <param name="nIndex"></param>
		/// <returns></returns>
		public double InputValue( int nIndex )
		{
			if( nIndex < arrayInSet.Count )
				return ( double )arrayInSet[ nIndex ];
			else
				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( nIndex < arrayOutSet.Count )
				return ( double )arrayOutSet[ nIndex ];
			else
			{
				return 0.0;
			}
		}

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

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

	}

	public class FuzzyIntegerPattern : FuzzyPattern
	{
		public FuzzyIntegerPattern() : base()
		{
		}

		public FuzzyIntegerPattern( int nInSize, int nOutSize ) : base( nInSize, nOutSize )
		{
		}

		/// <summary>
		/// constructor taking array lists
		/// </summary>
		/// <param name="arrayInSet"></param>
		/// <param name="arrayOutSet"></param>
		public FuzzyIntegerPattern( ArrayList arrayInSet, ArrayList arrayOutSet ) : base( arrayInSet, arrayOutSet )
		{
		}


		public FuzzyIntegerPattern( FuzzyInteger inputOne, FuzzyInteger inputTwo, double output ) : base()
		{
			this.InSet.Add( inputOne );
			this.InSet.Add( inputTwo );
			this.OutSet.Add( output );
		}

		public FuzzyIntegerPattern( FuzzyInteger inputOne, FuzzyInteger inputTwo ) : base()
		{
			this.InSet.Add( inputOne );
			this.InSet.Add( inputTwo );
		}

		new public FuzzyInteger InputValue( int nIndex )
		{

			if( nIndex < this.InSet.Count )
				return ( FuzzyInteger )this.InSet[ nIndex ];
			else
			{
				return new FuzzyInteger();
			}
		}

		public void SetInValue( int nIndex, FuzzyInteger nValue )
		{		
			if( nIndex < this.InSet.Count )
				this.InSet[ nIndex ] = nValue;
			else
				this.InSet.Add( nValue );
		}
			
	}

	public class FuzzyDoublePattern : FuzzyPattern
	{
		public FuzzyDoublePattern() : base()
		{
		}

		public FuzzyDoublePattern( int nInSize, int nOutSize ) : base( nInSize, nOutSize )
		{
		}

		/// <summary>
		/// constructor taking array lists
		/// </summary>
		/// <param name="arrayInSet"></param>
		/// <param name="arrayOutSet"></param>
		public FuzzyDoublePattern( ArrayList arrayInSet, ArrayList arrayOutSet ) : base( arrayInSet, arrayOutSet )
		{
		}


		public FuzzyDoublePattern( FuzzyInteger inputOne, FuzzyInteger inputTwo, double output ) : base()
		{
			this.InSet.Add( inputOne );
			this.InSet.Add( inputTwo );
			this.OutSet.Add( output );
		}

		public FuzzyDoublePattern( FuzzyInteger inputOne, FuzzyInteger inputTwo ) : base()
		{
			this.InSet.Add( inputOne );
			this.InSet.Add( inputTwo );
		}

		new public FuzzyDouble InputValue( int nIndex )
		{

			if( nIndex < this.InSet.Count )
				return ( FuzzyDouble )this.InSet[ nIndex ];
			else
			{
				return new FuzzyDouble();
			}
		}

		public void SetInValue( int nIndex, FuzzyDouble nValue )
		{		
			if( nIndex < this.InSet.Count )
				this.InSet[ nIndex ] = nValue;
			else
				this.InSet.Add( nValue );
		}
			
	}
}

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