-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWashing_Machine.m
149 lines (117 loc) · 4.52 KB
/
Washing_Machine.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
% Fuzzified Washing Machine
% doc fuzzy for more information
clear
clc
close all
%% Constructing FIS and defineing properties
wm = mamfis(); % creating mamdani FIS (class constructor)
wm.Name = 'Fuzzified Washing Machine'; % system name
wm.AndMethod = 'min'; % min or prod
wm.OrMethod = 'max'; % max or probor
wm.ImplicationMethod = 'min'; % min or prod
wm.AggregationMethod = 'max'; % max or sum
wm.DefuzzificationMethod = 'centroid'; % centroid or bisector or mom or
% lom or som
%% Adding inputs
wm = wm.addInput(); % adding inputs
wm.Inputs(1).Name = 'TOD'; % input name
wm.Inputs(1).Range = [0, 100]; % input range
wm.Inputs(2).Name = 'DOC';
wm.Inputs(2).Range = [0, 100];
wm.Inputs(3).Name = 'MOC';
wm.Inputs(3).Range = [0, 100];
%% Adding Output
wm = wm.addOutput(); % adding output
wm.Outputs(1).Name = 'SpinP'; % output name
wm.Outputs(1).Range = [0, 60]; % output range
%% Adding input membership functions
wm = wm.addMF('TOD', 'trimf', [0, 0, 50], 'name', 'NotGreasy'); % adding
% membership functions to inputs
wm = wm.addMF('TOD', 'trimf', [10, 50, 90], 'name', 'Medium');
wm = wm.addMF('TOD', 'trimf', [50, 100, 100], 'name', 'Greasy');
wm = wm.addMF('DOC', 'trimf', [0, 0, 50], 'name', 'Small');
wm = wm.addMF('DOC', 'trimf', [10, 50, 90], 'name', 'Medium');
wm = wm.addMF('DOC', 'trimf', [50, 100, 100], 'name', 'Large');
wm = wm.addMF('MOC', 'trimf', [0, 0, 50], 'name', 'Light');
wm = wm.addMF('MOC', 'trimf', [10, 50, 90], 'name', 'Medium');
wm = wm.addMF('MOC', 'trimf', [50, 100, 100], 'name', 'Heavy');
%% Adding output membership functions
wm.Outputs(1).MembershipFunction(1).Name = 'VeryShort';
wm.Outputs(1).MembershipFunction(1).Type = 'trimf';
wm.Outputs(1).MembershipFunction(1).Parameters = [-14, 6, 23];
wm.Outputs(1).MembershipFunction(2).Name = 'Short';
wm.Outputs(1).MembershipFunction(2).Type = 'trimf';
wm.Outputs(1).MembershipFunction(2).Parameters = [0, 14, 41];
wm.Outputs(1).MembershipFunction(3).Name = 'Medium';
wm.Outputs(1).MembershipFunction(3).Type = 'trimf';
wm.Outputs(1).MembershipFunction(3).Parameters = [11, 30, 45];
wm.Outputs(1).MembershipFunction(4).Name = 'Long';
wm.Outputs(1).MembershipFunction(4).Type = 'trimf';
wm.Outputs(1).MembershipFunction(4).Parameters = [23, 45, 60];
wm.Outputs(1).MembershipFunction(5).Name = 'VeryLong';
wm.Outputs(1).MembershipFunction(5).Type = 'trimf';
wm.Outputs(1).MembershipFunction(5).Parameters = [39, 58, 75];
%% Defineing Rules
R = cell(1, 27); % preallocation for speed
Spin_Period = {'VeryShort', 'Short', 'Medium', 'Medium', 'Medium', 'Long', ...
'Medium', 'Medium', 'Long', 'Short', 'Medium', 'Long', 'Medium', ...
'Long', 'Long', 'Short', 'Long', 'Long', 'Short', 'Medium', 'Long', ...
'Medium', 'Long', 'VeryLong', 'Medium', 'Long', 'VeryLong'};
c = 0; % counter
for i = {'NotGreasy', 'Medium', 'Greasy'}
for j = {'Small', 'Medium', 'Large'}
for k = {'Light', 'Medium', 'Heavy'}
c = c + 1;
R{c} = ['If TOD is ' char(i) ' and DOC is ' char(j) ...
' and MOC is ' char(k) ' then SpinP is ' ...
Spin_Period{c}]; % rules
disp(['Rule ' num2str(c) ': If Type of Dirt is ' char(i) ...
' and Dirtiness of Cloth is ' char(j) ...
' and Mass of Clothes is ' ...
char(k) ' then Spin Period is ' Spin_Period{c}])
disp(newline)
wm = wm.addRule(R{c});
end
end
end
%% Evaluation
ruleview(wm) % showing rules and changing inputs
plotfis(wm) % plotting Fuzzified Washing Machine system
surfview(wm) % plotting FIS surface
figure('name', 'Membership Functions')
subplot(2, 2, 1)
plotmf(wm, 'input', 1)
title('Input(1): Type of Dirt');
subplot(2, 2, 2)
plotmf(wm, 'input', 2)
title('Input(2): Dirtiness of Cloth');
subplot(2, 2, 3)
plotmf(wm, 'input', 3)
title('Input(3): Mass of Clothes');
subplot(2, 2, 4)
plotmf (wm, 'output', 1)
title('Output(1): Spin Period');
n = 10;
A = (0 : n : 100).';
sz = size(A, 1);
In3 = repmat(A, sz^2, 1);
in2 = cell(sz, 1);
in1 = cell(sz, 1);
c=0;
for i = A.'
c = c + 1;
in2{c} = i * ones(sz, 1);
in1{c} = i * ones(sz^2, 1);
end
In2 = [in2{:}];
In2 = repmat(In2(:), sz, 1);
In1 = [in1{:}];
In1 = In1(:);
Out = evalfis(wm, [In1, In2, In3]);
figure
scatter3(In1, In2, In3, 70, Out, 'filled')
colorbar
colormap jet
xlabel('Type of Dirt');
ylabel('Dirtiness of Cloth');
zlabel('Mass of Clothes');