コード例 #1
0
def test_interp_membership():
    x = np.r_[0:4.1:0.1]
    mfx = trapmf(x, [0, 1, 2, 4])

    yy = interp_membership(x, mfx, 0)
    assert yy == 0

    yy = interp_membership(x, mfx, 0.535)
    assert_allclose(np.r_[yy], np.r_[0.535])

    yy = interp_membership(x, mfx, np.pi / 3.)
    assert yy == 1

    yy = interp_membership(x, mfx, 2.718)
    assert_allclose(np.r_[yy], np.r_[0.641])

    assert_allclose(interp_membership(x, mfx, [0.2, 2.73, 3.14]),
                    np.asarray([interp_membership(x, mfx, i)
                                for i in [0.2, 2.73, 3.14]]))

    mfx[-1] = 0.7
    mfx[0] = 0.2
    assert_allclose([0, 0], interp_membership(x, mfx, [-11, 5]))
    assert_allclose([0.2, 0.7], interp_membership(x, mfx, [-11, 5],
                                                  False))
コード例 #2
0
def test_interp_membership():
    x = np.r_[0:4.1:0.1]
    mfx = trapmf(x, [0, 1, 2, 4])

    yy = interp_membership(x, mfx, 0)
    assert yy == 0

    yy = interp_membership(x, mfx, 0.535)
    assert_allclose(np.r_[yy], np.r_[0.535])

    yy = interp_membership(x, mfx, np.pi / 3.)
    assert yy == 1

    yy = interp_membership(x, mfx, 2.718)
    assert_allclose(np.r_[yy], np.r_[0.641])
コード例 #3
0
ファイル: test_fuzzy_ops.py プロジェクト: fmmb/scikit-fuzzy
def test_interp_membership():
    x = np.r_[0:4.1:0.1]
    mfx = trapmf(x, [0, 1, 2, 4])

    yy = interp_membership(x, mfx, 0)
    assert yy == 0

    yy = interp_membership(x, mfx, 0.535)
    assert_allclose(np.r_[yy], np.r_[0.535])

    yy = interp_membership(x, mfx, np.pi / 3.)
    assert yy == 1

    yy = interp_membership(x, mfx, 2.718)
    assert_allclose(np.r_[yy], np.r_[0.641])
コード例 #4
0
def test_interp_universe():
    x = np.r_[0:4.1:0.1]
    mfx = trapmf(x, [0, 1, 2, 4])

    xx = interp_universe(x, mfx, 0.5)
    assert_allclose(xx, [0.5, 3])

    xx = interp_universe(x, mfx, 0.0)
    assert_allclose(xx, [0, 4])

    xx = interp_universe(x, mfx, 1.5)
    assert len(xx) == 0

    xx = interp_universe(x, mfx, 0.3)
    y = [interp_membership(x, mfx, value) for value in xx]
    assert_allclose(y, 0.3)