1import numpy as np
2from numpy.testing import assert_allclose, assert_array_equal, TestCase
3from random import randint
4from skfuzzy.membership import trapmf
5from skfuzzy.fuzzymath import (cartadd, cartprod, classic_relation, contrast,
6                               interp10, maxmin_composition,
7                               maxprod_composition, interp_membership,
8                               interp_universe, relation_min, relation_product,
9                               fuzzy_add, fuzzy_sub, fuzzy_min, fuzzy_mult,
10                               fuzzy_div, fuzzy_compare, inner_product,
11                               modus_ponens, outer_product, fuzzy_similarity,
12                               sigmoid, partial_dmf)
13
14
15def test_cartadd():
16    a = np.r_[0, 0, 0, 0.3, 0.7, 1, 0.9, 0]
17    b = np.r_[0, 0, 1, 0.2, 0.1, 0, 0]
18    z = cartadd(a, b)
19
20    expected = np.r_[[[0. ,  0. ,  1. ,  0.2,  0.1,  0. ,  0. ],
21                      [0. ,  0. ,  1. ,  0.2,  0.1,  0. ,  0. ],
22                      [0. ,  0. ,  1. ,  0.2,  0.1,  0. ,  0. ],
23                      [0.3,  0.3,  1.3,  0.5,  0.4,  0.3,  0.3],
24                      [0.7,  0.7,  1.7,  0.9,  0.8,  0.7,  0.7],
25                      [1. ,  1. ,  2. ,  1.2,  1.1,  1. ,  1. ],
26                      [0.9,  0.9,  1.9,  1.1,  1. ,  0.9,  0.9],
27                      [0. ,  0. ,  1. ,  0.2,  0.1,  0. ,  0. ]]]
28
29    assert_allclose(z, expected)
30
31
32def test_cartprod():
33    a = np.r_[0, 0, 0, 0.3, 0.7, 1, 0.9, 0]
34    b = np.r_[0, 0, 1, 0.2, 0.1, 0, 0]
35    z = cartprod(a, b)
36
37    expected = np.r_[[[0.,  0.,  0. ,  0. ,  0. ,  0.,  0.],
38                      [0.,  0.,  0. ,  0. ,  0. ,  0.,  0.],
39                      [0.,  0.,  0. ,  0. ,  0. ,  0.,  0.],
40                      [0.,  0.,  0.3,  0.2,  0.1,  0.,  0.],
41                      [0.,  0.,  0.7,  0.2,  0.1,  0.,  0.],
42                      [0.,  0.,  1. ,  0.2,  0.1,  0.,  0.],
43                      [0.,  0.,  0.9,  0.2,  0.1,  0.,  0.],
44                      [0.,  0.,  0. ,  0. ,  0. ,  0.,  0.]]]
45
46    assert_allclose(z, expected)
47
48
49def test_classic_relation():
50    a = np.r_[0, 0, 0, 0.3, 0.7, 1, 0.9, 0]
51    b = np.r_[0, 0, 1, 0.2, 0.1, 0, 0]
52    z = classic_relation(a, b)
53
54    expected = np.r_[[[1. ,  1. ,  1. ,  1. ,  1. ,  1. ,  1. ],
55                      [1. ,  1. ,  1. ,  1. ,  1. ,  1. ,  1. ],
56                      [1. ,  1. ,  1. ,  1. ,  1. ,  1. ,  1. ],
57                      [0.7,  0.7,  0.7,  0.7,  0.7,  0.7,  0.7],
58                      [0.3,  0.3,  0.7,  0.3,  0.3,  0.3,  0.3],
59                      [0. ,  0. ,  1. ,  0.2,  0.1,  0. ,  0. ],
60                      [0.1,  0.1,  0.9,  0.2,  0.1,  0.1,  0.1],
61                      [1. ,  1. ,  1. ,  1. ,  1. ,  1. ,  1. ]]]
62
63    assert_allclose(z, expected)
64
65
66class TestContrast(TestCase):
67    def test_trivial_curves(self):
68        im = np.r_[[[0, 3, 4, 6, 1],
69                    [3, 6, 1, 1, 8],
70                    [4, 2, 6, 0, 7],
71                    [5, 5, 9, 0, 2]]]
72        test = contrast(im, 0.5)
73        assert_array_equal(test, contrast(im, (0.5, 0.5)))
74
75        expected = np.array(
76            [[0.        , 0.40824829, 0.47140452, 0.59175171, 0.23570226],
77             [0.40824829, 0.59175171, 0.23570226, 0.23570226, 0.76429774],
78             [0.47140452, 0.33333333, 0.59175171, 0.        , 0.66666667],
79             [0.52859548, 0.52859548, 1.        , 0.        , 0.33333333]])
80
81        assert_allclose(test, expected * 9)
82
83    def test_contrast(self):
84        a = np.r_[0, 0, 0, 0.3, 0.7, 1, 0.9, 0]
85        z = contrast(a, 1.8)
86
87        # Legacy slower code which should produce identical result
88        p = 1.8
89        m = 0.5
90        ymin = np.fmin(a, m)
91        ymax = np.fmax(a, m)
92        w = np.arange(len(a))
93        wmax = w[ymax > m]
94        wmin = w[ymax <= m]
95        ymin = 2 ** (p - 1) * ymin ** p
96        ymax = 1 - 2 ** (p - 1) * (1 - ymax) ** p
97        ymin[wmax] = 0
98        ymax[wmin] = 0
99
100        assert_allclose(z, ymin + ymax)
101
102        # Legacy slower code which should produce identical result
103        p = 0.5
104        m = 0.5
105        z = contrast(a, 0.5)
106        ymin = np.fmin(a, m)
107        ymax = np.fmax(a, m)
108        w = np.arange(len(a))
109        wmax = w[ymax > m]
110        wmin = w[ymax <= m]
111        ymin = 2 ** (p - 1) * ymin ** p
112        ymax = 1 - 2 ** (p - 1) * (1 - ymax) ** p
113        ymin[wmax] = 0
114        ymax[wmin] = 0
115
116        assert_allclose(z, ymin + ymax)
117
118        # Legacy slower code which should produce identical result
119        p = 2.
120        m = 0.5
121        z = contrast(a, 2.)
122        ymin = np.fmin(a, m)
123        ymax = np.fmax(a, m)
124        w = np.arange(len(a))
125        wmax = w[ymax > m]
126        wmin = w[ymax <= m]
127        ymin = 2 ** (p - 1) * ymin ** p
128        ymax = 1 - 2 ** (p - 1) * (1 - ymax) ** p
129        ymin[wmax] = 0
130        ymax[wmin] = 0
131
132        assert_allclose(z, ymin + ymax)
133
134    def test_contrast_offcenter(self):
135        a = np.r_[0, 0, 0, 0.3, 0.7, 1, 0.9, 0]
136        z = contrast(a, 1.8, 0.75)
137
138        expected = np.r_[0, 0, 0, 0.14413493, 0.66241089, 1, 0.95195502, 0]
139
140        assert_allclose(z, expected)
141
142
143def test_fuzzy_add():
144    x = np.r_[0:8]
145    A = np.r_[0, .3, .6, .8, 1, .7, .2, 0]
146    B = np.r_[0,  1, .9, .5, .2, .1, 0, 0]
147
148    test_u, test_mf = fuzzy_add(x ** 2, A, x ** 2, B)
149    expected_u = np.r_[0., 1., 2., 4., 5., 8., 9., 10., 13., 16., 17., 18.,
150                       20., 25., 26., 29., 32., 34., 36., 37., 40., 41., 45.,
151                       49., 50., 52., 53., 58., 61., 65., 72., 74., 85., 98.]
152    expected_mf = np.r_[0., 0., 0.3, 0., 0.6, 0.6, 0., 0.8, 0.8, 0., 1., 0.5,
153                        0.9, 0.5, 0.7, 0.7, 0.2, 0.5, 0., 0.2, 0.2, 0.2, 0.2,
154                        0., 0.1, 0.2, 0., 0., 0.1, 0., 0., 0., 0., 0.]
155    assert_allclose(test_u, expected_u)
156    assert_allclose(test_mf, expected_mf)
157
158
159def test_fuzzy_compare():
160    pair = np.r_[[[1, 0.6, 0.7, 0.5],
161                  [0.2, 1, 0.8, 0.6],
162                  [0.3, 0.2, 1, 0.4],
163                  [0.9, 0.5, 0.8, 1]]]
164
165    test = fuzzy_compare(pair)
166    expected = np.r_[[[63., 21., 27.  , 63. ],
167                      [63., 63., 15.75, 52.5],
168                      [63., 63., 63.  , 63. ],
169                      [35., 63., 31.5 , 63. ]]] / 63.
170    assert_allclose(test, expected)
171
172
173def test_fuzzy_sub():
174    x = np.r_[0:8]
175    A = np.r_[0, .3, .6, .8, 1, .7, .2, 0]
176
177    test_u, test_mf = fuzzy_sub(x, A, x, A)
178
179    expected_u = np.r_[-7., -6., -5., -4., -3., -2., -1., 0., 1., 2., 3., 4.,
180                       5., 6., 7.]
181    expected_mf = np.r_[0., 0., 0.2, 0.3, 0.6, 0.7, 0.8, 1., 0.8, 0.7, 0.6,
182                        0.3, 0.2, 0., 0.]
183    assert_allclose(test_u, expected_u)
184    assert_allclose(test_mf, expected_mf)
185
186
187def test_fuzzy_min():
188    x = np.r_[0:8]
189    A = np.r_[0, .3, .6, .8, 1, .7, .2, 0]
190    B = np.r_[0,  1, .9, .5, .2, .1, 0, 0]
191
192    testu_, test_mf = fuzzy_min(x, A, x, B)
193
194    expected_u = np.r_[0., 1., 2., 3., 4., 5., 6., 7.]
195    expected_mf = np.r_[0., 1., 0.9, 0.5, 0.2, 0.1, 0., 0.]
196    assert_allclose(testu_, expected_u)
197    assert_allclose(test_mf, expected_mf)
198
199
200def test_fuzzy_mult():
201    vol  = np.r_[.5, .75, 1, 1.25, 1.5]
202    V    = np.r_[0, .5, 1, .5, 0]
203    pa   = np.r_[.5, 1.75, 2, 2.25, 2.5]
204    P    = V.copy()
205
206    test_u, test_mf = fuzzy_mult(pa, P, vol, V)
207    expected_u = np.r_[0.25, 0.375, 0.5,0.625, 0.75, 0.875, 1., 1.125, 1.25,
208                       1.3125, 1.5,1.6875, 1.75, 1.875, 2., 2.1875, 2.25, 2.5,
209                       2.625, 2.8125, 3., 3.125, 3.375, 3.75]
210    expected_mf = np.r_[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.5, 0.5, 0.5,
211                        0.5, 0., 1., 0.5, 0.5, 0.5, 0., 0.5, 0., 0., 0., 0.]
212    assert_allclose(test_u, expected_u)
213    assert_allclose(test_mf, expected_mf)
214
215
216def test_fuzzy_div():
217    vol  = np.r_[.5, .75, 1, 1.25, 1.5]
218    V    = np.r_[0, .5, 1, .5, 0]
219    pa   = np.r_[.5, 1.75, 2, 2.25, 2.5]
220    P    = V.copy()
221
222    test_u, test_mf = fuzzy_div(pa, P, vol, V)
223    expected_u = np.r_[2., 2.4, 3., 4., 6., 7., 8., 8.4, 9., 9.6, 10., 10.5,
224                       10.8, 12., 13.5, 14., 15., 16., 18., 20., 21., 24.,
225                       27., 30.] / 6.
226    expected_mf = np.r_[0., 0., 0., 0., 0., 0., 0., 0.5, 0., 0.5, 0., 0.5,
227                        0.5, 1., 0.5, 0.5, 0., 0.5, 0.5, 0., 0., 0., 0., 0.]
228    assert_allclose(test_u, expected_u)
229    assert_allclose(test_mf, expected_mf)
230
231
232def test_inner_product():
233    A = [0.3, 0.2, 0.1, 0, 0.7, 0.9, 1]
234    B = [0.5, 0.5, 0.6, 0.4, 0.6, 0.3, 0.2]
235    c = inner_product(A, B)
236    assert_allclose(np.r_[c], np.r_[0.6])
237    c = inner_product(np.asarray(A), np.asarray(B))
238    assert_allclose(np.r_[c], np.r_[0.6])
239
240
241def test_interp10():
242    x = np.r_[0, 1, 0.5, 0.25]
243    z = interp10(x)
244    expected = np.r_[0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.,
245        0.95, 0.9, 0.85, 0.8, 0.75, 0.7, 0.65, 0.6, 0.55, 0.5, 0.475,
246        0.45, 0.425, 0.4, 0.375,  0.35, 0.325,  0.3, 0.275,  0.25]
247
248    # ~1e-16 float errors from interpolation
249    assert_allclose(z, expected)
250
251
252def test_maxmin_composition():
253    mfI = np.r_[0.4, 0.7, 1.0, 0.8, 0.6]
254    mfV = np.r_[0.2, 0.6, 1.0, 0.9, 0.7]
255    mfC = np.r_[0.4, 1.0, 0.8]
256
257    P = cartprod(mfV, mfI)
258    S = cartprod(mfI, mfC)
259
260    test = maxmin_composition(P, S)
261    expected = np.r_[[[0.2,  0.2,  0.2],
262                      [0.4,  0.6,  0.6],
263                      [0.4,  1. ,  0.8],
264                      [0.4,  0.9,  0.8],
265                      [0.4,  0.7,  0.7]]]
266    assert_allclose(test, expected)
267
268    A = np.r_[0.3, 0.2, 0.1, 0, 0.7, 0.9, 1]
269    B = np.r_[0.5, 0.5, 0.6, 0.4, 0.6, 0.3, 0.2]
270    c = maxmin_composition(A, B)
271    assert (1, 1) == c.shape
272    assert_allclose(c, np.r_[[[0.6]]])
273
274
275def test_maxprod_composition():
276    mfI = np.r_[0.4, 0.7, 1.0, 0.8, 0.6]
277    mfV = np.r_[0.2, 0.6, 1.0, 0.9, 0.7]
278    mfC = np.r_[0.4, 1.0, 0.8]
279
280    P = cartprod(mfV, mfI)
281    S = cartprod(mfI, mfC)
282
283    test = maxprod_composition(P, S)
284    expected = np.r_[[[0.08,  0.2 ,  0.16],
285                      [0.24,  0.6 ,  0.48],
286                      [0.4 ,  1.  ,  0.8 ],
287                      [0.36,  0.9 ,  0.72],
288                      [0.28,  0.7 ,  0.56]]]
289    assert_allclose(test, expected)
290
291    A = np.r_[0.3, 0.2, 0.1, 0, 0.7, 0.9, 1]
292    B = np.r_[0.5, 0.5, 0.6, 0.4, 0.6, 0.3, 0.2]
293    c = maxprod_composition(A, B)
294    assert (1, 1) == c.shape
295    assert_allclose(c, np.r_[[[0.42]]])
296
297
298def test_interp_membership():
299    x = np.r_[0:4.1:0.1]
300    mfx = trapmf(x, [0, 1, 2, 4])
301
302    yy = interp_membership(x, mfx, 0)
303    assert yy == 0
304
305    yy = interp_membership(x, mfx, 0.535)
306    assert_allclose(np.r_[yy], np.r_[0.535])
307
308    yy = interp_membership(x, mfx, np.pi / 3.)
309    assert yy == 1
310
311    yy = interp_membership(x, mfx, 2.718)
312    assert_allclose(np.r_[yy], np.r_[0.641])
313
314    assert_allclose(interp_membership(x, mfx, [0.2, 2.73, 3.14]),
315                    np.asarray([interp_membership(x, mfx, i)
316                                for i in [0.2, 2.73, 3.14]]))
317
318    mfx[-1] = 0.7
319    mfx[0] = 0.2
320    assert_allclose([0, 0], interp_membership(x, mfx, [-11, 5]))
321    assert_allclose([0.2, 0.7], interp_membership(x, mfx, [-11, 5],
322                                                  False))
323
324
325def test_interp_universe():
326    x = np.r_[0:4.1:0.1]
327    mfx = trapmf(x, [0, 1, 2, 4])
328
329    xx = interp_universe(x, mfx, 0.5)
330    assert_allclose(xx, [0.5, 3])
331
332    xx = interp_universe(x, mfx, 0.0)
333    assert_allclose(xx, [0, 4])
334
335    xx = interp_universe(x, mfx, 1.5)
336    assert len(xx) == 0
337
338    xx = interp_universe(x, mfx, 0.3)
339    y = [interp_membership(x, mfx, value) for value in xx]
340    assert_allclose(y, 0.3)
341
342def test_modus_ponens():
343    A = np.r_[0, 0.6, 1, 0.2]
344    B = np.r_[0, 0.4, 1, 0.8, 0.3, 0]
345    C = np.r_[0.3, 0.5, 0.6, 0.6, 0.5, 0.3]
346    Aprime = np.r_[0.5, 1, 0.3, 0]
347
348    R_expected = np.r_[[[  1,   1,   1,   1,   1,   1],
349                        [0.4, 0.4, 0.6, 0.6, 0.4, 0.4],
350                        [  0,  0.4,   1, 0.8, 0.3,  0],
351                        [0.8, 0.8, 0.8, 0.8, 0.8, 0.8]]]
352    Bprime_expected = np.r_[0.5, 0.5, 0.6, 0.6, 0.5, 0.5]
353
354    R, Bprime = modus_ponens(A, B, Aprime)
355    assert_allclose(R, R_expected)
356    assert_allclose(Bprime, Bprime_expected)
357
358    R_expected = np.r_[[[ 0.3,  0.5,  0.6,  0.6,  0.5,  0.3],
359                        [ 0.3,  0.4,  0.6,  0.6,  0.4,  0.3],
360                        [ 0. ,  0.4,  1. ,  0.8,  0.3,  0. ],
361                        [ 0.3,  0.5,  0.6,  0.6,  0.5,  0.3]]]
362    Bprime_expected = np.r_[ 0.3,  0.5,  0.6,  0.6,  0.5,  0.3]
363
364    R, Bprime = modus_ponens(A, B, Aprime, C)
365    assert_allclose(R, R_expected)
366    assert_allclose(Bprime, Bprime_expected)
367
368
369def test_outer_product():
370    A = [0.3, 0.2, 0.1, 0, 0.7, 0.9, 1]
371    B = [0.5, 0.5, 0.6, 0.4, 0.6, 0.3, 0.2]
372    c = outer_product(A, B)
373    assert_allclose(np.r_[c], np.r_[0.4])
374    c = outer_product(np.asarray(A), np.asarray(B))
375    assert_allclose(np.r_[c], np.r_[0.4])
376
377
378def test_relation_min():
379    A = np.r_[0, 0, 0, 0, 0.5, 1, 0.5, 0, 0, 0, 0]  # Fuzzy zero
380    B = np.r_[0, 0, 0, 0, 0, 0, 0.6, 1, 0.6, 0, 0]  # Fuzzy +2
381
382    mamdani = relation_min(A, B)
383    expected = np.r_[[[0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
384                      [0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
385                      [0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
386                      [0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
387                      [0.,  0.,  0.,  0.,  0.,  0.,  0.5, 0.5, 0.5, 0.,  0.],
388                      [0.,  0.,  0.,  0.,  0.,  0.,  0.6, 1.,  0.6, 0.,  0.],
389                      [0.,  0.,  0.,  0.,  0.,  0.,  0.5, 0.5, 0.5, 0.,  0.],
390                      [0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
391                      [0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
392                      [0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
393                      [0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.]]]
394
395    assert_allclose(mamdani, expected)
396
397
398def test_relation_product():
399    A = np.r_[0, 0, 0, 0, 0.5, 1, 0.5, 0, 0, 0, 0]  # Fuzzy zero
400    B = np.r_[0, 0, 0, 0, 0, 0, 0.6, 1, 0.6, 0, 0]  # Fuzzy +2
401
402    product = relation_product(A, B)
403    expected = np.r_[[[0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
404                      [0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
405                      [0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
406                      [0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
407                      [0.,  0.,  0.,  0.,  0.,  0.,  0.3, 0.5, 0.3, 0.,  0.],
408                      [0.,  0.,  0.,  0.,  0.,  0.,  0.6, 1.,  0.6, 0.,  0.],
409                      [0.,  0.,  0.,  0.,  0.,  0.,  0.3, 0.5, 0.3, 0.,  0.],
410                      [0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
411                      [0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
412                      [0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
413                      [0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.]]]
414
415    assert_allclose(product, expected)
416
417
418def test_fuzzy_similarity():
419    A = [0.3, 0.2, 0.1, 0, 0.7, 0.9, 1]
420    B = [0.5, 0.5, 0.6, 0.4, 0.6, 0.3, 0.2]
421    c = fuzzy_similarity(A, B)
422    assert_allclose(np.r_[c], np.r_[0.6])
423    c = fuzzy_similarity(A, B, mode='avg')
424    assert_allclose(np.r_[c], np.r_[0.6])
425
426
427def test_sigmoid():
428    a = np.arange(30) / 29.
429    expected = np.array(
430      [ 0.4378235 ,  0.44207164,  0.44632827,  0.45059279,  0.45486458,
431        0.45914303,  0.4634275 ,  0.46771738,  0.47201205,  0.47631085,
432        0.48061317,  0.48491837,  0.48922581,  0.49353484,  0.49784484,
433        0.50215516,  0.50646516,  0.51077419,  0.51508163,  0.51938683,
434        0.52368915,  0.52798795,  0.53228262,  0.5365725 ,  0.54085697,
435        0.54513542,  0.54940721,  0.55367173,  0.55792836,  0.5621765 ])
436
437    test = sigmoid(a, 0.5)
438    assert_allclose(test, expected)
439
440
441def test_partial_dmf_gauss():
442    name = 'gaussmf'
443    mean = -1.5
444    sigma = 0.75
445    gaussmf_param_dict = {'mean': mean,
446                          'sigma': sigma}
447    test_int = randint(1, 3)
448
449    gaussmf_results = [partial_dmf(-1.5, name, gaussmf_param_dict, 'mean'),
450                       partial_dmf(-1.5, name, gaussmf_param_dict, 'sigma'),
451                       partial_dmf(-1.5, name, {'mean': mean, 'sigma': test_int * sigma}, 'mean') ==
452                       -partial_dmf(-1.5, name, {'mean': mean, 'sigma': -test_int * sigma}, 'mean')]
453    gaussmf_expected = [0., 0., True]
454    assert_allclose(gaussmf_results, gaussmf_expected)
455
456
457def test_partial_dmf_gbell():
458    name = 'gbellmf'
459    a = 2.
460    b = 1.
461    c = 0.5
462    gbellmf_param_dict = {'a': a, 'b': b, 'c': c}
463
464    gbellmf_results = [partial_dmf(-1.5, name, gbellmf_param_dict, 'a'),
465                       partial_dmf(2.5, name, gbellmf_param_dict, 'a'),
466                       partial_dmf(-1.5, name, gbellmf_param_dict, 'b'),
467                       partial_dmf(2.5, name, gbellmf_param_dict, 'b'),
468                       partial_dmf(-1.5, name, gbellmf_param_dict, 'c'),
469                       partial_dmf(2.5, name, gbellmf_param_dict, 'c')
470                       ]
471    gbellmf_expected = [0.25, 0.25, -0.0, -0.0, -0.25, 0.25]
472    assert_allclose(gbellmf_results, gbellmf_expected)
473
474
475def test_partial_dmf_sigmoid():
476    name = 'sigmf'
477    b_one = 1.0
478    c_one = 3.0
479    b_two = -1.0
480    c_two = 0.5
481    sigmf_param_dict_one = {'b': b_one, 'c': c_one}
482    sigmf_param_dict_two = {'b': b_two, 'c': c_two}
483
484    sigmf_results = [partial_dmf(1.0, name, sigmf_param_dict_one, 'b'),
485                     partial_dmf(-1.0, name, sigmf_param_dict_two, 'b'),
486                     partial_dmf(1.0, name, sigmf_param_dict_one, 'c'),
487                     partial_dmf(-1.0, name, sigmf_param_dict_two, 'c')
488                     ]
489    sigmf_expected = [-0.75, -0.125, 0., 0.]
490    assert_allclose(sigmf_results, sigmf_expected)
491
492
493if __name__ == "__main__":
494    np.testing.run_module_suite()
495