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

Fuzzy Logic Vs Adaline Neural Network

, 29 Oct 2003
An experiment to see if it possible to duplicate the behavior of the Adaline Network using Fuzzy Logic.
fuzzylogicvadaline.zip
Fuzzy Logic Vs Adaline Neural Network
Fuzzy Logic Library
Fuzzy Logic Library.csproj.user
Fuzzy Logic Vs Adaline Neural Network
App.ico
bin
Debug
Fuzzy Logic Library.dll
Fuzzy Logic Vs Adaline Neural Network.exe
Lin2Var.trn
Fuzzy Logic Vs Adaline Neural Network.csproj.user
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

Share

About the Author

pseudonym67

United Kingdom United Kingdom
No Biography provided

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