def _in_mf_def(mfname, mfdef): ''' Return a FuzzyTermType for this MF definition. ''' cname = mfdef.__class__.__name__ mftype = None if cname == 'GaussMembFunc': mftype = FuzzyTermType.TYPE_gaussianShape param = [mfdef.mu, mfdef.sigma] elif cname == 'BellMembFunc': param = [mfdef.a, mfdef.b, mfdef.c] pass elif cname == 'TriangularMembFunc': param = [mfdef.a, mfdef.b, mfdef.c] mftype = FuzzyTermType.TYPE_triangularShape elif cname == 'TrapezoidalMembFunc': param = [mfdef.a, mfdef.b, mfdef.c, mfdef.d] mftype = FuzzyTermType.TYPE_trapezoidShape assert mftype, 'JFML does not implement term type {}'.format(cname) param = [p.item() for p in param] # Values, not torch Parameters return FuzzyTermType(name=mfname, type_java=mftype, param=param)
from py4jfml.rulebase.MamdaniRuleBaseType import MamdaniRuleBaseType from py4jfml.term.FuzzyTerm import FuzzyTerm from py4jfml.term.FuzzyTermType import FuzzyTermType # FuzzyInference iris = FuzzyInferenceSystem("iris - MAMDANI") # KnowledgeBase kb = KnowledgeBaseType() iris.setKnowledgeBase(kb) # FUZZY VARIABLE SepalLength sl = FuzzyVariableType("SepalLength", 4.3, 7.9) # FUZZY TERM low sl_low = FuzzyTermType("low", FuzzyTerm.TYPE_trapezoidShape, [4.3, 4.3, 5.019, 6.048]) sl.addFuzzyTerm(sl_low) # FUZZY TERM medium sl_medium = FuzzyTermType("medium", FuzzyTerm.TYPE_triangularShape, [5.019, 6.048, 7.05]) sl.addFuzzyTerm(sl_medium) # FUZZY TERM high sl_high = FuzzyTermType("high", FuzzyTerm.TYPE_trapezoidShape, [6.048, 7.05, 7.9, 7.9]) sl.addFuzzyTerm(sl_high) # FUZZY TERM NOT(low) sl_not_low = FuzzyTermType("NOT(low)", FuzzyTerm.TYPE_trapezoidShape, [4.3, 4.3, 5.019, 6.048]) sl_not_low.setComplement("true") sl.addFuzzyTerm(sl_not_low)
from py4jfml.rulebase.TsukamotoRuleBaseType import TsukamotoRuleBaseType from py4jfml.term.FuzzyTermType import FuzzyTermType from py4jfml.term.TsukamotoTermType import TsukamotoTermType tipper = FuzzyInferenceSystem("tipper - TSUKAMOTO") #KNOWLEDGE BASE kb = KnowledgeBaseType() tipper.setKnowledgeBase(kb) #FUZZY VARIABLE food food = FuzzyVariableType(name="food", domainLeft=0.0, domainRight=10.0) #FUZZY TERM rancid rancid = FuzzyTermType(name="rancid", type_java=FuzzyTermType.TYPE_triangularShape, param=[0.0, 2.0, 5.5]) food.addFuzzyTerm(rancid) #FUZZY TERM delicious delicious = FuzzyTermType(name="delicious", type_java=FuzzyTermType.TYPE_rightLinearShape, param=[5.5, 10.0]) food.addFuzzyTerm(delicious) kb.addVariable(food) #FUZZY VARIABLE service service = FuzzyVariableType(name="service", domainLeft=0.0, domainRight=10.0) #FUZZY TERM poor
from py4jfml.rule.FuzzyRuleType import FuzzyRuleType from py4jfml.rulebase.MamdaniRuleBaseType import MamdaniRuleBaseType from py4jfml.term.FuzzyTermType import FuzzyTermType japaneseDietAssessment = FuzzyInferenceSystem( "japaneseDietAssessment - MAMDANI") # KNOWLEDGE BASE kb = KnowledgeBaseType() japaneseDietAssessment.setKnowledgeBase(kb) # FUZZY VARIABLE PCC(Percentage of Calories from Carbohydrate) pcc = FuzzyVariableType("PCC", 0., 100.) # FUZZY TERM low pcc_low = FuzzyTermType("low", FuzzyTermType.TYPE_trapezoidShape, [0., 0., 55., 60.]) pcc.addFuzzyTerm(pcc_low) # FUZZY TERM medium pcc_medium = FuzzyTermType("medium", FuzzyTermType.TYPE_trapezoidShape, [55., 60., 65., 70.]) pcc.addFuzzyTerm(pcc_medium) # FUZZY TERM high pcc_high = FuzzyTermType("high", FuzzyTermType.TYPE_trapezoidShape, [65., 70., 100., 100.]) pcc.addFuzzyTerm(pcc_high) kb.addVariable(pcc) # FUZZY VARIABLE PCP(Percentage of Calories from Protein)
from py4jfml.rule.FuzzyRuleType import FuzzyRuleType from py4jfml.rulebase.TsukamotoRuleBaseType import TsukamotoRuleBaseType from py4jfml.term.FuzzyTermType import FuzzyTermType from py4jfml.term.TsukamotoTermType import TsukamotoTermType tipper = FuzzyInferenceSystem("tipper - TSUKAMOTO") # KNOWLEDGE BASE kb = KnowledgeBaseType() tipper.setKnowledgeBase(kb) # FUZZY VARIABLE food food = FuzzyVariableType("food", 0., 10.) # FUZZY TERM rancid rancid = FuzzyTermType("rancid", FuzzyTermType.TYPE_triangularShape, [0., 2., 5.5]) food.addFuzzyTerm(rancid) # FUZZY TERM delicious delicious = FuzzyTermType("delicious", FuzzyTermType.TYPE_rightLinearShape, [5.5, 10.]) food.addFuzzyTerm(delicious) kb.addVariable(food) # FUZZY VARIABLE service service = FuzzyVariableType("service", 0., 10.) # FUZZY TERM poor poor = FuzzyTermType("poor", FuzzyTermType.TYPE_leftGaussianShape, [0., 2.]) service.addFuzzyTerm(poor)
from py4jfml.rule.ConsequentType import ConsequentType from py4jfml.rule.FuzzyRuleType import FuzzyRuleType from py4jfml.rulebase.MamdaniRuleBaseType import MamdaniRuleBaseType from py4jfml.term.FuzzyTermType import FuzzyTermType invertedPendulum = FuzzyInferenceSystem(name="invertedPendulum - MAMDANI") #KNOWLEDGE BASE kb = KnowledgeBaseType() invertedPendulum.setKnowledgeBase(value=kb) #FUZZY VARIABLE Angle ang = FuzzyVariableType(name="Angle", domainLeft=0.0, domainRight=255.0) #FUZZY TERM VNEG ang_vneg = FuzzyTermType(name="very negative", type_java=FuzzyTermType.TYPE_trapezoidShape, param=[0.0, 0.0, 48.0, 88.0]) ang.addFuzzyTerm(ft=ang_vneg) #FUZZY TERM NEG ang_neg = FuzzyTermType(name="negative", type_java=FuzzyTermType.TYPE_triangularShape, param=[48.0, 88.0, 128.0]) ang.addFuzzyTerm(ft=ang_neg) #FUZZY TERM NEU ang_neu = FuzzyTermType(name="zero", type_java=FuzzyTermType.TYPE_triangularShape, param=[88.0, 128.0, 168.0]) ang.addFuzzyTerm(ft=ang_neu) #FUZZY TERM POS ang_pos = FuzzyTermType(name="positive", type_java=FuzzyTermType.TYPE_triangularShape, param=[128.0, 168.0, 208.0]) ang.addFuzzyTerm(ft=ang_pos) #FUZZY TERM VPOS
from py4jfml.rule.ConsequentType import ConsequentType from py4jfml.rule.FuzzyRuleType import FuzzyRuleType from py4jfml.rulebase.MamdaniRuleBaseType import MamdaniRuleBaseType from py4jfml.term.FuzzyTermType import FuzzyTermType invertedPendulum = FuzzyInferenceSystem("invertedPendulum - MAMDANI") # KNOWLEDGE BASE kb = KnowledgeBaseType() invertedPendulum.setKnowledgeBase(kb) # FUZZY VARIABLE ang = FuzzyVariableType("Angle", 0.0, 255.0) # FUZZY TERM VNEG ang_vneg = FuzzyTermType("very negative", FuzzyTermType.TYPE_trapezoidShape, [0.0, 0.0, 48.0, 88.0]) ang.addFuzzyTerm(ang_vneg) #FUZZY TERM NEG ang_neg = FuzzyTermType("negative", FuzzyTermType.TYPE_triangularShape,[48.0, 88.0, 128.0]) ang.addFuzzyTerm(ang_neg) # FUZZY TERM NEU ang_neu = FuzzyTermType("zero", FuzzyTermType.TYPE_triangularShape,[88.0, 128.0, 168.0]) ang.addFuzzyTerm(ang_neu) #FUZZY TERM POS ang_pos = FuzzyTermType("positive", FuzzyTermType.TYPE_triangularShape,[128.0, 168.0, 208.0]) ang.addFuzzyTerm(ang_pos) # FUZZY TERM VPOS
from py4jfml.rule.FuzzyRuleType import FuzzyRuleType from py4jfml.rulebase.MamdaniRuleBaseType import MamdaniRuleBaseType from py4jfml.term.AggregatedFuzzyTermType import AggregatedFuzzyTermType from py4jfml.term.FuzzyTermType import FuzzyTermType tipper = FuzzyInferenceSystem("tipper - MAMDANI") # KNOWLEDGE BASE kb = KnowledgeBaseType() tipper.setKnowledgeBase(kb) # FUZZY VARIABLE food food = FuzzyVariableType("food", 0., 10.) # FUZZY TERM rancid rancid = FuzzyTermType("rancid", FuzzyTermType.TYPE_triangularShape, [0., 2., 5.5]) food.addFuzzyTerm(rancid) # FUZZY TERM delicious delicious = FuzzyTermType("delicious", FuzzyTermType.TYPE_rightLinearShape, [5.5, 10.]) food.addFuzzyTerm(delicious) kb.addVariable(food) # FUZZY VARIABLE service service = FuzzyVariableType("service", 0., 10.) # FUZZY TERM poor poor = FuzzyTermType("poor", FuzzyTermType.TYPE_leftGaussianShape, [0., 2.]) service.addFuzzyTerm(poor)
from py4jfml.term.FuzzyTermType import FuzzyTermType #A FUZZY VARIABLE from py4jfml.term.TskTerm import TskTerm from py4jfml.term.TskTermType import TskTermType from py4jfml.term.TsukamotoTermType import TsukamotoTermType domainLeft = 0.0 domainRight = 255. force = FuzzyVariableType("Force", domainLeft, domainRight) force.setDefaultValue(0.0) force.setAccumulation("MAX") force.setType("output") # FUZZY TERM VNEG termName = "very negative" force_vneg = FuzzyTermType(termName, FuzzyTermType.TYPE_trapezoidShape, [0.0, 0.0, 48.0, 88.0]) # FUZZY TERM NEG force_neg = FuzzyTermType("negative", FuzzyTermType.TYPE_triangularShape, [48.0, 88.0, 128.0]) # FUZZY TERM NEU force_neu = FuzzyTermType("zero", FuzzyTermType.TYPE_triangularShape, [88.0, 128.0, 168.0]) defuzzCoA = DefuzzifierCenterOfArea(2., 4., [force_vneg]) defuzzCoA.setValue(5., 15.) nameCoa = "CenterOfArea" if defuzzCoA.getName() == nameCoa: print("DefuzzifierCenterOfArea test case 1 (name) passed.") else: print("DefuzzifierCenterOfArea test case 1 (name) failed.") if defuzzCoA.getValueY(5.) == 15.:
from py4jfml.parameter.TwoParamType import TwoParamType from py4jfml.rule.ClauseType import ClauseType from py4jfml.term.AggregatedFuzzyTermType import AggregatedFuzzyTermType from py4jfml.term.CircularTermType import CircularTermType from py4jfml.term.FuzzyTermType import FuzzyTermType # methods test of package aggregated # FUZZY VARIABLE food from py4jfml.term.TskTerm import TskTerm from py4jfml.term.TskTermType import TskTermType from py4jfml.term.TsukamotoTermType import TsukamotoTermType food = FuzzyVariableType("food", 0., 10.) # FUZZY TERM rancid rancid = FuzzyTermType("rancid", FuzzyTermType.TYPE_triangularShape, [0., 2., 5.5]) food.addFuzzyTerm(rancid) # FUZZY TERM delicious delicious = FuzzyTermType("delicious", FuzzyTermType.TYPE_rightLinearShape, [5.5, 10.]) food.addFuzzyTerm(delicious) # FUZZY VARIABLE service service = FuzzyVariableType("service", 0., 10.) # FUZZY TERM poor poor = FuzzyTermType("poor", FuzzyTermType.TYPE_leftGaussianShape, [0., 2.]) service.addFuzzyTerm(poor) # FUZZY TERM good
#CLOUD service datumQuality = [8.0,7.7,10.0,8.6] cloudQuality = AnYaDataCloudType(name="quality", terms=datumQuality) kb.addVariable(var=cloudQuality) #FUZZY VARIABLE tip tip = FuzzyVariableType(name="tip", domainLeft=0.0, domainRight=20.0) tip.setDefaultValue(0.0) tip.setAccumulation("MAX") tip.setDefuzzifierName("COG") tip.setType("output") #FUZZY TERM cheap cheap = FuzzyTermType(name="cheap", type_java=FuzzyTermType.TYPE_triangularShape, param=[0.0, 5.0, 10.0]) tip.addFuzzyTerm(cheap) #FUZZY TERM average average = FuzzyTermType(name="average", type_java=FuzzyTermType.TYPE_triangularShape, param=[5.0, 10.0, 15.0]) tip.addFuzzyTerm(average) #FUZZY TERM generous generous = FuzzyTermType(name="generous", type_java=FuzzyTermType.TYPE_triangularShape, param=[10.0, 15.0, 20.0]) tip.addFuzzyTerm(generous) kb.addVariable(tip) #RULE BASE rb = AnYaRuleBaseType("rulebase1")
from py4jfml.term.FuzzyTermType import FuzzyTermType gateway = JavaGateway() iris = FuzzyInferenceSystem("iris - MAMDANI") #KNOWLEDGEBASE kb = KnowledgeBaseType() iris.setKnowledgeBase(kb) #FUZZY VARIABLE PetalWidth pw = FuzzyVariableType(name="PetalWidth", domainLeft=0.1, domainRight=2.5) #FUZZY TERM low pw_lowLIN = FuzzyTermType(name="lowLIN", type_java=FuzzyTerm.TYPE_leftLinearShape, param=[0., 0.8]) pw.addFuzzyTerm(pw_lowLIN) #lowGAU pw_lowGAU = FuzzyTermType(name="lowGAU", type_java=FuzzyTerm.TYPE_leftGaussianShape, param=[0.5, 0.2]) pw.addFuzzyTerm(pw_lowGAU) #lowPI pw_lowPi = FuzzyTermType(name="lowPi", type_java=FuzzyTerm.TYPE_piShape, param=[1., 1.2]) pw.addFuzzyTerm(pw_lowPi) #lowZ pw_lowZ = FuzzyTermType(name="lowZ",
from py4jfml.rule.FuzzyRuleType import FuzzyRuleType from py4jfml.rulebase.MamdaniRuleBaseType import MamdaniRuleBaseType from py4jfml.term.FuzzyTermType import FuzzyTermType iris = FuzzyInferenceSystem("iris - MAMDANI") #KNOWLEDGE BASE kb = KnowledgeBaseType() iris.setKnowledgeBase(kb) #FUZZY VARIABLE PetalWidth pw = FuzzyVariableType(name="PetalWidth", domainLeft=0.1, domainRight=2.5) #FUZZY TERM low pw_low = FuzzyTermType(name="low", type_java=FuzzyTermType.TYPE_trapezoidShape, param=[0.1, 0.1, 0.244, 1.087]) pw.addFuzzyTerm(pw_low) #FUZZY TERM medium pw_medium = FuzzyTermType(name="medium", type_java=FuzzyTermType.TYPE_trapezoidShape, param=[0.244, 1.087, 1.419, 1.906]) pw.addFuzzyTerm(pw_medium) #FUZZY TERM high pw_high = FuzzyTermType(name="high", type_java=FuzzyTermType.TYPE_trapezoidShape, param=[1.419, 1.906, 2.5, 2.5]) pw.addFuzzyTerm(pw_high)