示例#1
0
def ex2_model():
    invardefs = [
            ('x', make_bell_mfs(2.5, 2, [1, 6])),
            ('y', make_bell_mfs(2.5, 2, [1, 6])),
            ('z', make_bell_mfs(2.5, 2, [1, 6])),
            ]
    outvars = ['output']
    model = anfis.AnfisNet('Jang\'s example 2', invardefs, outvars)
    return model
示例#2
0
def ex1_model():
    '''
        These are the original (untrained) MFS for Jang's example 1.
    '''
    invardefs = [
            ('x0', make_bell_mfs(3.33333, 2, [-10, -3.333333, 3.333333, 10])),
            ('x1', make_bell_mfs(3.33333, 2, [-10, -3.333333, 3.333333, 10])),
            ]
    outvars = ['y0']
    anf = anfis.AnfisNet('Jang\'s example 1', invardefs, outvars)
    return anf
def vignette_ex2():
    '''
        These are the original (untrained) MFS for Vignette example 2.
        Like example 1, but uses 5 Bell MFs for each input.
    '''
    invardefs = [
            ('x0', make_bell_mfs(4, 1, [-10, -5, 0, 5, 10])),
            ('x1', make_bell_mfs(4, 1, [-10, -5, 5, 0, 10])),
            ]
    outvars = ['y0']
    anf = anfis.AnfisNet('Vignette Example 1', invardefs, outvars)
    return anf
def vignette_ex1():
    '''
        These are the original (untrained) MFS for Vignette example 1.
        Uses 4 Bell membership functions in each input
    '''
    invardefs = [
            ('x0', make_bell_mfs(4, 1, [-10, -3.5, 3.5, 10])),
            ('x1', make_bell_mfs(4, 1, [-10, -3.5, 3.5, 10])),
            ]
    outvars = ['y0']
    anf = anfis.AnfisNet('Vignette Example 1', invardefs, outvars)
    return anf
def plant_model_untrained():
    '''
        Thhis is the initial (untrained) model: (y_now, y_next) -> u
        Uses 3 Bell membership functions for each input.
    '''
    invardefs = [
        ('y_now', make_bell_mfs(1, 2, [-1, 0, 1])),
        ('y_next', make_bell_mfs(1, 2, [-1, 0, 1])),
    ]
    outvars = ['u']
    anf = anfis.AnfisNet('Plant Model', invardefs, outvars)
    return anf
示例#6
0
def ex4_model():
    '''
        Example 4 model, from Jang's data; 4 variables with 2 MFs each.
        Predict x(t+6) based on x(t-18), x(t-12), x(t-6), x(t)
        These are the starting MFs values he suggests.
    '''
    invardefs = [
            ('xm18', make_bell_mfs(0.444045, 2, [0.425606, 1.313696])),
            ('xm12', make_bell_mfs(0.444045, 2, [0.425606, 1.313696])),
            ('xm6',  make_bell_mfs(0.444045, 2, [0.425606, 1.313696])),
            ('x',    make_bell_mfs(0.444045, 2, [0.425606, 1.313696])),
            ]
    outvars = ['xp6']
    model = anfis.AnfisNet('Jang\'s example 4', invardefs, outvars)
    return model
示例#7
0
def initial_anfis():
    '''
        Build and return a (non-trained) anfis model: (theta, dtheta) -> force
        Assume range for theta is (-20, 20) and dtheta is (-50, 50)
        Use 2 Bell MFs for each input, and non-hybrid learning.
    '''
    invardefs = [
        ('theta', make_bell_mfs(20, 2, [-20, 20])),
        ('dtheta', make_bell_mfs(50, 2, [-50, 50])),
    ]
    outvars = ['force']
    anf = anfis.AnfisNet('Pendulum Controller',
                         invardefs,
                         outvars,
                         hybrid=False)
    return anf
示例#8
0
def jang_traned_anfis():
    '''
        This is the trained ANFIS model from Jang's book (pg 474)
    '''
    invardefs = [
        ('theta', make_bell_mfs(-1.59, 2.34, [-19.49, 19.49])),
        ('dtheta', make_bell_mfs(85.51, 1.94, [-23.21, 23.21])),
    ]
    outvars = ['force']
    coeffs = torch.tensor([
        [0.0502, 0.1646, -10.09],
        [0.0083, 0.0119, -1.09],
        [0.0083, 0.0119, 1.09],
        [0.0502, 0.1646, 10.09],
    ],
                          dtype=dtype).unsqueeze(1)
    anf = anfis.AnfisNet('Pendulum Controller',
                         invardefs,
                         outvars,
                         hybrid=False)
    anf.coeff = coeffs
    return anf
示例#9
0
def ex3_model(mfnum=7):
    '''
        Example 3 model, with variable number of Bell MFs, range (-1,+1).
        Specify the no. of MFs, or make it 0 and I'll use Jang's 5 centers.
        Either way, the Bell width/slope values are from Jang's data.
    '''
    # The paper says 7 MFs are best, but his code uses 5 MFs
    if mfnum < 1:  # use the 5 MF values from Jang's code
        centers = [-0.999921, -0.499961, 0.000000, 0.499961, 0.99992]
    else:  # just spread them evenly accross the range (-1, +1)
        centers = np.linspace(-1, 1, mfnum)
    invardefs = [('k', make_bell_mfs(0.249980, 4, centers))]
    outvars = ['y']
    model = anfis.AnfisNet('Jang\'s example 3', invardefs, outvars)
    return model