Skip to content

Commit a7f3851

Browse files
jpg-130cclauss
authored andcommitted
fuzzy operations added (#1310)
* fuzzy operations added * fuzzy inference system added * unnecessary files removed * requirements added * Modified requirements for travis ci * Modified requirements for travis ci * Add scikit-fuzzy to requirements.txt
1 parent 4590363 commit a7f3851

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

fuzzy_logic/fuzzy_operations.py

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
"""README, Author - Jigyasa Gandhi(mailto:[email protected])
2+
Requirements:
3+
- scikit-fuzzy
4+
- numpy
5+
- matplotlib
6+
Python:
7+
- 3.5
8+
"""
9+
# Create universe of discourse in python using linspace ()
10+
import numpy as np
11+
X = np.linspace(start=0, stop=75, num=75, endpoint=True, retstep=False)
12+
13+
# Create two fuzzy sets by defining any membership function (trapmf(), gbellmf(),gaussmf(), etc).
14+
import skfuzzy as fuzz
15+
abc1=[0,25,50]
16+
abc2=[25,50,75]
17+
young = fuzz.membership.trimf(X,abc1)
18+
middle_aged = fuzz.membership.trimf(X,abc2)
19+
20+
# Compute the different operations using inbuilt functions.
21+
one = np.ones(75)
22+
zero = np.zeros((75,))
23+
#1. Union = max(µA(x), µB(x))
24+
union = fuzz.fuzzy_or(X, young, X, middle_aged)[1]
25+
#2. Intersection = min(µA(x), µB(x))
26+
intersection = fuzz.fuzzy_and(X, young, X, middle_aged)[1]
27+
#3. Complement (A) = (1- min(µA(x))
28+
complement_a = fuzz.fuzzy_not(young)
29+
#4. Difference (A/B) = min(µA(x),(1- µB(x)))
30+
difference = fuzz.fuzzy_and(X, young, X, fuzz.fuzzy_not(middle_aged)[1])[1]
31+
#5. Algebraic Sum = [µA(x) + µB(x) – (µA(x) * µB(x))]
32+
alg_sum = young + middle_aged - (young*middle_aged)
33+
#6. Algebraic Product = (µA(x) * µB(x))
34+
alg_product = young*middle_aged
35+
#7. Bounded Sum = min[1,(µA(x), µB(x))]
36+
bdd_sum = fuzz.fuzzy_and(X, one, X, young+middle_aged)[1]
37+
#8. Bounded difference = min[0,(µA(x), µB(x))]
38+
bdd_difference = fuzz.fuzzy_or(X, zero, X, young-middle_aged)[1]
39+
40+
#max-min composition
41+
#max-product composition
42+
43+
44+
# Plot each set A, set B and each operation result using plot() and subplot().
45+
import matplotlib.pyplot as plt
46+
47+
plt.figure()
48+
49+
plt.subplot(4,3,1)
50+
plt.plot(X,young)
51+
plt.title("Young")
52+
plt.grid(True)
53+
54+
plt.subplot(4,3,2)
55+
plt.plot(X,middle_aged)
56+
plt.title("Middle aged")
57+
plt.grid(True)
58+
59+
plt.subplot(4,3,3)
60+
plt.plot(X,union)
61+
plt.title("union")
62+
plt.grid(True)
63+
64+
plt.subplot(4,3,4)
65+
plt.plot(X,intersection)
66+
plt.title("intersection")
67+
plt.grid(True)
68+
69+
plt.subplot(4,3,5)
70+
plt.plot(X,complement_a)
71+
plt.title("complement_a")
72+
plt.grid(True)
73+
74+
plt.subplot(4,3,6)
75+
plt.plot(X,difference)
76+
plt.title("difference a/b")
77+
plt.grid(True)
78+
79+
plt.subplot(4,3,7)
80+
plt.plot(X,alg_sum)
81+
plt.title("alg_sum")
82+
plt.grid(True)
83+
84+
plt.subplot(4,3,8)
85+
plt.plot(X,alg_product)
86+
plt.title("alg_product")
87+
plt.grid(True)
88+
89+
plt.subplot(4,3,9)
90+
plt.plot(X,bdd_sum)
91+
plt.title("bdd_sum")
92+
plt.grid(True)
93+
94+
plt.subplot(4,3,10)
95+
plt.plot(X,bdd_difference)
96+
plt.title("bdd_difference")
97+
plt.grid(True)
98+
99+
plt.subplots_adjust(hspace = 0.5)
100+
plt.show()

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pandas
88
pillow
99
pytest
1010
requests
11+
scikit-fuzzy
1112
sklearn
1213
sympy
1314
tensorflow

0 commit comments

Comments
 (0)