def my_model_k1():
    """
    Initialization of the ANFIS regressor for k1 prediction. Single output.
    Fuzzy reasoning and rules can be modified according to human-expertise.
    :return:
    model: Initialized ANFIS
    """
    invardefs = [
        ('x0', make_gauss_mfs(0.5, np.linspace(0, 1, 2))),
        ('x1', make_gauss_mfs(0.5, np.linspace(0, 1, 4))),
        ('x2', make_gauss_mfs(0.5, np.linspace(0, 1, 3))),
        ('x3', make_gauss_mfs(0.5, np.linspace(0, 1, 3))),
        ('x4', make_gauss_mfs(0.5, np.linspace(0, 1, 6))),
        ('x5', make_gauss_mfs(0.5, np.linspace(0, 1, 3))),
        ('x6', make_gauss_mfs(0.5, np.linspace(0, 1, 6))),
        ('x7', make_gauss_mfs(0.5, np.linspace(0, 1, 5))),
        ('x8', make_gauss_mfs(0.5, np.linspace(0, 1, 5))),
        ('x9', make_gauss_mfs(0.5, np.linspace(0, 1, 7))),
    ]
    outvars = ['k1']
    model = anfis.AnfisNet('My_Anfis', invardefs, outvars, grid=False)

    rules = [[1, 1, 2, 2, 4, 1, 4, 0, 1, 6], [0, 0, 0, 0, 0, 0, 0, 3, 4, 2],
             [1, 3, 2, 1, 5, 2, 5, 2, 0, 0], [0, 0, 1, 1, 1, 0, 1, 1, 3, 1],
             [1, 3, 2, 2, 5, 2, 5, 0, 0, 3], [0, 2, 0, 0, 2, 1, 2, 4, 3, 4],
             [0, 2, 1, 1, 3, 1, 3, 1, 2, 4], [1, 1, 2, 1, 4, 1, 4, 2, 1, 5]]
    model.set_rules(rules)
    return model
def my_model_class1():
    """
    Initialization of the ANFIS classifier for virtual generic model. Multi-output.
    Fuzzy reasoning and rules can be modified according to human-expertise.
    :return:
    model: Initialized ANFIS
    """
    invardefs = [('x0', make_gauss_mfs(0.5, np.linspace(0, 1, 5))),
                 ('x1', make_gauss_mfs(0.5, np.linspace(0, 1, 4))),
                 ('x2', make_gauss_mfs(0.5, np.linspace(0, 1, 3))),
                 ('x3', make_gauss_mfs(0.5, np.linspace(0, 1, 3))),
                 ('x4', make_gauss_mfs(0.5, np.linspace(0, 1, 7))),
                 ('x5', make_gauss_mfs(0.5, np.linspace(0, 1, 3))),
                 ('x6', make_gauss_mfs(0.5, np.linspace(0, 1, 5))),
                 ('x7', make_gauss_mfs(0.5, np.linspace(0, 1, 5))),
                 ('x8', make_gauss_mfs(0.5, np.linspace(0, 1, 2))),
                 ('x9', make_gauss_mfs(0.5, np.linspace(0, 1, 7)))]

    outvars = ['dc1', 'dc2', 'dc3', 'dc4', 'dc5', 'dc6', 'dc7', 'dc8']
    model = anfis.AnfisNet('My_Anfis',
                           invardefs,
                           outvars,
                           hybrid=False,
                           grid=False)
    # 20.07
    rules = [[0, 0, 1, 2, 6, 0, 0, 0, 1, 3], [3, 0, 0, 0, 2, 0, 3, 2, 0, 0],
             [2, 3, 2, 1, 1, 2, 2, 2, 1, 4], [1, 0, 0, 1, 5, 0, 1, 1, 0, 2],
             [0, 2, 2, 2, 4, 1, 0, 0, 1, 1], [4, 1, 1, 0, 0, 0, 4, 2, 0, 5],
             [1, 1, 1, 1, 2, 0, 1, 4, 0, 6], [2, 0, 1, 1, 3, 0, 2, 3, 1, 3]]

    model.set_rules(rules, hybrid=False)
    return model
def vignette_ex3():
    '''
        These are the original (untrained) MFS for Vignette example 3.
        Like example 1, but now using 5 Gaussian MFs.
    '''
    invardefs = [
            ('x0', make_gauss_mfs(2, [-10, -5, 0, 5, 10])),
            ('x1', make_gauss_mfs(2, [-10, -5, 0, 5, 10]))
            ]
    outvars = ['y0']
    anf = anfis.AnfisNet('Vignette Example 3', invardefs, outvars)
    return anf
Beispiel #4
0
def model():
    invardefs = [
        # ainda n escolhi os centros e sigma
        ('x(t-18)', make_gauss_mfs(sigma=0.2, mu_list=[0.4, 1.2])),
        ('x(t-12)', make_gauss_mfs(sigma=0.2, mu_list=[0.4, 1.2])),
        ('x(t-6)', make_gauss_mfs(sigma=0.2, mu_list=[0.4, 1.2])),
        ('x(t)', make_gauss_mfs(sigma=0.2, mu_list=[0.4, 1.2]))
    ]
    outvars = ['ys']

    model = anfis.AnfisNet('mackey-glass', invardefs, outvars)
    return model
def vignette_ex5():
    '''
        These are the original (untrained) MFS for Vignette example 5
        Same MFs as for example 3, but now there will be two outputs.
        These will be: y0 = sinc(x0, x1) and y1 = 1 - sinc(x0,x1).
    '''
    invardefs = [
            ('x0', make_gauss_mfs(2, [-10, -5, 0, 5, 10])),
            ('x1', make_gauss_mfs(2, [-10, -5, 0, 5, 10]))
            ]
    outvars = ['y0', 'y1']
    anf = anfis.AnfisNet('Vignette Example 5', invardefs, outvars)
    return anf
Beispiel #6
0
def fuzzy_classifier(num_in, num_mfs=5):
    '''
        Make a fuzzy classifier with 5 MFS per input, and one output
    '''
    sigma = 10 / num_mfs
    mulist = torch.linspace(-5, 5, num_mfs).tolist()
    invardefs = [('x{}'.format(i), membership.make_gauss_mfs(sigma, mulist))
                 for i in range(num_in)]
    outvars = ['y0']
    model = anfis.AnfisNet('Simple classifier', invardefs, outvars)
    return model
Beispiel #7
0
def ex1_model():
    '''
        Define modelo e parametros para funcoes de pertinencia
    '''
    # invardefs = [
    #         ('x0', make_bell_mfs(3.33333, 2, list(np.linspace(0, 2*np.pi, 3))))
    #         ]
    invardefs = [('x0',
                  make_gauss_mfs(sigma=1.2,
                                 mu_list=np.linspace(0, 2 * np.pi, 3)))]
    outvars = ['y0']

    anf = anfis.AnfisNet('Aproximacao senoidal', invardefs, outvars)
    return anf
Beispiel #8
0
 def mk_var(name):
     return (name, make_gauss_mfs(1, [-5, 0.08, 1.67]))
Beispiel #9
0
 def mk_var(name, centros, i):
     return (name, make_gauss_mfs(3,
                                  [centros[n, i] for n in range(n_rules)]))
Beispiel #10
0
def classifier_rig(window="small"):
    """
    Initialization of the ANFIS classifier for test rig. Multi-output.
    Fuzzy reasoning and rules can be modified according to human-expertise.
    :param window: "small", or "large" window size
    :return:
    model: Initialized ANFIS
    """
    if window == "small":
        invardefs = [
            ('x0', make_gauss_mfs(0.5, np.linspace(0, 1, 2))),
            ('x1', make_gauss_mfs(0.5, np.linspace(0, 1, 6))),
            ('x2', make_gauss_mfs(0.5, np.linspace(0, 1, 4))),
            ('x3', make_gauss_mfs(0.5, np.linspace(0, 1, 3))),
            ('x4', make_gauss_mfs(0.5, np.linspace(0, 1, 3))),
            ('x5', make_gauss_mfs(0.5, np.linspace(0, 1, 3))),
            ('x6', make_gauss_mfs(0.5, np.linspace(0, 1, 2))),
            ('x7', make_gauss_mfs(0.5, np.linspace(0, 1, 3))),
            ('x8', make_gauss_mfs(0.5, np.linspace(0, 1, 2))),
            ('x9', make_gauss_mfs(0.5, np.linspace(0, 1, 3))),
        ]
        # 22.07 small
        rules = [[1, 0, 0, 2, 2, 0, 0, 2, 0,
                  2], [0, 2, 2, 1, 0, 1, 1, 1, 1, 1],
                 [0, 5, 1, 0, 1, 2, 1, 0, 1,
                  0], [0, 1, 2, 0, 1, 2, 1, 0, 1, 0],
                 [0, 4, 3, 1, 0, 1, 1, 1, 1, 1],
                 [0, 3, 3, 1, 0, 1, 1, 1, 1, 1]]
    else:
        invardefs = [
            ('x0', make_gauss_mfs(0.5, np.linspace(0, 1, 3))),
            ('x1', make_gauss_mfs(0.5, np.linspace(0, 1, 3))),
            ('x2', make_gauss_mfs(0.5, np.linspace(0, 1, 4))),
            ('x3', make_gauss_mfs(0.5, np.linspace(0, 1, 4))),
            ('x4', make_gauss_mfs(0.5, np.linspace(0, 1, 4))),
            ('x5', make_gauss_mfs(0.5, np.linspace(0, 1, 4))),
            ('x6', make_gauss_mfs(0.5, np.linspace(0, 1, 2))),
            ('x7', make_gauss_mfs(0.5, np.linspace(0, 1, 3))),
            ('x8', make_gauss_mfs(0.5, np.linspace(0, 1, 4))),
            ('x9', make_gauss_mfs(0.5, np.linspace(0, 1, 3))),
        ]
        # 22.07 Large
        rules = [[2, 0, 0, 3, 0, 0, 0, 2, 0,
                  2], [0, 2, 3, 0, 1, 1, 1, 1, 3, 1],
                 [1, 1, 1, 2, 3, 2, 1, 0, 1,
                  0], [1, 2, 2, 0, 2, 3, 1, 0, 2, 0],
                 [0, 2, 3, 1, 1, 1, 1, 1, 3, 1]]
    outvars = ['nc', 'dc1', 'dc2', 'dc3', 'dc4', 'dc5', 'dc6']
    model = anfis.AnfisNet('My_Anfis',
                           invardefs,
                           outvars,
                           hybrid=False,
                           grid=False)
    model.set_rules(rules, hybrid=False)
    return model
Beispiel #11
0
def my_model_c1(rules='less'):
    """
    Initialization of the ANFIS regressor for c1 prediction. Single output.
    Fuzzy reasoning and rules can be modified according to human-expertise.
    :param rules: one rule for each case (less) or three rules for each case (more)
    :return:
    model: Initialized ANFIS
    """
    if rules == 'less':
        invardefs = [
            ('x0', make_gauss_mfs(0.5, np.linspace(0, 1, 3))),
            ('x1', make_gauss_mfs(0.5, np.linspace(0, 1, 7))),
            ('x2', make_gauss_mfs(0.5, np.linspace(0, 1, 4))),
            ('x3', make_gauss_mfs(0.5, np.linspace(0, 1, 7))),
            ('x4', make_gauss_mfs(0.5, np.linspace(0, 1, 6))),
            ('x5', make_gauss_mfs(0.5, np.linspace(0, 1, 6))),
            ('x6', make_gauss_mfs(0.5, np.linspace(0, 1, 7))),
            ('x7', make_gauss_mfs(0.5, np.linspace(0, 1, 5))),
            ('x8', make_gauss_mfs(0.5, np.linspace(0, 1, 7))),
            ('x9', make_gauss_mfs(0.5, np.linspace(0, 1, 7))),
        ]

        # 14.07
        rules = [[1, 0, 0, 6, 5, 1, 6, 0, 0,
                  6], [0, 4, 0, 2, 2, 0, 2, 0, 3, 2],
                 [2, 5, 3, 1, 1, 5, 1, 4, 5,
                  1], [0, 1, 0, 5, 4, 0, 5, 0, 1, 5],
                 [2, 2, 2, 4, 0, 4, 4, 3, 3,
                  4], [1, 6, 1, 0, 2, 3, 0, 1, 6, 0],
                 [1, 4, 1, 2, 3, 3, 2, 2, 4, 2],
                 [1, 3, 0, 3, 4, 2, 3, 0, 2, 3]]

    elif rules == 'more':
        invardefs = [
            ('x0', make_gauss_mfs(0.5, np.linspace(0, 1, 5))),
            ('x1', make_gauss_mfs(0.5, np.linspace(0, 1, 6))),
            ('x2', make_gauss_mfs(0.5, np.linspace(0, 1, 10))),
            ('x3', make_gauss_mfs(0.5, np.linspace(0, 1, 5))),
            ('x4', make_gauss_mfs(0.5, np.linspace(0, 1, 8))),
            ('x5', make_gauss_mfs(0.5, np.linspace(0, 1, 5))),
            ('x6', make_gauss_mfs(0.5, np.linspace(0, 1, 8))),
            ('x7', make_gauss_mfs(0.5, np.linspace(0, 1, 9))),
            ('x8', make_gauss_mfs(0.5, np.linspace(0, 1, 5))),
            ('x9', make_gauss_mfs(0.5, np.linspace(0, 1, 11))),
        ]

        rules = [[4, 1, 6, 4, 0, 4, 0, 1, 4,
                  4], [3, 0, 8, 4, 3, 4, 3, 4, 4, 7],
                 [4, 5, 8, 4, 5, 4, 5, 6, 4,
                  8], [3, 0, 7, 4, 2, 4, 2, 3, 4, 6],
                 [4, 4, 8, 4, 4, 4, 4, 5, 4,
                  7], [4, 3, 9, 4, 7, 4, 7, 8, 4, 10],
                 [4, 3, 9, 4, 6, 4, 6, 7, 4,
                  9], [4, 2, 6, 4, 1, 4, 1, 2, 4, 5],
                 [0, 2, 5, 0, 0, 0, 1, 0, 0,
                  0], [4, 2, 1, 4, 0, 4, 1, 1, 4, 3],
                 [2, 2, 4, 2, 0, 2, 1, 1, 2,
                  2], [0, 2, 2, 0, 0, 0, 1, 1, 0, 2],
                 [0, 2, 5, 0, 0, 0, 1, 0, 0,
                  1], [3, 2, 0, 3, 0, 3, 1, 1, 3, 3],
                 [0, 2, 3, 0, 0, 0, 1, 0, 0, 2],
                 [1, 2, 4, 1, 0, 1, 1, 1, 1, 2]]
    outvars = ['c1']
    model = anfis.AnfisNet('My_Anfis', invardefs, outvars, grid=False)
    model.set_rules(rules)
    return model
Beispiel #12
0
 def mk_var(name, centros, i):  # de iris_example
     return (name, make_gauss_mfs(1,
                                  [centros[n, i] for n in range(n_rules)]))
Beispiel #13
0
 def mk_var(name, centros, i):  # de iris_example
     return (name,
             make_gauss_mfs(1,
                            [centros[0, i], centros[1, i], centros[2, i]]))