예제 #1
0
def write_xml(model, domains, filename):
    '''
        Write an XML representation of an ANFIS model to the given file.
    '''
    jfml_fis = convert(model, domains)
    Py4jfml.writeFSTtoXML(jfml_fis, filename)
    print('Written', filename)
예제 #2
0
from py4j.java_gateway import JavaGateway
from py4jfml.Py4Jfml import Py4jfml
import os

gateway = JavaGateway()

#percorso del file xml da valutare
str_xml = os.getcwd() + "/" + "IrisMamdani2.xml"

#Sistema fuzzy
fs = Py4jfml.load(str_xml)
#limite minimo massimo e medio SepalLength
limitiSL = [4.3, 7.9, 6.1]

#limite minimo massimo e medio SepalWidth
limitiSW = [2., 4.4, 3.2]

#limite minimo massimo e medio PetalLength
limitiPL = [1., 6.9, 3.9]

#limite minimo massimo e medio PetalWidth
limitiPW = [0.1, 2.5, 1.2]

for i in range(3):
    fuzzyVarSL = fs.getVariable("SepalLength")

    #imposto i valori
    fuzzyVarSL.setValue(float(limitiSL[i]))
    for j in range(3):
        fuzzyVarSW = fs.getVariable("SepalWidth")
ant2.addClause(ClauseType(pl, pl_medium))
ant2.addClause(ClauseType(pw, pw_medium))
con2 = ConsequentType()
con2.addThenClause(ClauseType(irisClass, irisClass_virginica))
r2.setAntecedent(ant2)
r2.setConsequent(con2)

rb.addRule(r2);

# RULE 3
r3 = FuzzyRuleType("rule3", connector="and", connectorMethod="MIN", weight=1.0)
ant3 = AntecedentType()
ant3.addClause(ClauseType(sl, sl_not_low))
ant3.addClause(ClauseType(pl, pl_not_low))
ant3.addClause(ClauseType(pw, pw_high))
con3 = ConsequentType()
con3.addThenClause(ClauseType(irisClass, irisClass_versicolor))
r3.setAntecedent(ant3)
r3.setConsequent(con3)

rb.addRule(r3)

iris.addRuleBase(rb)

print(iris)

# WRITTING IRIS EXAMPLE INTO AN XML FILE
irisXMLFile = "IrisMamdani2.xml"
Py4jfml.writeFSTtoXML(iris, irisXMLFile)

Py4jfml.kill()
예제 #4
0
from py4j.java_gateway import JavaGateway
from py4jfml.Py4Jfml import Py4jfml
import os

gateway = JavaGateway()

#percorso del file xml da valutare
str_xml = os.getcwd() + "/" + "IrisMamdani3.xml"

#creazione sistema fuzzy
fs1 = Py4jfml.load(str_xml)
fs2 = Py4jfml.load(str_xml)
fs3 = Py4jfml.load(str_xml)

#imposto i valori di input

#caso limite minimo
pw1 = fs1.getVariable("PetalWidth")
pw1.setValue(0.1)
#caso medio
pw2 = fs2.getVariable("PetalWidth")
pw2.setValue(2.5)
#caso limite massimo
pw3 = fs3.getVariable("PetalWidth")
pw3.setValue(1.2)

#valutazione fuzzy testlib 1
fs1.evaluate()

#valutazione fuzzy testlib 2
fs2.evaluate()
예제 #5
0
from py4j.java_gateway import JavaGateway
from py4jfml.Py4Jfml import Py4jfml

import matplotlib.pyplot as plt
from sklearn import datasets
from sklearn import svm

gateway = JavaGateway()

#%% load data
# import some data to play with
iris = datasets.load_iris()

#%% load FIS from FML file

fis = Py4jfml.load("IrisMamdani2.xml")
print(fis)

fis_output = []
for sample in iris.data:
    fis.getVariable("SepalLength").setValue(sample[0])
    fis.getVariable("SepalWidth").setValue(sample[1])
    fis.getVariable("PetalLength").setValue(sample[2])
    fis.getVariable("PetalWidth").setValue(sample[3])
    fis.evaluate()
    fis_output.append(fis.getVariable("irisClass").getValue())

    #%% Train a svm from scikit-learn
    clf = svm.SVC(gamma=0.001, C=100.)
    clf.fit(iris.data, iris.target)
    svm_output = clf.predict(iris.data)
예제 #6
0
con2 = ConsequentType()
con2.addThenClause(variable=tip, term=average)
rule2.setAntecedent(ant2)
rule2.setConsequent(con2)

rb.addRule(rule2)

#RULE 3
rule3 = FuzzyRuleType(name="rule3",
                      connector="or",
                      connectorMethod="MAX",
                      weight=1.0)
ant3 = AntecedentType()
ant3.addClause(c=ClauseType(service, excellent))
ant3.addClause(c=ClauseType(food, delicious))
con3 = ConsequentType()
con3.addThenClause(variable=tip, term=generous)
rule3.setAntecedent(ant3)
rule3.setConsequent(con3)

rb.addRule(rule3)

tipper.addRuleBase(rb)

#WRITTING TIPPER EXAMPLE INTO AN XML FILE
tipperXMLFile = "TipperTsukamoto2.xml"
Py4jfml.writeFSTtoXML(tipper, tipperXMLFile)

print(tipper)

Py4jfml.kill()
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.)
ant243 = AntecedentType()
ant243.addClause(ClauseType(pcc, pcc_high))
ant243.addClause(ClauseType(pcp, pcp_high))
ant243.addClause(ClauseType(pcf, pcf_high))
ant243.addClause(ClauseType(pcr, pcr_high))
ant243.addClause(ClauseType(fgb, fgb_high))
con243 = ConsequentType()
con243.addThenClause(variable=dhl, term=dhl_low)
r243.setAntecedent(ant243)
r243.setConsequent(con243)
rb.addRule(r243)

japaneseDietAssessment.addRuleBase(rb)

print(japaneseDietAssessment)

# WRITTING JAPANESE DIET ASSESSMENT EXAMPLE INTO AN XML FILE
japaneseDietAssessmentXMLFile = "JapaneseDietAssessmentMamdani.xml"
Py4jfml.writeFSTtoXML(japaneseDietAssessment, japaneseDietAssessmentXMLFile)

Py4jfml.kill()
#RULE 18
r18 = FuzzyRuleType(name="rule18", connector="and", connectorMethod="MIN", weight=1.0)
ant18 = AntecedentType()
ant18.addClause(c=ClauseType(ang, ang_vpos))
ant18.addClause(c=ClauseType(ca, ca_neu))
con18 = ConsequentType()
con18.addThenClause(variable=force, term=force_vpos)
r18.setAntecedent(value=ant18)
r18.setConsequent(value=con18)
rb.addRule(rule=r18)

#RULE 19
r19 = FuzzyRuleType(name="rule19", connector="and", connectorMethod="MIN", weight=1.0)
ant19 = AntecedentType()
ant19.addClause(c=ClauseType(ang, ang_pos_or_vpos))
ant19.addClause(c=ClauseType(ca, ca_pos_or_vpos))
con19 = ConsequentType()
con19.addThenClause(variable=force, term=force_vpos)
r19.setAntecedent(value=ant19)
r19.setConsequent(value=con19)
rb.addRule(r19)

invertedPendulum.addRuleBase(rb);

print(invertedPendulum)

#WRITTING INVERTED PENDULUM EXAMPLE INTO AN XML FILE
invertedPendulumXMLFile = "InvertedPendulumMamdani1.xml"
Py4jfml.writeFSTtoXML(invertedPendulum, invertedPendulumXMLFile)

Py4jfml.kill()
예제 #9
0
con2.addTskThenClause(variable=tip, term=average)
rule2.setAntecedent(ant2)
rule2.setTskConsequent(con2)

fr.addTskRule(rule2)

#RULE 3
rule3 = TskFuzzyRuleType(name="rule3",
                         connector="or",
                         connectorMethod="MAX",
                         weight=1.0)
ant3 = AntecedentType()
ant3.addClause(c=ClauseType(service, excellent))
ant3.addClause(c=ClauseType(food, delicious))
con3 = TskConsequentType()
con3.addTskThenClause(variable=tip, term=generous)
rule3.setAntecedent(ant3)
rule3.setTskConsequent(con3)

fr.addTskRule(rule3)

tipper.addRuleBase(fr)

#WRITTING TIPPER EXAMPLE INTO AN XML FILE
str_xml = "TipperTSK.xml"
Py4jfml.writeFSTtoXML(tipper, str_xml)

print(tipper)

Py4jfml.kill()
예제 #10
0
pydoc.help(ObjectFactory)
pydoc.help(KnowledgeBaseType)
pydoc.help(AggregatedFuzzyVariableType)
pydoc.help(AnYaDataCloudType)
pydoc.help(FuzzyVariableType)
pydoc.help(TskVariableType)
pydoc.help(TsukamotoVariableType)
pydoc.help(WZ)

pydoc.help(AntecedentType)
pydoc.help(AnYaAntecedentType)
pydoc.help(AnYaRuleType)
pydoc.help(ClauseType)
pydoc.help(ConsequentClausesType)
pydoc.help(ConsequentType)
pydoc.help(FuzzyRuleType)
pydoc.help(TskClauseType)
pydoc.help(TskConsequentClausesType)
pydoc.help(TskConsequentType)
pydoc.help(TskFuzzyRuleType)

pydoc.help(AnYaRuleBaseType)
pydoc.help(FuzzySystemRuleBase)
pydoc.help(MamdaniRuleBaseType)
pydoc.help(RuleBaseType)
pydoc.help(TskRuleBaseType)

pydoc.help(TsukamotoRuleBaseType)

Py4jfml.kill()
예제 #11
0
                    weight=1.0)
ant11 = AntecedentType()
ant11.addClause(c=ClauseType(pw, pw_highSIN))
con11 = ConsequentType()
con11.addThenClause(c=ClauseType(irisClass, irisClass_versicolor))
r11.setAntecedent(value=ant11)
r11.setConsequent(value=con11)
rb.addRule(r11)

# RULE 12
r12 = FuzzyRuleType(name="rule12",
                    connector="and",
                    connectorMethod="MIN",
                    weight=1.0)
ant12 = AntecedentType()
ant12.addClause(c=ClauseType(pw, pw_highS))
con12 = ConsequentType()
con12.addThenClause(c=ClauseType(irisClass, irisClass_versicolor))
r12.setAntecedent(value=ant12)
r12.setConsequent(value=con12)
rb.addRule(r12)

iris.addRuleBase(rb)

# WRITTING IRIS EXAMPLE INTO AN XML FILE
str_xml = os.getcwd() + "/" + "IrisMamdani3.xml"
Py4jfml.writeFSTtoXML(iris, str_xml)

print(iris)

Py4jfml.kill()
예제 #12
0
                              names=features + target,
                              dtype={target[0]: str})
    fold_dict["trainingset"] = trainingset
    testset = pd.read_csv("./" + fold_path + "/" + testset_filename,
                          header=None,
                          names=features + target,
                          dtype={target[0]: str})
    fold_dict["testset"] = testset

    # load FIS
    fis_array = []
    actual_array = []
    for fis_idx in range(len(term_num)):
        fis_filename = ("BEER3.txt_CV" + str(fold_idx) + "_RP" +
                        str(term_num[fis_idx]) + "_SP_FDTP_S.kb.xml.jfml.xml")
        fis_array += [Py4jfml.load("./" + fold_path + "/" + fis_filename)]
        fold_dict["fis_array"] = fis_array

        # test FIS
        actuals = []
        fis = fis_array[fis_idx]
        for i in range(len(testset)):
            for f in features:
                fvar = fis.getVariable(f)
                if fvar is not None:
                    fvar.setValue(testset[f][i])
            fis.evaluate()
            actuals.append(str(fis.getVariable(target[0]).getValue()))
        actual_array += [actuals]
    fold_dict["fis_results"] = actual_array