FuzzyLogicinCCreatingafuzzy-basedinferenceengineGregViot,Dr.Dobb'sJournal,February1993GregisamemberoftheMotorolatechnicalladderandiscurrentlymergingfuzzylogicwithmicrocontrollers.HehasanMSEEfromNationalTechnologicalUniversityandaBSEEfromtheUniversityofTexasatAustin.GregcanbecontactedatMotorolaAdvancedMicrocontrollerDivision,6501WilliamCannonDriveWest,Austin,Texas78735-8598.Fuzzylogicisapowerful,yetstraightforward,problem-solvingtechniquewithwidespreadapplicability,especiallyintheareasofcontrolanddecisionmaking.Ingeneral,itismostusefulinhandlingproblemsnoteasilydefinablebypracticalmathematicalmodels.Forinstance,fuzzylogichasbeenemployedinsuchtasksasmanagingstock-marketportfoliosandcontrollingsubwaysystems.Fuzzyderivesmuchofitspowerfromitsabilitytodrawconclusionsandgenerateresponsesbasedonvague,ambiguous,qualitative,incomplete,orimpreciseinformation.Inthisrespect,fuzzy-basedsystemshaveareasoningabilitysimilartothatofhumans.Infact,thebehaviorofafuzzysystemisrepresentedinaverysimpleandnaturalway.Thisallowsquickconstructionofunderstandable,maintainable,androbustsystems.Inaddition,afuzzyapproachgenerallyrequiresmuchlessmemoryandcomputingpowerthanconventionalmethods,therebypermittingsmallerandlessexpensivesystems.LotfiZadeh,aprofessorattheUniversityofCaliforniaatBerkeley,isthepersonmostwidelyassociatedwithfuzzylogic.In1965hepresentedtheoriginalpaperformallydefiningfuzzy-settheory,fromwhichfuzzylogicemerged.Zadehextendedtraditionaltheorytoresolvetheparadoxessometimesgeneratedfromthenothing-or-allclassificationsofAristotelianlogic.Traditionally,alogicpremisehastwoextremes:eithercompletelytrueorcompletelyfalse.However,inthefuzzyworld,apremiserangesindegreeoftruthfrom0to100percent,whichallowsittobepartiallytrueandpartiallyfalse.Byincorporatingthisdegreeoftruthconcept,fuzzylogicextendstraditionallogicintwoways.First,setsarelabeledqualitatively(usinglinguistictermssuchastall,warm,active,nearby,andsoon),andtheelementsofthesesetsareassignedvaryingdegreesofmembership.Forinstance,a5'11mananda6'4manmaybothbemembersofasetoftallmen,althoughthe6'4manhasahigherdegreeofmembership.Secondly,anyactionoroutputresultingfromapremisebeingtrueexecutestoastrengthreflectingthedegreetowhichthatpremiseistrue.Asanexample,imagineafanmotor,thespeedofwhichisafunctionoftemperature,asshowninTable1.Thecurrentsuppliedtothefanmotorisregulatedbysetsoftemperature:cold,cool,warm,andhot.Inthissystem,asthetemperaturegraduallymovesfromwarmtocool,thecurrentgraduallymovesfrom50to15.Bycontinuouslytrackinginputs,outputscanavoidabruptchanges,evenasinputstranscendsetboundaries.Fuzzy-basedsystemsareconstructedsothatgeneratedoutputschangeinasmoothandcontinuousmanner,regardlessofinputscrossingsetboundaries.Table1:Fan-speedcontrol.TemperatureFanSpeedRelativeMotorCurrent------------------------------------------ColdOff0CoolSlow15WarmMedium50HotFast100OrganizationofaFuzzySystemFigure1illustratestheflowofdatathroughafuzzysystem.Systeminputsundergothreetransformationstobecomesystemoutputs.First,afuzzificationprocessthatusespredefinedmembershipfunctionsmapseachsysteminputintooneormoredegreesofmembership.Then,therulesintherulebase(alsopredefined)areevaluatedbycombiningdegreesofmembershiptoformoutputstrengths.Andlastly,thedefuzzificationprocesscomputessystemoutputsbasedonstrengthsandmembershipfunctions.FuzzificationofInputsFuzzificationistheprocessofassigningorcalculatingavaluetorepresentaninput'sdegreeofmembershipinoneormorequalitativegroupings,calledfuzzysets.Figure2showsasysteminput,temperature,withfuzzysetscold,cool,warm,andhot.Eachtemperaturevaluehasadegreeofmembershipineachofthesesets.Thedegreeofmembershipisdeterminedbyamembershipfunction,whichisdefinedbasedonexperienceorintuition.Figure9illustratesthedegreeofmembershipcalculationforatrapezoidalmembershipfunction.Itisacceptedthatmembershipfunctionschangeseveraltimesasthesystemistunedtoachievedesiredresponsestogiveninputs.Generally,oncethesystemisinoperation,themembershipfunctionsdonotchange.Simpleshapessuchastrapezoidsandtrianglesareoftenusedtodefinemembershipinfuzzysets,butanysuitablefunctioncanbeused.Inaddition,youmustdecideuponthenumberoffuzzysetspersysteminput.InFigure2,afuzzysetlabeledcomfortablecouldbeinsertedbetweencoolandwarm.Thenumberoffuzzy-setmembershipfunctionsandtheshapesyouchoosedependonsuchthingsasrequiredaccuracy,responsivenessandstabilityofthesystem,easeofimplementation,manipulation,andmaintenance,andsoon.Thetrapezoidalandtriangularmembershipfunctionsaremostcommonandhaveproventobegoodcompromisesbetweeneffectivenessandefficiency.ThefuzzysetsmustspantheX-axiscoveringtheentirerange,oruniverseofdiscourse,forasysteminput.MappingtotheY-axisrangesfrom0to1andrepresentsthedegreetowhichaninputvalueisamemberofthatparticularfuzzyset.Overlappingbetweensetboundariesisdesirableandkeytothesmoothoperationofthesystem.Itpermitsmembershipinmultiple--evenseeminglycontradictory--sets.InFigure2,63degreescanbebothcoolandwarm,butitiscooltoagreaterdegree.Anoverlapof25percentbetweenadjacentfuzzysetsisageneralruleofthumb.Thefuz