def generate_mf_group(self, G, x): mf_group = {} for (k, v) in G.iteritems(): shp = v['shp'] mf = v['mf'] if mf == 'trap': mf_group[k] = trapmf(x, shp) if mf == 'tri': mf_group[k] = trimf(x, shp) if mf == 'gbell': mf_group[k] = gbellmf(x, shp[0], shp[1], shp[2]) if mf == 'gauss': mf_group[k] = gaussmf(x, shp[0], shp[1]) if mf == 'gauss2': mf_group[k] = gauss2mf(x, shp[0], shp[1]) if mf == 'sig': mf_group[k] = sigmf(x, shp[0], shp[1]) if mf == 'psig': mf_group[k] = psigmf(x, shp[0], shp[1], shp[2], shp[3]) if mf == 'zmf': mf_group[k] = zmf(x, shp[0], shp[1], shp[2], shp[3]) if mf == 'smf': mf_group[k] = smf(x, shp[0], shp[1], shp[2], shp[3]) if mf == 'pimf': mf_group[k] = pimf(x, shp[0], shp[1], shp[2], shp[3]) if mf == 'piecemf': mf_group[k] = piecemf(x, shp[0], shp[1], shp[2], shp[3]) return mf_group
def test_gauss2mf(): x = np.arange(-4, 5.1, 0.1) expected = np.ones_like(x) expected[x < 1.2] = np.exp(-(x[x < 1.2] - 1.2)**2 / (2 * 0.45**2)) expected[x > 3.1] = np.exp(-(x[x > 3.1] - 3.1)**2 / (2 * 0.9**2)) test = gauss2mf(x, 1.2, 0.45, 3.1, 0.9) assert_allclose(test, expected)
def test_gauss2mf(): x = np.arange(-4, 5.1, 0.1) expected = np.ones_like(x) expected[x < 1.2] = np.exp(- (x[x < 1.2] - 1.2)**2 / (2 * 0.45**2)) expected[x > 3.1] = np.exp(- (x[x > 3.1] - 3.1)**2 / (2 * 0.9**2)) test = gauss2mf(x, 1.2, 0.45, 3.1, 0.9) assert_allclose(test, expected)
def gaussprod(x, mean1, sigma1, mean2, sigma2): '''Ensure the means are in correct order before calling gauss2mf''' if mean1 > mean2: mean1, sigma1, mean2, sigma2 = mean2, sigma2, mean1, sigma1 return skmemb.gauss2mf(x, mean1, sigma1, mean2, sigma2)