-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathANFIS_Construct.m
108 lines (81 loc) · 2.79 KB
/
ANFIS_Construct.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
% Clear environment variables
clc;
clear;
close all;
%% Data Preprocessing
% Read data
data = xlsread('ANFIS_WO_sync8.csv');
% Extract columns
rho = data(:, 1);
omega = data(:, 2);
% Calculate statistical values
rho_min = min(rho);
rho_max = max(rho);
rho_mean = mean(rho);
rho_std = std(rho);
omega_min = min(omega);
omega_max = max(omega);
omega_mean = mean(omega);
omega_std = std(omega);
% Set data for Am1-Am6
Am1 = rho_max;
Am2 = rho_max;
Am3 = rho_min;
Am4 = rho_min;
Am5 = omega_min;
Am6 = omega_max;
Am7 = omega_min;
Am8 = omega_max;
%% Create Fuzzy Inference System
% Initialize Fuzzy Inference System
% fis = newfis('ANFIS-WO', 'sugeno', 'min', 'max', 'prod', 'sum', 'wtaver');
fis = newfis('ANFIS-WO', 'mamdani', 'min', 'max', 'min', 'max', 'centroid');
% Add Input Variable p And Custom Membership Function A1-A4
fis = addvar(fis, 'input', 'p', [-25 25]);
fis = addmf(fis, 'input', 1, 'A1', 'smf', [1, Am1]);
fis = addmf(fis, 'input', 1, 'A2', 'custmf2', [1, Am2]);
fis = addmf(fis, 'input', 1, 'A3', 'custmf3', [Am3, 1]);
fis = addmf(fis, 'input', 1, 'A4', 'zmf', [Am4, -1]);
% Add Another Input Variable w And Custom Membership Function A5-A6
fis = addvar(fis, 'input', 'w', [-0.6 0.6]);
fis = addmf(fis, 'input', 2, 'A5', 'zmf', [Am5 Am6]);
fis = addmf(fis, 'input', 2, 'A6', 'smf', [Am7 Am8]);
% Add Output Variable for Wheel Odometry Variance
<<<<<<< HEAD
fis = addvar(fis, 'output', 'Q1Variance', [0 1]);
fis = addmf(fis, 'output', 1, 'HighVariance', 'trimf', [0.33, 0.66, 1]);
fis = addmf(fis, 'output', 1, 'LowVariance', 'trimf', [0, 0.33, 0.66]);
=======
fis = addvar(fis, 'output', 'WOVariance', [0 1]);
fis = addmf(fis, 'output', 1, 'HighVariance', 'trimf', [1/3, 2/3, 1]);
fis = addmf(fis, 'output', 1, 'LowVariance', 'trimf', [0, 1/3, 2/3]);
>>>>>>> 0f6e2f2894f2741dc9b5fb26a7c8f1c98bbb25ea
% Define rules
rules = [
% Rule format: [input1_mf input2_mf output_mf weight operator]
% Operator 1 for AND which uses min
1 2 1 1 1; % min(A1(p), A2(w)) -> High Variance
2 2 1 1 1; % min(A2(p), A2(w)) -> High Variance
4 2 1 1 1; % min(A4(p), A2(w)) -> High Variance
1 1 1 1 1; % min(A1(p), A1(w)) -> High Variance
4 1 1 1 1; % min(A4(p), A1(w)) -> High Variance
3 2 2 1 1; % min(A3(p), A2(w)) -> Low Variance
2 1 2 1 1; % min(A2(p), A1(w)) -> Low Variance
3 1 1 1 1; % min(A3(p), A1(w)) -> High Variance
];
% Add All Rules To FIS
fis = addrule(fis, rules);
rules_display = showrule(fis);
save('./FIS_WO.mat', 'fis');
% Draw A Structure Disgram Of FIS
<<<<<<< HEAD
% plotfis(fis);
=======
plotfis(fis);
>>>>>>> 0f6e2f2894f2741dc9b5fb26a7c8f1c98bbb25ea
%%
<<<<<<< HEAD
plotmf(fis,'output',1,101)
% plotmf(fis,'input',2)
=======
>>>>>>> 0f6e2f2894f2741dc9b5fb26a7c8f1c98bbb25ea