12,699,308 members (32,302 online)

80.3K views
32 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.Text; using System.Collections; namespace Fuzzy_Logic_Library { /// /// Summary description for FuzzyWord. /// public class FuzzyWord : FuzzyBasic { private string strWord; private double dMinMaxDifference; private double dComparedMembership; private char[] punctuationArray; private int nMinimumLetters; private int nValueDifference; private bool bAcceptPlurals; private int nMaximumIncorrectLetters; private bool bLowerCase; public string Word { get { return strWord; } set { strWord = value; /// get the value for the word double dValue = 0; for( int i=0; i /// compare two fuzzy words /// /// /// public FuzzyWord Compare( string comparison ) { if( comparison == "" || comparison == null ) { return null; } /// check the passed in string for any punctuation marks if they exist /// remove them if( comparison.IndexOfAny( punctuationArray ) != -1 ) { /// special case Origin of the species has the punctuation " ,- " which gives a bad value if( comparison.LastIndexOf( '-' ) != -1 ) comparison = comparison.Remove( comparison.Length -1, 1 ); comparison = comparison.Remove( comparison.Length -1, 1 ); if( comparison == "" || comparison == null ) return null; } /// check if not case sensitive if( LowerCase == true ) { comparison = comparison.ToLower(); } /// check if plurals are accepted. if( AcceptPlurals == true ) { /// treat plurals as acceptable if( comparison[ comparison.Length -1 ] == 's' || comparison[ comparison.Length - 1 ] == 'S' ) { string strTest = comparison.Remove( comparison.Length -1, 1 ); if( strTest == "" || strTest == null ) return null; /// check for apostrophy s if( strTest[ strTest.Length -1 ] == '\'' ) { strTest = strTest.Remove( strTest.Length -1, 1 ); } if( strTest == Word ) { FuzzyWord temp = new FuzzyWord( comparison ); temp.ComparedMembership = 1.0; return temp; } } } if( comparison == Word ) { FuzzyWord temp = new FuzzyWord( comparison ); temp.ComparedMembership = 1.0; return temp; } /// get the value for the comparison double dValue = 0; for( int i=0; i= this.MinimumMatchingLetters ) { if( comparison.Length > Word.Length && nCount + this.MaximumIncorrectLetters >= comparison.Length ) { FuzzyWord temp = new FuzzyWord( comparison ); /// set the membership value if( dValue >= this.Number - nValueDifference && dValue <= this.Number + nValueDifference ) temp.ComparedMembership = 1.12; else if( dValue >= this.Number - ( nValueDifference * 2 ) && dValue <= this.Number + ( nValueDifference * 2 ) ) temp.ComparedMembership = 1.25; else if( dValue >= this.Number - ( nValueDifference * 3 ) && dValue <= this.Number + ( nValueDifference * 3 ) ) temp.ComparedMembership = 1.37; else if( dValue >= this.Number - ( nValueDifference * 4 ) && dValue <= this.Number + ( nValueDifference * 4 ) ) temp.ComparedMembership = 1.50; else if( dValue >= this.Number - ( nValueDifference * 5 ) && dValue <= this.Number + ( nValueDifference * 5 ) ) temp.ComparedMembership = 1.63; else if( dValue >= this.Number - ( nValueDifference * 6 ) && dValue <= this.Number + ( nValueDifference * 6 ) ) temp.ComparedMembership = 1.75; else temp.ComparedMembership = 1.87; return temp; } if( comparison.Length <= Word.Length && Word.Length - this.MaximumIncorrectLetters > 0 ) { FuzzyWord temp = new FuzzyWord( comparison ); /// set the membership value if( dValue >= this.Number - nValueDifference && dValue <= this.Number + nValueDifference ) temp.ComparedMembership = 0.87; else if( dValue >= this.Number - ( nValueDifference * 2 ) && dValue <= this.Number + ( nValueDifference * 2 ) ) temp.ComparedMembership = 0.75; else if( dValue >= this.Number - ( nValueDifference * 3 ) && dValue <= this.Number + ( nValueDifference * 3 ) ) temp.ComparedMembership = 0.63; else if( dValue >= this.Number - ( nValueDifference * 4 ) && dValue <= this.Number + ( nValueDifference * 4 ) ) temp.ComparedMembership = 0.50; else if( dValue >= this.Number - ( nValueDifference * 5 ) && dValue <= this.Number + ( nValueDifference * 5 ) ) temp.ComparedMembership = 0.37; else if( dValue >= this.Number - ( nValueDifference * 6 ) && dValue <= this.Number + ( nValueDifference * 6 ) ) temp.ComparedMembership = 0.25; else temp.ComparedMembership = 0.12; return temp; } } return null; } } /// /// Class for holding complete sentences /// public class FuzzySentence : FuzzyBasic { private ArrayList arraySentence; private char finalPunctuation; public string Sentence { get { StringBuilder strTemp = new StringBuilder(); for( int i=0; i /// Basic Constructor /// public FuzzySentence() : base() { arraySentence = new ArrayList(); } /// /// Constructor that takes the string for the sentence /// /// public FuzzySentence( string strSentence ) : base() { arraySentence = new ArrayList(); AddSentence( strSentence ); } /// /// add a single word to the sentence /// /// public void AddWord( FuzzyWord fuzzyWord ) { arraySentence.Add( fuzzyWord ); } /// /// add a single word to the sentence /// /// public void AddWord( string strWord ) { arraySentence.Add( strWord ); } /// /// Add the sentence /// /// public void AddSentence( string strSentence ) { /// clear out any current sentence arraySentence.Clear(); int nCount = 0; /// extract the words for( int i=0; i /// A paragraph is a collection of sentences /// public class FuzzyParagraph : FuzzyBasic { ArrayList arrayParagraph; public string Paragraph { get { StringBuilder strTemp = new StringBuilder(); for( int i=0; i /// basic constructor /// public FuzzyParagraph() : base() { arrayParagraph = new ArrayList(); } /// /// constructor taking the paragraph as a string /// /// public FuzzyParagraph( string strParagraph ) : base() { arrayParagraph = new ArrayList(); AddParagraph( strParagraph ); } /// /// build the paragraph string by string /// /// public void AddSentence( FuzzySentence fuzzySentence ) { arrayParagraph.Add( fuzzySentence ); } /// /// add a whole paragraph /// /// public void AddParagraph( string strParagraph ) { arrayParagraph.Clear(); StringBuilder strString = new StringBuilder(); for( int i=0; i /// A set to hold a collection of fuzzy paragraphs /// Not sure if this should inherit from fuzzy set at the moment see how things work out /// public class FuzzyParagraphSet : FuzzySet { public FuzzyParagraphSet() : base() { } public FuzzyParagraphSet( string strName ) : base() { this.Name = strName; } } } ```

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