Esempio n. 1
0
def _mk_antecedents(local_jfml, rules, invars):
    '''
        Convert the rule antecedents to ClauseType, and combine for each rule.
        Return a list with one AntecedentType per rule.
    '''
    row_ants = []
    for rule_idx in rules.mf_indices:
        thisrule = AntecedentType()
        for (varname, fv), i in zip(invars, rule_idx):
            jfml_var = local_jfml.get_variable(varname)
            mfname = list(fv.mfdefs.keys())[i]
            jfml_term = local_jfml.get_term(varname, mfname)
            ct = ClauseType(jfml_var, jfml_term)
            thisrule.addClause(c=ct)
        row_ants.append(thisrule)
    return row_ants
irisClass_virginica = FuzzyTermType("virginica", FuzzyTerm.TYPE_singletonShape, [2.0])
irisClass.addFuzzyTerm(irisClass_virginica)

# FUZZY TERM versicolor
irisClass_versicolor = FuzzyTermType("versicolor", FuzzyTerm.TYPE_singletonShape, [3.0])
irisClass.addFuzzyTerm(irisClass_versicolor)

kb.addVariable(irisClass)

# RULE BASE
rb = MamdaniRuleBaseType("rulebase-iris")

# RULE 1
r1 = FuzzyRuleType("rule1", connector="and", connectorMethod="MIN", weight=1.0)
ant1 = AntecedentType()
ant1.addClause(ClauseType(pw, pw_low))
con1 = ConsequentType()
con1.addThenClause(ClauseType(irisClass, irisClass_setosa))
r1.setAntecedent(ant1)
r1.setConsequent(con1)

rb.addRule(r1)

# RULE 2
r2 = FuzzyRuleType("rule2", connector="and", connectorMethod="MIN", weight=1.0)
ant2 = AntecedentType()
ant2.addClause(ClauseType(sw, sw_not_high))
ant2.addClause(ClauseType(pl, pl_medium))
ant2.addClause(ClauseType(pw, pw_medium))
con2 = ConsequentType()
con2.addThenClause(ClauseType(irisClass, irisClass_virginica))
Esempio n. 3
0
                             type_java=FuzzyTermType.TYPE_rightGaussianShape,
                             paramList=[20.0, 10.0])
tip.addTsukamotoTerm(t=generous)

kb.addVariable(tip)

#RULE BASE
rb = TsukamotoRuleBaseType("rulebase1")

#RULE 1
rule1 = FuzzyRuleType(name="rule1",
                      connector="or",
                      connectorMethod="MAX",
                      weight=1.0)
ant1 = AntecedentType()
ant1.addClause(c=ClauseType(food, rancid))
ant1.addClause(c=ClauseType(service, poor, "very"))
con1 = ConsequentType()
con1.addThenClause(variable=tip, term=cheap)
rule1.setAntecedent(ant1)
rule1.setConsequent(con1)

rb.addRule(rule1)

#RULE 2
rule2 = FuzzyRuleType(name="rule2",
                      connector="or",
                      connectorMethod="MAX",
                      weight=1.0)
ant2 = AntecedentType()
ant2.addClause(c=ClauseType(service, good))
dhl.addFuzzyTerm(dhl_high)

# FUZZY TERM high
dhl_veryhigh = FuzzyTermType("very high", FuzzyTermType.TYPE_trapezoidShape,
                             [7.5, 8.5, 10., 10.])
dhl.addFuzzyTerm(dhl_veryhigh)

kb.addVariable(dhl)

# RULE BASE
rb = MamdaniRuleBaseType("rulebase1")

# RULE 1
r1 = FuzzyRuleType("rule1", connector="and", connectorMethod="MIN", weight=1.)
ant1 = AntecedentType()
ant1.addClause(ClauseType(pcc, pcc_low))
ant1.addClause(ClauseType(pcp, pcp_low))
ant1.addClause(ClauseType(pcf, pcf_low))
ant1.addClause(ClauseType(pcr, pcr_low))
ant1.addClause(ClauseType(fgb, fgb_low))
con1 = ConsequentType()
con1.addThenClause(variable=dhl, term=dhl_verylow)
r1.setAntecedent(ant1)
r1.setConsequent(con1)
rb.addRule(r1)

# RULE 243
r243 = FuzzyRuleType("rule243",
                     connector="and",
                     connectorMethod="MIN",
                     weight=1.)
force_pos = FuzzyTermType(name="positive", type_java=FuzzyTermType.TYPE_triangularShape, param=[128.0, 168.0, 208.0])
force.addFuzzyTerm(ft=force_pos)

#FUZZY TERM VPOS
force_vpos = FuzzyTermType(name="very positive", type_java=FuzzyTermType.TYPE_trapezoidShape, param=[168.0, 208.0, 255.0, 255.0])
force.addFuzzyTerm(ft=force_vpos)

kb.addVariable(var=force)

#RULE BASE
rb = MamdaniRuleBaseType(name="rulebase1")

#RULE 1
r1 = FuzzyRuleType(name="rule1", connector="and", connectorMethod="MIN", weight=1.0)
ant1 = AntecedentType()
ant1.addClause(c=ClauseType(ang, ang_vneg_or_neg))
ant1.addClause(c=ClauseType(ca, ca_vneg_or_neg))
con1 = ConsequentType()
con1.addThenClause(variable=force, term=force_vneg)
r1.setAntecedent(value=ant1)
r1.setConsequent(value=con1)
rb.addRule(rule=r1)

#RULE 2
r2 = FuzzyRuleType(name="rule2", connector="and", connectorMethod="MIN", weight=1.0)
ant2 = AntecedentType()
ant2.addClause(c=ClauseType(ang, ang_vneg))
ant2.addClause(c=ClauseType(ca, ca_neu))
con2 = ConsequentType()
con2.addThenClause(variable=force, term=force_vneg)
r2.setAntecedent(value=ant2)
good = FuzzyTermType("good", FuzzyTermType.TYPE_gaussianShape, [5., 4.])
service.addFuzzyTerm(good)

# FUZZY TERM excellent
excellent = FuzzyTermType("excellent", FuzzyTermType.TYPE_rightGaussianShape,
                          [10., 2.])
service.addFuzzyTerm(excellent)

kb.addVariable(service)

# AGGREGATED FUZZY VARIABLE quality
quality = AggregatedFuzzyVariableType("quality")

# AGGREGATED FUZZY TERM acceptable
acceptable = AggregatedFuzzyTermType("acceptable")
acceptable_t1 = ClauseType(food, delicious)
acceptable_t2 = ClauseType(service, good)
acceptable_t3 = ClauseType(service, excellent)
acceptable_or = OrAggregatedType(c1=acceptable_t2, c2=acceptable_t3)
acceptable_and = AndAggregatedType(c1=acceptable_t1, term2=acceptable_or)
acceptable.setAnd(acceptable_and)

# AGGREGATED FUZZY TERM bad
bad = AggregatedFuzzyTermType("bad")
bad_t1 = ClauseType(food, rancid)
bad_t2 = ClauseType(service, poor)
bad_or = OrAggregatedType(c1=bad_t1, c2=bad_t2)
bad.setOr(bad_or)

quality.addAggregatedFuzzyTerm(acceptable)
quality.addAggregatedFuzzyTerm(bad)
Esempio n. 7
0
ang_or1 = OrLogicalType("BSUM", "very negative", "negative")
ang_c1 = CircularDefinitionType(orLogical=ang_or1, var=ang)
nameTerm = "very negative or negative"
ang_vneg_or_neg = FuzzyTermType(nameTerm, circular=ang_c1)
ang.addFuzzyTerm(ang_vneg_or_neg)
name1 = "ChangeAngle"
ca = FuzzyVariableType(name1, 0.0, 255.0)
ca_vneg = FuzzyTermType(nameTerm, FuzzyTermType.TYPE_trapezoidShape,
                        [0.0, 0.0, 48.0, 88.0])
ca.addFuzzyTerm(ca_vneg)
ca_or1 = OrLogicalType("BSUM", "very negative", "negative")
ca_c1 = CircularDefinitionType(orLogical=ca_or1, var=ca)
ca_vneg_or_neg = FuzzyTermType(nameTerm, circular=ca_c1)
ca.addFuzzyTerm(ca_vneg_or_neg)
ant1 = AntecedentType()
ant1.addClause(ClauseType(ang, ang_vneg_or_neg))
ant1.addClause(ClauseType(ca, ca_vneg_or_neg))
if ant1.getClauses()[1].getVariable().getName() == name1:
    print("AntecedentType, ClauseType, FuzzyVariableType test case passed.")
else:
    print("AntecedentType, ClauseType, FuzzyVariableType test case failed.")
if ant1.getClauses()[1].getTerm().getName() == nameTerm:
    print("AntecedentType, ClauseType, FuzzyTermType test case passed.")
else:
    print("AntecedentType, ClauseType, FuzzyTermType test case failed.")
ant1 = AnYaAntecedentType(dataCloud=anyaVar)
name = str(anyaVar.getName()) + "modified"
anyaVar.setName(name)
ant1.setDataCloudName(anyaVar.getName())
if ant1.getDataCloudName() == name:
    print("AnYaAntecedentType, AnYaDataCloudType test case passed.")
Esempio n. 8
0
service = FuzzyVariableType("service", 0., 10.)

# FUZZY TERM poor
poor = FuzzyTermType("poor", FuzzyTermType.TYPE_leftGaussianShape, [0., 2.])
service.addFuzzyTerm(poor)

# FUZZY TERM good
good = FuzzyTermType("good", FuzzyTermType.TYPE_gaussianShape, [5., 4.])
service.addFuzzyTerm(good)

# FUZZY TERM excellent
excellent = FuzzyTermType("excellent", FuzzyTermType.TYPE_rightGaussianShape,
                          [10., 2.])
service.addFuzzyTerm(excellent)

acceptable_t1 = ClauseType(food, delicious)
acceptable_t2 = ClauseType(service, good)
acceptable_t3 = ClauseType(service, excellent)
acceptable_or = OrAggregatedType(c1=acceptable_t2, c2=acceptable_t3)
acceptable_and = AndAggregatedType(c1=acceptable_t1, term2=acceptable_or)

try:
    property_tnorm = "property tNorm"
    acceptable_and.setTNorm(property_tnorm)
    assert property_tnorm == acceptable_and.getTNorm()

    property_tConorm = "property tConorm"
    acceptable_or.setTConorm(property_tConorm)
    assert property_tConorm == acceptable_or.getTConorm()

    print("Testing of package aggregated: SUCCESSFUL")
Esempio n. 9
0
                                     param=[3.])
irisClass.addFuzzyTerm(irisClass_versicolor)

kb.addVariable(irisClass)

#RULE BASE
rb = MamdaniRuleBaseType("rulebase-iris")

#RULE 1
r1 = FuzzyRuleType(name="rule1",
                   connector="and",
                   connectorMethod="MIN",
                   weight=1.0)

ant1 = AntecedentType()
ant1.addClause(c=ClauseType(pw, pw_lowLIN))
con1 = ConsequentType()
con1.addThenClause(c=ClauseType(variable=irisClass, term=irisClass_setosa))
r1.setAntecedent(value=ant1)
r1.setConsequent(value=con1)
rb.addRule(r1)

#RULE 2
r2 = FuzzyRuleType("rule2", connector="and", connectorMethod="MIN", weight=1.0)
ant2 = AntecedentType()
ant2.addClause(c=ClauseType(pw, pw_lowGAU))
con2 = ConsequentType()
con2.addThenClause(c=ClauseType(irisClass, irisClass_setosa))
r2.setAntecedent(value=ant2)
r2.setConsequent(value=con2)
rb.addRule(r2)
    param=[2.0, 3.0, 3.0])
irisClass.addFuzzyTerm(irisClass_versicolor)

kb.addVariable(irisClass)

#RULE BASE
rb = MamdaniRuleBaseType("rulebase-iris")

#RULE 1
r1 = FuzzyRuleType(name="rule1",
                   connector="and",
                   connectorMethod="MIN",
                   weight=1.0)

ant1 = AntecedentType()
ant1.addClause(c=ClauseType(pw, pw_low))
con1 = ConsequentType()
con1.addThenClause(variable=irisClass, term=irisClass_setosa)
r1.setAntecedent(value=ant1)
r1.setConsequent(value=con1)

rb.addRule(r1)

#RULE 2
r2 = FuzzyRuleType(name="rule2",
                   connector="and",
                   connectorMethod="MIN",
                   weight=1.0)

ant2 = AntecedentType()
ant2.addClause(c=ClauseType(pw, pw_medium))