示例#1
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")
示例#2
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)
示例#3
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()
示例#4
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