12,246,406 members (37,494 online)

78.7K views
30 bookmarked
Posted

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; using System.Xml.Serialization; using System.Xml; using System.Xml.Schema; using System.Collections; using System.Text; namespace Fuzzy_Logic_Library { /// /// removed the basic stuff to a seperate class to avoid code duplication /// abstract public class FuzzyBasic { /// /// Does Fuzzy Number need an absoluteMaximum and an AbsoluteMinimum value /// that it cannot pass? /// private double dNumber; private double dMaximum; private double dMinimum; /// /// membership value goes between 0 and 2 /// a value less than 1 is in the lower half of the membership and a value /// greater than 1 is in the higher part of the membership /// private double dMembership; /// /// arbritrary members /// private double dID; private string strName; public double Number { get { return dNumber; } set { dNumber = value; SetMembership(); } } public double Maximum { get { return dMaximum; } set { dMaximum = value; } } /// /// is the value a full member of this set note it can be set by the outside /// this is because the code may not always treat the central point between the /// maximum and minimum numbers as the location for full membership /// public double Membership { get { return dMembership; } set { dMembership = value; } } public double Minimum { get { return dMinimum; } set { dMinimum = value; } } public double ID { get { return dID; } set { dID = value; } } public string Name { get { return strName; } set { strName = value; } } public FuzzyBasic() { Minimum = 0; Maximum = 0; Number = 0; dMembership = 0.0; ID = 0; Name = ""; } public FuzzyBasic( FuzzyBasic fuzzy ) { this.ID = fuzzy.ID; this.Maximum = fuzzy.Maximum; this.Membership = fuzzy.Membership; this.Minimum = fuzzy.Minimum; this.Name = fuzzy.Name; this.Number = fuzzy.Number; } /// /// Set the membership value for the number /// Now virtual for overriding with the membership method of choice /// public virtual void SetMembership() { if( Maximum == 0 || Maximum < Minimum ) return; if( Number > Maximum || Number <= Minimum ) { Membership = 0.0; return; } double dMiddle = Minimum + ( ( Maximum - Minimum ) / 2 ); if( Number == dMiddle ) { Membership = 1.0; } else if( Number < dMiddle ) { double dHalfMiddle = dMiddle - ( dMiddle / 2 ); if( Number == dHalfMiddle ) { Membership = 0.50; } else if( Number > dHalfMiddle ) { double dHalfAgain = dHalfMiddle + ( dHalfMiddle / 2 ); if( Number == dHalfAgain ) { Membership = 0.75; } else if( Number > dHalfAgain ) { Membership = 0.87; } else Membership = 0.63; } else { double dHalfAgain = dHalfMiddle - ( dHalfMiddle / 2 ); if( Number == dHalfAgain ) { Membership = 0.25; } else if( Number > dHalfAgain ) { Membership = 0.37; } else Membership = 0.12; } } else { double dHalfMiddle = dMiddle + ( dMiddle / 2 ); if( Number == dHalfMiddle ) { Membership = 1.50; } else if( Number > dHalfMiddle ) { double dHalfAgain = dHalfMiddle + ( ( Maximum - dHalfMiddle ) / 2 ); if( Number == dHalfAgain ) { Membership = 1.75; } else if( Number > dHalfAgain ) { Membership = 1.87; } else Membership = 1.63; } else { double dHalfAgain = dHalfMiddle - ( ( dHalfMiddle - dMiddle ) / 2 ); if( Number == dHalfAgain ) { Membership = 1.25; } else if( Number > dHalfAgain ) { Membership = 1.37; } else Membership = 1.12; } } } /// /// Check if the set values are equal name and id not checked as /// these are arbitrary /// /// /// public bool IsEqual( FuzzyBasic fuzzy ) { if( fuzzy.Maximum == this.Maximum && fuzzy.Membership == this.Membership && fuzzy.Minimum == this.Minimum && fuzzy.Number == this.Number ) { return true; } return false; } } /// /// Fuzzy SetParameters class is an aid class to help in setting up variables /// for set operations between different types of sets /// public class FuzzySetParameters { private double dSetOneMinMinimum; private double dSetOneMaxMinimum; private double dSetOneMinMembership; private double dSetOneMaxMembership; private double dSetOneMinMaximum; private double dSetOneMaxMaximum; private double dSetOneMinNumber; private double dSetOneMaxNumber; private double dSetTwoMinMinimum; private double dSetTwoMaxMinimum; private double dSetTwoMinMembership; private double dSetTwoMaxMembership; private double dSetTwoMinMaximum; private double dSetTwoMaxMaximum; private double dSetTwoMinNumber; private double dSetTwoMaxNumber; public FuzzySetParameters() { dSetOneMinMinimum = 0; dSetOneMaxMinimum = 0; dSetOneMinMembership = 0; dSetOneMaxMembership = 0; dSetOneMinMaximum = 0; dSetOneMaxMaximum = 0; dSetOneMinNumber = 0; dSetOneMaxNumber = 0; dSetTwoMinMinimum = 0; dSetTwoMaxMinimum = 0; dSetTwoMinMembership = 0; dSetTwoMaxMembership = 0; dSetTwoMinMaximum = 0; dSetTwoMaxMaximum = 0; dSetTwoMinNumber = 0; dSetTwoMaxNumber = 0; } public double SetOneMinMinimum { get { return dSetOneMinMinimum; } set { dSetOneMinMinimum = value; } } public double SetOneMaxMinimum { get { return dSetOneMaxMinimum; } set { dSetOneMaxMinimum = value; } } public double SetOneMinMembership { get { return dSetOneMinMembership; } set { dSetOneMinMembership = value; } } public double SetOneMaxMembership { get { return dSetOneMaxMembership; } set { dSetOneMaxMembership = value; } } public double SetOneMinMaximum { get { return dSetOneMinMaximum; } set { dSetOneMinMaximum = value; } } public double SetOneMaxMaximum { get { return dSetOneMaxMaximum; } set { dSetOneMaxMaximum = value; } } public double SetOneMinNumber { get { return dSetOneMinNumber; } set { dSetOneMinNumber = value; } } public double SetOneMaxNumber { get { return dSetOneMaxNumber; } set { dSetOneMaxNumber = value; } } public double SetTwoMinMinimum { get { return dSetTwoMinMinimum; } set { dSetTwoMinMinimum = value; } } public double SetTwoMaxMinimum { get { return dSetTwoMaxMinimum; } set { dSetTwoMaxMinimum = value; } } public double SetTwoMinMembership { get { return dSetTwoMinMembership; } set { dSetTwoMinMembership = value; } } public double SetTwoMaxMembership { get { return dSetTwoMaxMembership; } set { dSetTwoMaxMembership = value; } } public double SetTwoMinMaximum { get { return dSetTwoMinMaximum; } set { dSetTwoMinMaximum = value; } } public double SetTwoMaxMaximum { get { return dSetTwoMaxMaximum; } set { dSetTwoMaxMaximum = value; } } public double SetTwoMinNumber { get { return dSetTwoMinNumber; } set { dSetTwoMinNumber = value; } } public double SetTwoMaxNumber { get { return dSetTwoMaxNumber; } set { dSetTwoMaxNumber = value; } } } /// /// The Fuzzy Set class holds the basic Fuzzy Set stuff /// abstract public class FuzzySet { private ArrayList arrayFuzzy; private string strName; public string Name { get { return strName; } set { strName = value; } } /// /// basic constructor /// public FuzzySet() { arrayFuzzy = new ArrayList(); } /// /// allow direct access to the ArrayList /// public ArrayList FuzzyArray { get { return arrayFuzzy; } } public int Count { get { return arrayFuzzy.Count; } } /// /// is there a fuzzy number that has the membership value of 1 /// /// public bool IsCompleteMembership() { for( int i=0; i /// get the value that has complete membership /// /// public FuzzyBasic GetCompleteMembership() { for( int i=0; i /// Get the value of the best member in the fuzzy set /// Note returns lowest value ie less than one /// /// public FuzzyBasic GetBestMembershipValue() { int nBestMember = 0; double dBestValue = 0.0; double dTempValue = 0.0; for( int i=0; i dBestValue && dTempValue < 1.0 ) { dBestValue = dTempValue; nBestMember = i; } } return ( FuzzyBasic )arrayFuzzy[ nBestMember ]; } /// /// returns the best membership value greater than 1 /// /// public FuzzyBasic GetHighestBestMembershipValue() { int nBestMember = 0; double dBestValue = 0.0; double dTempValue = 0.0; for( int i=0; i 1.0 ) { dBestValue = dTempValue; nBestMember = i; } } return ( FuzzyBasic )arrayFuzzy[ nBestMember ]; } #region /* OVERRIDE THESE IN CHILD CLASSES IF NEEDED */ /// The folowing functions are fairly essential ( so far ) /// but require specific class function knowledge for implementation. /// /// gets the default membership value for the term ie when membership == 1 /// therefore gets the middle value /// /// /// public virtual double ValueFromTerm( string strTerm ) { return 0.0; } /// /// get the name of the current value of the set /// /// public virtual string GetTerm() { return null; } /// /// Is the current value within the specified term ( name of the fuzzy item ) /// /// /// name of the fuzzy item that the value is supposed to be within /// true or false public virtual bool IsTerm( string strTerm ) { return false; } /// /// Set the value for the Set to the Name of a passed in fuzzy number /// /// public virtual void SetToTerm( string strTerm ) { } #endregion /// /// use an indexer for the class /// public FuzzyBasic this[ int index ] { get { if( index <= arrayFuzzy.Count ) return ( FuzzyBasic )arrayFuzzy[ index ]; else return null; } set { if( index < arrayFuzzy.Count ) { arrayFuzzy.RemoveAt( index ); arrayFuzzy.Insert( index, value ); } else arrayFuzzy.Add( value ); } } /// get a string for logging and printing the contents of the current fuzzy set public string FuzzyPrintOut { get { StringBuilder strTemp = new StringBuilder(); strTemp.Append( "\nContents Of Fuzzy Set " ); if( this.Name != "" ) strTemp.Append( "Name = " + this.Name + "\n" ); else strTemp.Append( "\n" ); for( int i=0; i

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