4 base
= os
.path
.dirname(__file__
)
5 path
= os
.path
.dirname(base
)
6 path
= os
.path
.dirname(path
)
7 sys
.path
.insert(0, path
)
10 import matplotlib
.pyplot
as plt
11 except Exception as e
:
15 import liba
# type: ignore
17 title
= "Gaussian membership function"
18 x
= np
.arange(-3, 3, 0.001)
19 y
= liba
.mf
.gauss(x
, 1, 0)
24 plt
.savefig(os
.path
.join(base
, "mf_gauss.png"))
26 title
= "Gaussian combination membership function"
27 x
= np
.arange(-3, 3, 0.001)
28 y
= liba
.mf
.gauss2(x
, 1, -1, 1, +1)
33 plt
.savefig(os
.path
.join(base
, "mf_gauss2.png"))
35 title
= "Generalized bell-shaped membership function"
36 x
= np
.arange(-3, 3, 0.001)
37 y
= liba
.mf
.gbell(x
, 2, 4, 0)
42 plt
.savefig(os
.path
.join(base
, "mf_gbell.png"))
44 title
= "Sigmoidal membership function"
45 x
= np
.arange(-3, 3, 0.001)
46 y
= liba
.mf
.sig(x
, 2, 0)
51 plt
.savefig(os
.path
.join(base
, "mf_sig.png"))
53 title
= "Difference between two sigmoidal membership functions"
54 x
= np
.arange(-3, 3, 0.001)
55 y
= liba
.mf
.dsig(x
, 5, -2, +5, 2)
60 plt
.savefig(os
.path
.join(base
, "mf_dsig.png"))
62 title
= "Product of two sigmoidal membership functions"
63 x
= np
.arange(-3, 3, 0.001)
64 y
= liba
.mf
.psig(x
, 5, -2, -5, 2)
69 plt
.savefig(os
.path
.join(base
, "mf_psig.png"))
71 title
= "Triangular membership function"
72 x
= np
.arange(0, 2, 0.001)
73 y
= liba
.mf
.tri(x
, 0, 1, 2)
78 plt
.savefig(os
.path
.join(base
, "mf_tri.png"))
81 title
= "Trapezoidal membership function"
82 x
= np
.arange(0, 3, 0.001)
83 y
= liba
.mf
.trap(x
, 0, 1, 2, 3)
88 plt
.savefig(os
.path
.join(base
, "mf_trap.png"))
90 title
= "Linear s-shaped saturation membership function"
91 x
= np
.arange(0, 3, 0.001)
92 y
= liba
.mf
.lins(x
, 1, 2)
97 plt
.savefig(os
.path
.join(base
, "mf_lins.png"))
99 title
= "Linear z-shaped saturation membership function"
100 x
= np
.arange(0, 3, 0.001)
101 y
= liba
.mf
.linz(x
, 1, 2)
106 plt
.savefig(os
.path
.join(base
, "mf_linz.png"))
108 title
= "S-shaped membership function"
109 x
= np
.arange(0, 3, 0.001)
110 y
= liba
.mf
.s(x
, 1, 2)
115 plt
.savefig(os
.path
.join(base
, "mf_s.png"))
117 title
= "Z-shaped membership function"
118 x
= np
.arange(0, 3, 0.001)
119 y
= liba
.mf
.z(x
, 1, 2)
124 plt
.savefig(os
.path
.join(base
, "mf_z.png"))
127 title
= "Pi-shaped membership function"
128 x
= np
.arange(0, 3, 0.001)
129 y
= liba
.mf
.pi(x
, 0, 1, 2, 3)
134 plt
.savefig(os
.path
.join(base
, "mf_pi.png"))
138 (liba
.mf
.TRI
, -3 * S
, -3 * S
, -2 * S
),
139 (liba
.mf
.TRI
, -3 * S
, -2 * S
, -1 * S
),
140 (liba
.mf
.TRI
, -2 * S
, -1 * S
, +0 * S
),
141 (liba
.mf
.TRI
, -1 * S
, +0 * S
, +1 * S
),
142 (liba
.mf
.TRI
, +0 * S
, +1 * S
, +2 * S
),
143 (liba
.mf
.TRI
, +1 * S
, +2 * S
, +3 * S
),
144 (liba
.mf
.TRI
, +2 * S
, +3 * S
, +3 * S
),
147 title
= "membership function"
148 x
= np
.arange(-3 * S
, +3 * S
, 0.001)
152 plt
.plot(x
, liba
.mf()(param
[0], x
, param
[1:]))
153 plt
.savefig(os
.path
.join(base
, "mf.png"))