13,055,408 members (54,410 online)

#### Stats

81.3K views
32 bookmarked
Posted 29 Oct 2003

# 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.
 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; namespace Fuzzy_Logic_Library { /// /// Fuzzy number class deals with fuzzy numbers /// public class FuzzyNumber : FuzzyBasic { public FuzzyNumber() : base() { // // TODO: Add constructor logic here // } public FuzzyNumber( double number ) : base() { Number = number; } public FuzzyNumber( FuzzyNumber fuzzy ) : base() { this.ID = fuzzy.ID; this.Maximum = fuzzy.Maximum; this.Membership = fuzzy.Membership; this.Minimum = fuzzy.Minimum; this.Name = fuzzy.Name; this.Number = fuzzy.Number; } public FuzzyNumber( double rangeLow, double rangeHigh ) : base() { Minimum = rangeLow; Maximum = rangeHigh; Number = rangeLow + ( ( rangeHigh - rangeLow ) /2 ); Membership = 1.0; } public FuzzyNumber( double number, double rangeLow, double rangeHigh ) : base() { Minimum = rangeLow; Maximum = rangeHigh; Number = number; Membership = 0.0; SetMembership(); } public FuzzyNumber( string name, double number ) { Minimum = number - 10; Maximum = number + 10; Number = number; SetMembership(); Name = name; } public FuzzyNumber( string name, double number, double rangeLow, double rangeHigh ) : base() { Minimum = rangeLow; Maximum = rangeHigh; Number = number; SetMembership(); Name = name; } public FuzzyNumber( string name, double rangeLow, double rangeHigh ) : base() { Minimum = rangeLow; Maximum = rangeHigh; Number = rangeLow + ( ( rangeHigh - rangeLow ) / 2 ); Membership = 1.0; Name = name; } public FuzzyNumber( string name, double number, double rangeLow, double rangeHigh, bool bUseMaxAsComplete ) : base() { Minimum = rangeLow; if( bUseMaxAsComplete == true ) Maximum = rangeHigh + rangeHigh; else Maximum = rangeHigh; Number = number; Membership = 0.0; Name = name; SetMembership(); } public override string ToString() { return base.ToString() + ", Number = " + Number.ToString() + ", Minimum = " + Minimum.ToString() + ", Maximum = " + Maximum.ToString() + ", Membership = " + Membership.ToString(); } /// /// Overloaded operators Note no attempt is made to check for minimum and maximum /// values this is up to the code using the class /// public static FuzzyNumber operator +( FuzzyNumber num, double number ) { FuzzyNumber fuzzTemp = new FuzzyNumber( num.Number + number, num.Minimum, num.Maximum ); fuzzTemp.SetMembership(); return fuzzTemp; } public static FuzzyNumber operator +( FuzzyNumber num, FuzzyNumber number ) { FuzzyNumber fuzzTemp = new FuzzyNumber( num.Number + number.Number, num.Minimum, num.Maximum ); fuzzTemp.SetMembership(); return fuzzTemp; } public static FuzzyNumber operator -( FuzzyNumber num, double number ) { FuzzyNumber fuzzTemp = new FuzzyNumber( num.Number - number, num.Minimum, num.Maximum ); fuzzTemp.SetMembership(); return fuzzTemp; } public static FuzzyNumber operator -( FuzzyNumber num, FuzzyNumber number ) { FuzzyNumber fuzzTemp = new FuzzyNumber( num.Number - number.Number, num.Minimum, num.Maximum ); fuzzTemp.SetMembership(); return fuzzTemp; } public static FuzzyNumber operator *( FuzzyNumber num, double number ) { FuzzyNumber fuzzTemp; if( num.Number == 0.0 || number == 0.0 ) { fuzzTemp = new FuzzyNumber( num.Number, num.Minimum, num.Maximum ); fuzzTemp.SetMembership(); return fuzzTemp; } fuzzTemp = new FuzzyNumber( num.Number * number, num.Minimum, num.Maximum ); fuzzTemp.SetMembership(); return fuzzTemp; } public static FuzzyNumber operator *( FuzzyNumber num, FuzzyNumber number ) { FuzzyNumber fuzzTemp; if( num.Number == 0.0 || number.Number == 0.0 ) { fuzzTemp = new FuzzyNumber( num.Number, num.Minimum, num.Maximum ); fuzzTemp.SetMembership(); return fuzzTemp; } fuzzTemp = new FuzzyNumber( num.Number * number.Number, num.Minimum, num.Maximum ); fuzzTemp.SetMembership(); return fuzzTemp; } public static FuzzyNumber operator /( FuzzyNumber num, double number ) { FuzzyNumber fuzzTemp; if( num.Number == 0.0 || number == 0.0 ) { fuzzTemp = new FuzzyNumber( num.Number, num.Minimum, num.Maximum ); fuzzTemp.SetMembership(); return fuzzTemp; } fuzzTemp = new FuzzyNumber( num.Number / number, num.Minimum, num.Maximum ); fuzzTemp.SetMembership(); return fuzzTemp; } public static FuzzyNumber operator /( FuzzyNumber num, FuzzyNumber number ) { FuzzyNumber fuzzTemp; if( num.Number == 0.0 || number.Number == 0.0 ) { fuzzTemp = new FuzzyNumber( num.Number, num.Minimum, num.Maximum ); fuzzTemp.SetMembership(); return fuzzTemp; } fuzzTemp = new FuzzyNumber( num.Number / number.Number, num.Minimum, num.Maximum ); fuzzTemp.SetMembership(); return fuzzTemp; } public static FuzzyNumber operator %( FuzzyNumber num, double number ) { FuzzyNumber fuzzTemp; if( num.Number == 0.0 || number == 0.0 ) { fuzzTemp = new FuzzyNumber( num.Number, num.Minimum, num.Maximum ); fuzzTemp.SetMembership(); return fuzzTemp; } fuzzTemp = new FuzzyNumber( num.Number % number, num.Minimum, num.Maximum ); fuzzTemp.SetMembership(); return fuzzTemp; } public static FuzzyNumber operator %( FuzzyNumber num, FuzzyNumber number ) { FuzzyNumber fuzzTemp; if( num.Number == 0.0 || number.Number == 0.0 ) { fuzzTemp = new FuzzyNumber( num.Number, num.Minimum, num.Maximum ); fuzzTemp.SetMembership(); return fuzzTemp; } fuzzTemp = new FuzzyNumber( num.Number % number.Number, num.Minimum, num.Maximum ); fuzzTemp.SetMembership(); return fuzzTemp; } } /// /// The fuzzy set class for holding and manipulating fuzzy numbers /// public class FuzzyNumberSet : FuzzySet { private double setValue; public double FuzzySetValue { get { return setValue; } set { setValue = value; UpdateSetValue(); } } /// /// basic constructor /// public FuzzyNumberSet() : base() { } /// /// conbstructor that creates a number of empty fuzzy numbers /// /// public FuzzyNumberSet( int nNumberCount ) : base() { for( int i=0; i /// constructor that takes the first fuzzy number /// /// public FuzzyNumberSet( FuzzyNumber fuzzyNum ) : base() { FuzzyArray.Add( fuzzyNum ); } /// /// constructor that takes the values for the first fuzzy number /// /// /// /// public FuzzyNumberSet( double number, double minimum, double maximum ) : base() { FuzzyNumber temp = new FuzzyNumber( number, minimum, maximum ); FuzzyArray.Add( temp ); } /// /// get the name of the current value of the set /// /// public override string GetTerm() { for( int i=0; i /// Is the current value within the specified term ( name of the fuzzy number ) /// /// /// name of the fuzzy number that the value is supposed to be within /// true or false public override bool IsTerm( string strTerm ) { for( int i=0; i= this.setValue && temp.Minimum <= this.setValue ) { return true; } else return false; } } return false; } /// /// gets the default membership value for the term ie when membership == 1 /// therefore gets the middle value /// /// /// public override double ValueFromTerm( string strTerm ) { for( int i=0; i /// Set the value for the Set to the Name of a passed in fuzzy number /// /// public override void SetToTerm( string strTerm ) { this.FuzzySetValue = ValueFromTerm( strTerm ); } /// /// update the individual fuzzy numbers when the set value changes /// private void UpdateSetValue() { for( int i=0; i= ( ( FuzzyNumber )FuzzyArray[ i ] ).Minimum ) { ( ( FuzzyNumber )FuzzyArray[ i ] ).Number = this.FuzzySetValue; } else ( ( FuzzyNumber )FuzzyArray[ i ] ).Number = 0.0; } } /// Set operations /// Set Operations need to go here as you can't create a base class set ( FuzzySet ) and /// then down cast it in CSharp /// ( Still thinking in C++ ) /// /// return a union of the two passed sets /// /// /// /// public FuzzyNumberSet Union( FuzzyNumberSet fuzzySet ) { FuzzyNumberSet returnSet = new FuzzyNumberSet(); bool bFound = false; for( int i=0; i /// Union override that allows the setting of the membership parameters /// /// /// /// /// public FuzzyNumberSet Union( FuzzyNumberSet fuzzySet, FuzzySetParameters setParams ) { FuzzyNumberSet returnSet = new FuzzyNumberSet(); double dSetOneMinMinimum; double dSetOneMaxMinimum; double dSetOneMinMembership; double dSetOneMaxMembership; double dSetOneMinMaximum; double dSetOneMaxMaximum; double dSetOneMinNumber; double dSetOneMaxNumber; double dSetTwoMinMinimum; double dSetTwoMaxMinimum; double dSetTwoMinMembership; double dSetTwoMaxMembership; double dSetTwoMinMaximum; double dSetTwoMaxMaximum; double dSetTwoMinNumber; double dSetTwoMaxNumber; /// get all the items from set one that fit the required ( passed in ) parameters. for( int i=0; i= dSetOneMinMembership && ( ( FuzzyNumber )this.FuzzyArray[ i ] ).Maximum >= dSetOneMinMaximum && ( ( FuzzyNumber )this.FuzzyArray[ i ] ).Minimum >= dSetOneMinMinimum && ( ( FuzzyNumber )this.FuzzyArray[ i ] ).Number >= dSetOneMinNumber ) { returnSet[ returnSet.Count + 1 ] = new FuzzyNumber( ( FuzzyNumber )this.FuzzyArray[ i ] ); } } /// Get the ones in set two, not in set one ( though none should be when comparing different sets ) for( int i=0; i= dSetOneMinMaximum && ( ( FuzzyNumber )fuzzySet.FuzzyArray[ i ] ).Maximum >= dSetTwoMinMaximum && ( ( FuzzyNumber )this.FuzzyArray[ n ] ).Maximum <= dSetOneMaxMaximum && ( ( FuzzyNumber )fuzzySet.FuzzyArray[ i ] ).Maximum <= dSetTwoMaxMaximum && ( ( FuzzyNumber )this.FuzzyArray[ n ] ).Membership >= dSetOneMinMembership && ( ( FuzzyNumber )fuzzySet.FuzzyArray[ i ] ).Membership >= dSetTwoMinMembership && ( ( FuzzyNumber )this.FuzzyArray[ n ] ).Membership <= dSetOneMaxMembership && ( ( FuzzyNumber )fuzzySet.FuzzyArray[ i ] ).Membership <= dSetTwoMaxMembership && ( ( FuzzyNumber )this.FuzzyArray[ n ] ).Minimum >= dSetOneMinMinimum && ( ( FuzzyNumber )fuzzySet.FuzzyArray[ i ] ).Minimum >= dSetTwoMinMinimum && ( ( FuzzyNumber )this.FuzzyArray[ n ] ).Minimum <= dSetOneMaxMinimum && ( ( FuzzyNumber )fuzzySet.FuzzyArray[ i ] ).Minimum <= dSetTwoMaxMinimum && ( ( FuzzyNumber )this.FuzzyArray[ n ] ).Number >= dSetOneMinNumber && ( ( FuzzyNumber )fuzzySet.FuzzyArray[ i ] ).Number >= dSetTwoMinNumber && ( ( FuzzyNumber )this.FuzzyArray[ n ] ).Number <= dSetOneMaxNumber && ( ( FuzzyNumber )fuzzySet.FuzzyArray[ i ] ).Number <= dSetTwoMaxNumber ) { if( returnSet.IsInSet( ( FuzzyNumber )fuzzySet.FuzzyArray[ i ] ) == false ) { returnSet[ returnSet.Count + 1 ] = new FuzzyNumber( ( FuzzyNumber )fuzzySet.FuzzyArray[ i ] ); } } } } return returnSet; } /// /// return an intersection of the two sets /// /// /// /// public FuzzyNumberSet Intersection( FuzzyNumberSet fuzzySet ) { FuzzyNumberSet returnSet = new FuzzyNumberSet(); for( int i=0; i /// return an intersection of the two sets and allow the passing in of the required membership values /// /// /// /// /// /// /// /// public FuzzyNumberSet Intersection( FuzzyNumberSet fuzzySet, FuzzySetParameters setParams ) { FuzzyNumberSet returnSet = new FuzzyNumberSet(); double dSetOneMinMinimum; double dSetOneMaxMinimum; double dSetOneMinMembership; double dSetOneMaxMembership; double dSetOneMinMaximum; double dSetOneMaxMaximum; double dSetOneMinNumber; double dSetOneMaxNumber; double dSetTwoMinMinimum; double dSetTwoMaxMinimum; double dSetTwoMinMembership; double dSetTwoMaxMembership; double dSetTwoMinMaximum; double dSetTwoMaxMaximum; double dSetTwoMinNumber; double dSetTwoMaxNumber; for( int i=0; i= dSetOneMinMaximum && ( ( FuzzyNumber )fuzzySet.FuzzyArray[ n ] ).Maximum >= dSetTwoMinMaximum && ( ( FuzzyNumber )this.FuzzyArray[ i ] ).Maximum <= dSetOneMaxMaximum && ( ( FuzzyNumber )fuzzySet.FuzzyArray[ n ] ).Maximum <= dSetTwoMaxMaximum && ( ( FuzzyNumber )this.FuzzyArray[ i ] ).Membership >= dSetOneMinMembership && ( ( FuzzyNumber )fuzzySet.FuzzyArray[ n ] ).Membership >= dSetTwoMinMembership && ( ( FuzzyNumber )this.FuzzyArray[ i ] ).Membership <= dSetOneMaxMembership && ( ( FuzzyNumber )fuzzySet.FuzzyArray[ n ] ).Membership <= dSetTwoMaxMembership && ( ( FuzzyNumber )this.FuzzyArray[ i ] ).Minimum >= dSetOneMinMinimum && ( ( FuzzyNumber )fuzzySet.FuzzyArray[ n ] ).Minimum >= dSetTwoMinMinimum && ( ( FuzzyNumber )this.FuzzyArray[ i ] ).Minimum <= dSetOneMaxMinimum && ( ( FuzzyNumber )fuzzySet.FuzzyArray[ n ] ).Minimum <= dSetTwoMaxMinimum && ( ( FuzzyNumber )this.FuzzyArray[ i ] ).Number >= dSetOneMinNumber && ( ( FuzzyNumber )fuzzySet.FuzzyArray[ n ] ).Number >= dSetTwoMinNumber && ( ( FuzzyNumber )this.FuzzyArray[ i ] ).Number <= dSetOneMaxNumber && ( ( FuzzyNumber )fuzzySet.FuzzyArray[ n ] ).Number <= dSetTwoMaxNumber ) { if( dSetOneMinMaximum >= dSetTwoMinMaximum && dSetOneMaxMaximum <= dSetTwoMaxMaximum && dSetOneMinMembership >= dSetTwoMinMembership && dSetOneMaxMembership <= dSetTwoMaxMembership && dSetOneMinMinimum >= dSetTwoMinMinimum && dSetOneMaxMinimum <= dSetTwoMaxMinimum && dSetOneMinNumber >= dSetTwoMinNumber && dSetOneMaxNumber <= dSetTwoMaxNumber ) { returnSet[ returnSet.Count + 1 ] = new FuzzyNumber( ( FuzzyNumber )this.FuzzyArray[ i ] ); } } } } return returnSet; } /// /// return an exclusive or set /// /// /// /// public FuzzyNumberSet ExclusiveOR( FuzzyNumberSet fuzzySet ) { FuzzyNumberSet returnSet = new FuzzyNumberSet(); bool bFound = false; /// Get the ones in set one but not in set two for( int i=0; i /// exclusive or taking the fuzzy parameter set. /// /// /// /// /// public FuzzyNumberSet ExclusiveOR( FuzzyNumberSet fuzzySet, FuzzySetParameters setParams ) { FuzzyNumberSet returnSet = new FuzzyNumberSet(); bool bFound = false; double dSetOneMinMinimum; double dSetOneMaxMinimum; double dSetOneMinMembership; double dSetOneMaxMembership; double dSetOneMinMaximum; double dSetOneMaxMaximum; double dSetOneMinNumber; double dSetOneMaxNumber; double dSetTwoMinMinimum; double dSetTwoMaxMinimum; double dSetTwoMinMembership; double dSetTwoMaxMembership; double dSetTwoMinMaximum; double dSetTwoMaxMaximum; double dSetTwoMinNumber; double dSetTwoMaxNumber; /// Get the ones in set one but not in set two for( int i=0; i= dSetTwoMinMaximum && dSetOneMaxMaximum <= dSetTwoMaxMaximum && dSetOneMinMembership >= dSetTwoMinMembership && dSetOneMaxMembership <= dSetTwoMaxMembership && dSetOneMinMinimum >= dSetTwoMinMinimum && dSetOneMaxMinimum <= dSetTwoMaxMinimum && dSetOneMinNumber >= dSetTwoMinNumber && dSetOneMaxNumber <= dSetTwoMaxNumber ) { bFound = true; n=fuzzySet.Count; } } if( bFound == false ) { returnSet[ returnSet.Count + 1 ] = new FuzzyNumber( ( FuzzyNumber )this.FuzzyArray[ i ] ); } } /// get the ones in set two but not in set one for( int i=0; i= dSetTwoMinMaximum && dSetOneMaxMaximum <= dSetTwoMaxMaximum && dSetOneMinMembership >= dSetTwoMinMembership && dSetOneMaxMembership <= dSetTwoMaxMembership && dSetOneMinMinimum >= dSetTwoMinMinimum && dSetOneMaxMinimum <= dSetTwoMaxMinimum && dSetOneMinNumber >= dSetTwoMinNumber && dSetOneMaxNumber <= dSetTwoMaxNumber ) { bFound = true; n=this.Count; } } if( bFound == false ) { returnSet[ returnSet.Count + 1 ] = new FuzzyNumber( ( FuzzyNumber )fuzzySet.FuzzyArray[ i ] ); } } return returnSet; } } } ```

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.

A list of licenses authors might use can be found here