-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuzzy-arithmetics.Rmd
More file actions
186 lines (131 loc) · 6.47 KB
/
fuzzy-arithmetics.Rmd
File metadata and controls
186 lines (131 loc) · 6.47 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
---
title: 'Fuzzy Arithmetics Operations'
output: github_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Interval arithmetic
### Four fuzzy interval operations are implemented in the **fuzzy-arithmetic.R** script:
- Addition
- Subtraction
- Multiplication
- Division
```{r}
source("fuzzy-arithmetic.R")
```
### Let A = ($min_A, mean_A, max_A$) be a triangular fuzzy number represented by three points: minimum, mean and maximum values. From a base set $X \in [min_A, max_A]$, the fuzzy set $A:X \rightarrow [0, 1]$ is defined as $A(x, min_A, mean_A, max_A)$
```{r}
fuzzy.number.a = c(min.value = 1, mean.value = 4, max.value = 6)
base.set.a = seq(fuzzy.number.a["min.value"], fuzzy.number.a["max.value"], by=0.1)
```
```{r echo=FALSE}
plot(base.set.a, triangular.membership.function(base.set.a, fuzzy.number.a), type = "l", ylim = c(0,1), xlab = "", ylab = "", lty = 2, main = 'Fuzzy Set A = (1, 4, 6)', lwd = 2)
lines(rep(fuzzy.number.a['mean.value'], 2), c(0, 1), lty = 2)
text(fuzzy.number.a['mean.value'] + 1/5, 0.5, expression(italic(mu)))
```
```{r}
fuzzy.number.b = c(min.value = 3, mean.value = 5, max.value = 7)
base.set.b = seq(fuzzy.number.b["min.value"], fuzzy.number.b["max.value"], by=0.1)
```
```{r echo=FALSE}
plot(base.set.b, triangular.membership.function(base.set.b, fuzzy.number.b), type = "l", ylim = c(0,1), xlab = "", ylab = "", lty = 2, main = 'Fuzzy Set B = (3, 5, 7)', lwd = 2, col = 'red')
lines(rep(fuzzy.number.b['mean.value'], 2), c(0, 1), lty = 2, col = 'red')
text(fuzzy.number.b['mean.value'] + 1/5, 0.5, expression(italic(mu)))
```
### The *plot.ops* function gives the plot of all arithmetic operations
```{r fig.width = 15, fig.height = 10}
plot.ops(fuzzy.number.a, fuzzy.number.b)
```
### Adding fuzzy number A and fuzzy number B
$A = (min_A, mean_A, max_A) \\ B = (min_B, mean_B, max_B) \\ A+B = (min_A + min_B, mean_A + mean_B, max_A + max_B)$
```{r}
min.number = fuzzy.number.a['min.value'] + fuzzy.number.b['min.value']
mean.number = fuzzy.number.a['mean.value'] + fuzzy.number.b['mean.value']
max.number = fuzzy.number.a['max.value'] + fuzzy.number.b['max.value']
cat(paste0('A + B = [', min.number, ', ', max.number, '] = (', min.number, ', ', mean.number, ', ', max.number, ') '))
```
```{r}
plot.ops(fuzzy.number.a, fuzzy.number.b, "add")
```
### Subtracting fuzzy number A and fuzzy number B
$A-B = (min_A - max_B, mean_A - mean_B, max_A - min_B)$
```{r}
min.number = fuzzy.number.a['min.value'] - fuzzy.number.b['max.value']
mean.number = fuzzy.number.a['mean.value'] - fuzzy.number.b['mean.value']
max.number = fuzzy.number.a['max.value'] - fuzzy.number.b['min.value']
cat(paste0('A - B = [', min.number, ', ', max.number, '] = (', min.number, ', ', mean.number, ', ', max.number, ')'))
```
```{r}
plot.ops(fuzzy.number.a, fuzzy.number.b, "sub")
```
### Multiplying fuzzy number A and fuzzy number B
$A = (min_A, mean_A, max_A) \\ B = (min_B, mean_B, max_B) \\ (A * B) = \\ [\min\{min_A * min_B, min_A * max_B, max_A * min_B, max_A * max_B\}, \\ \max\{min_A * min_B, min_A * max_B, max_A * min_B, max_A * max_B\}]$
```{r}
mult.interval = function(x, y) c(x * y, rev(x) * y)
mult.ab = mult.interval(c(fuzzy.number.a["min.value"], fuzzy.number.a["max.value"]),
c(fuzzy.number.b["min.value"], fuzzy.number.b["max.value"]))
```
```{r}
cat(paste0('A * B = [', min(mult.ab), ', ', max(mult.ab), ']'))
```
#### The **multiplication** of two fuzzy triangular numbers does **not result in a triangular number**
#### Because of that, we need to find the mean value of the resulting fuzzy triangular number by setting $\alpha-cut = 1$
#### Let $A_\alpha[min^\alpha_A, max^\alpha_A]$ $\forall \alpha [0, 1]$ be a crisp interval of a triangular fuzzy number
$A_\alpha \\= [min^{\alpha}_A, max^{\alpha}_A] \\= [(mean_A - min_A)\alpha + min_A, -(max_A - mean_A)\alpha + max_A]\\$
$A = [1, 6] = (1, 4, 6)\\ A_\alpha \\ = [(4 - 1)\alpha + 1, -(6 - 4)\alpha + 6] \\ = [3\alpha + 1, -2\alpha + 6]\\$
$B = [3, 7] = (3, 5, 7) \\ B_\alpha \\ = [(5 - 3)\alpha + 3, -(7 - 5)\alpha + 7] \\ = [2\alpha + 3, -2\alpha + 7]\\$
$$ (A * B)_\alpha = [(3\alpha +1)(2\alpha + 3), (-2\alpha + 6)(-2\alpha + 7)] $$
#### When $\alpha = 0$:
```{r}
alpha = 0
min.number = (3 * alpha + 1) * (2 * alpha + 3)
max.number = (-2 * alpha + 6) * (-2 * alpha + 7)
cat(paste0('(A * B)0 = [', min.number, ', ', max.number, ']'))
```
#### When $\alpha = 1$:
```{r}
alpha = 1
mean.number = (3 * alpha + 1) * (2 * alpha + 3)
cat(paste0('(A * B)1 = [', mean.number, ', ', (-2 * alpha + 6) * (-2 * alpha + 7), ']'))
```
#### Finally, the mean value of the resulting fuzzy triangular number by setting $\alpha-cut = 1$ is A1 * B1 = [20, 20] = 20
```{r}
cat(paste0('A * B = [', min.number, ', ', max.number, '] = ', '(', min.number, ', ', mean.number, ', ', max.number, ')'))
```
```{r}
plot.ops(fuzzy.number.a, fuzzy.number.b, "mult")
```
### Dividing fuzzy number A and fuzzy number B
$A = (min_A, mean_A, max_A) \\ B = (min_B, mean_B, max_B) \\ (A / B) \\ = \left[\min{\left(\frac{min_A}{min_B}, \frac{min_A}{max_B}, \frac{max_A}{min_B}, \frac{max_A}{max_B}\right)}, \max{\left(\frac{min_A}{min_B}, \frac{min_A}{max_B}, \frac{max_A}{min_B}, \frac{max_A}{max_B}\right)}\right]$
```{r}
div.interval = function(x, y) c(x / y, rev(x) / y)
div.ab = round(div.interval(c(fuzzy.number.a["min.value"], fuzzy.number.a["max.value"]),
c(fuzzy.number.b["min.value"], fuzzy.number.b["max.value"])), 2)
```
```{r}
cat(paste0('A / B = [', min(div.ab), ', ', max(div.ab), ']'))
```
#### The **division** of two fuzzy triangular numbers does **not result in a triangular number**
#### Because of that, we need to find the mean value of the resulting fuzzy triangular number by setting $\alpha-cut = 1$
$$ (A / B)_\alpha = [(3\alpha +1)/(-2\alpha + 7), (-2\alpha + 6)/(2\alpha + 3)] $$
#### When $\alpha = 0$:
```{r}
alpha = 0
min.number = round((3 * alpha + 1)/(2 * alpha + 3), 2)
max.number = round((-2 * alpha + 6)/(-2 * alpha + 7), 2)
cat(paste0('(A / B)0 = [', min.number, ', ', max.number, ']'))
```
#### When $\alpha = 1$:
```{r}
alpha = 1
mean.number = round((3 * alpha + 1)/(2 * alpha + 3), 2)
cat(paste0('(A / B)1 = [', mean.number, ', ', round((-2 * alpha + 6)/(-2 * alpha + 7), 2), ']'))
```
#### Finally, the mean value of the resulting fuzzy triangular number by setting $\alpha-cut = 1$ is (A / B)1 = [0.8, 0.8] = 0.8
```{r}
cat(paste0('(A / B) = [', min.number, ', ', max.number, '] = (', min.number, ', ', mean.number, ', ', max.number, ')'))
```
```{r}
plot.ops(fuzzy.number.a, fuzzy.number.b, "div")
```