Artificial Intelligence and Machine Learning Course Assignments (3. Fuzzy Logic)


This article is the third part of the artificial intelligence and machine learning course assignment (3. Fuzzy logic)

This article is for learning reference only!


Jump to other chapters:

1. Basics of Knowledge Engineering

2. Function approximation

3. Fuzzy logic

4. Function optimization


3. Fuzzy logic


3.1 Problem 1 analysis and solution

       Suppose the domain of discourse U={x1,x2,x3,x4,x5}, A and B are two fuzzy sets on the domain of discourse U, it is known that:

A=\frac{0.2}{x_{1}}+\frac{0.3}{x_{2}}+\frac{0.5}{x_{3}}+\frac{0.6}{x_{4}}+\frac{1}{x_{5}}, B=\frac{0.1}{x_{1}}+\frac{0.4}{x_{3}}+\frac{1}{x_{4}}+\frac{0.7}{x_{5}}

 calculate:

A^{c},B^{c},A\cup B,A\cap B,A\cup A^{c},A\cap A^{c},A\cup B^{c},A\cap B^{c}

Solution:

A^{c}=\frac{0.8}{x_{1}}+\frac{0.7}{x_{2}}+\frac{0.5}{x_{3}}+\frac{0.4}{x_{4}}+\frac{0}{x_{5}}

B^{c}=\frac{0.9}{x_{1}}+\frac{1}{x_{2}}+\frac{0.6}{x_{3}}+\frac{0}{x_{4}}+\frac{0.3}{x_{5}}

A\cup B=\frac{0.2}{x_{1}}+\frac{0.3}{x_{2}}+\frac{0.5}{x_{3}}+\frac{1}{x_{4}}+\frac{1}{x_{5}}

A\cap B=\frac{0.1}{x_{1}}+\frac{0}{x_{2}}+\frac{0.4}{x_{3}}+\frac{0.6}{x_{4}}+\frac{0.7}{x_{5}}

A\cup A^{c}=\frac{0.8}{x_{1}}+\frac{0.7}{x_{2}}+\frac{0.5}{x_{3}}+\frac{0.6}{x_{4}}+\frac{1}{x_{5}}

A\cap A^{c}=\frac{0.2}{x_{1}}+\frac{0.3}{x_{2}}+\frac{0.5}{x_{3}}+\frac{0.4}{x_{4}}+\frac{0}{x_{5}}

A\cup B^{c}=\frac{0.9}{x_{1}}+\frac{1}{x_{2}}+\frac{0.6}{x_{3}}+\frac{0.6}{x_{4}}+\frac{1}{x_{5}}

A\cap B^{c}=\frac{0.2}{x_{1}}+\frac{0.3}{x_{2}}+\frac{0.5}{x_{3}}+\frac{0}{x_{4}}+\frac{0.3}{x_{5}}

3.2 Analysis and solution of problem 2

       Let there be fuzzy sets A, B, C on the domain of discussion X={x1,x2,x3}, Y={y1,y2,y3}, Z={z1,z2} and A=[0.5 0.7 0.1], =[0.2 0.1 0.8], C=[0.6 1], determine the fuzzy relationship R determined by the fuzzy conditional statement "If A and B then C", and determine that when the input A1=[0.1 0.4 1], B1=[1 0.3 0.1] output C1.

Solution: Because

A\times B\rightarrow C

R_{1}=A^{T}\times B=\begin{bmatrix} 0.5\\ 0.7 \\ 0.1 \end{bmatrix}\times \begin{bmatrix} 0.2 & 0.1 & 0.8 \end{bmatrix}=\begin{bmatrix} 0.2 & 0.1 & 0.5\\ 0.2 & 0.1 & 0.7\\ 0.1 & 0.1 & 0.1 \end{bmatrix}

Write R1 as a column vector:

R_{1}^{T}=\begin{bmatrix} 0.2 & 0.1 & 0.5 & 0.2 & 0.1 & 0.7 & 0.1 & 0.1 & 0.1 \end{bmatrix}^{T}

Then there are:

R=R_{1}^{T}\times C=\begin{bmatrix} 0.2 & 0.2\\ 0.1 & 0.1\\ 0.5 & 0.5\\ 0.2 & 0.2\\ 0.1 & 0.1\\ 0.6 & 0.7\\ 0.1 & 0.1\\ 0.1 & 0.1\\ 0.1 & 0.1 \end{bmatrix}

Given A1 and B1, then:

R_{2}=A_{1}^{T}\times B_{1}=\begin{bmatrix} 0.1\\ 0.4\\ 1 \end{bmatrix}\times \begin{bmatrix} 1 & 0.3 & 0.1 \end{bmatrix}=\begin{bmatrix} 0.1 & 0.1 & 0.1\\ 0.4 & 0.3 & 0.1\\ 1 & 0.3 & 0.1 \end{bmatrix}

In the same way, express R2 as a column vector:

R_{2}^{T}=\begin{bmatrix} 0.1 & 0.1 & 0.1 & 0.4 & 0.3 & 0.1 & 1 & 0.3 & 0.1 \end{bmatrix}^{T}

but:

C_{1}=(A_{1}\times B_{1})o(A\times B\rightarrow C)=R_{2}^{T}oR=\begin{bmatrix} 0.2 & 0.2 \end{bmatrix}

Then we finally get:

C_{1}=\frac{0.2}{z_{1}}+\frac{0.2}{z_{2}}

3.3 Analysis and solution of problem three

       Assume a dual input/single output system, the input X∈[-5, 5] and Y∈[-10, 10] are fuzzified into three levels: negative, zero, positive, and the output Z∈[-5, 5] is fuzzified into five Levels: negative big, negative small, zero, positive small, positive big. The fuzzy rule table is shown below. After appropriately selecting the membership function, design a fuzzy inference system based on the Mamdani model, draw the input/output curve, and calculate the size of the output Z when X and Y are 1 and -5 and -2 and 7 respectively, and analyze the selection What impact do different membership functions have on performance.

Table 3-1 Fuzzy relationship between X, Y and Z

X/Y=Z

burden

zero

just

burden

Upright

Masako

zero

zero

Masako

zero

Negative small

just

zero

Negative small

Big negative

3.3.1 Experimental steps

       By using the MATLAB/FUZZY toolbox to implement and build a model, design a MISO dual-input/single-output system, select semantic vocabulary that describes the input and output variables of the controller, and write it into the given fuzzy rule table. Open the FUZZY toolbox in MATLAB, click Edit, add an input variable, and name the input and output variables. The input variables are named X and Y, and the output variable is Z. Change the input and output range and type, input variables are X and Y, set the ranges to [-5, 5], [-10, 10] respectively, set the membership function to trimf, set Y is shown in Figure 3-2.

Figure 3-1 Set input variable X

 Figure 3-2 Set input variable Y

       The range of the output variable Z is set to [-5, 5], the membership function is set to trimf, among which the fuzzy rule selects mamdani, and the variable Z is set as shown in Figure 3-3. Click on the fuzzy rule inference engine, write the corresponding output output relationship and fuzzy rules as shown in Figure 3-4, and determine the fuzzy relationships of X, Y, and Z as shown in Table 3-1.

 Figure 3-3 Set output variable Z

 Figure 3-4 X, Y, Z fuzzy relationship settings

(a) Characteristic surface (b) Fuzzy rule browsing

Figure 3-5 Browsing characteristic surfaces and fuzzy rules

       Click the "View-Surface" menu in the editor window to obtain the input and output characteristic surface as shown in Figure 3-5(a). Then click the "View-Rules" menu command in the editor window to get the fuzzy rule browser shown in Figure 3-5(b). Enter 1 and -5 and -2 and 7 respectively in the iuput in the lower left corner of the window. Figure 3-6 is obtained, and the corresponding output results are: Z=1.06 and Z=-0.913.

(a) Enter [1, -5] (b) Enter [-2, 7]

Figure 3-6 The input and output results corresponding to the membership function trimf

       Use the membership function trapmf, that is, change the Type of the corresponding input and output variables X, Y, and Z, and select trapmf for all, as shown in Figure 3-7 and Figure 3-8(a). Click the "View-Surface" menu in the editor window to get the input and output characteristic surface as shown in Figure 3-8(b). Then click the "View-Rules" menu command in the editor window. In the lower left corner of the window Enter 1 and -5 and -2 and 7 respectively into iuput, and you can get Figure 3-9. The corresponding output results are: Z=1.24 and Z=-1.35.

(a) Input variable X (b) Input variable Y

Figure 3-7 Modify the input membership function to trapmf

(a) Output variable Z (b) Input and output characteristic surface

Figure 3-8 Output variable Z membership function and input-output characteristic surface

(a) Enter [1, -5] (b) Enter [-2, 7]

Figure 3-9 Corresponding input and output results of the membership function trapmf

        Using the membership function gbellmf, the input and output characteristic surface as shown in the figure below is obtained.

Figure 3-10 Membership function gbellmf input and output characteristic surface

        The corresponding output results of inputting [1;-5] and [-2;7] are: Z=1.09, Z=-1.72 respectively, as shown in Figure 3-11.

(a) Enter [1, -5] (b) Enter [-2, 7]

Figure 3-11 Corresponding input and output results of the membership function trapmf

       Modify the membership function to gaussmf, and the input and output characteristic surfaces are as shown in Figure 3-12.

 Figure 3-12 Membership function gaussmf input and output characteristic surface

(a) Enter [1, -5] (b) Enter [-2, 7]

Figure 3-13 Corresponding input and output results of the membership function trapmf

       As shown in Figure 3-13, the output results corresponding to the input [1;-5] and [-2;7] are: Z=0.863, Z=-1.02.

3.3.2 Experiment summary

       The membership functions are set to trimf, trapmf, gbellmf, and gaussmf in sequence. The inputs X and Y are [1, -5] and [-2, 7] respectively, and the output is Z. The results are shown in Table 3-2. It can be seen that using different membership functions, the results of fuzzy inference are different. The sharper the membership function curve, the higher the null value sensitivity, and the higher the resolution.

Table 3-2 Input and output results of different membership functions

membership function

X

Y

Z

trimf

1

-5

1.06

-2

7

-0.913

trapmf

1

-5

1.24

-2

7

-1.35

gbellmf

1

-5

1.09

-2

7

-1.72

gaussmf

1

-5

0.863

-2

7

-1.02


Other chapters of the Artificial Intelligence and Machine Learning Course Assignment: 1. Basics of Knowledge Engineering ; 2. Function Approximation ; 4. Function Optimization

Guess you like

Origin blog.csdn.net/HISJJ/article/details/130439917