fuzzy logic · fuzzy logic kanokwatt shiangjen computer science school of information and...

Post on 30-Jul-2020

4 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

FUZZY LOGIC

KANOKWATT SHIANGJENCOMPUTER SCIENCE

SCHOOL OF INFORMATION AND COMMUNICATION TECHNOLOGY

UNIVERSITY OF PHAYAO

Contents

• What is fuzzy logic?

• Application for fuzzy logic

• Why fuzzy logic?

• Fuzzy logic architecture

• Pros and Cons of fuzzy logic

• Q & A

• Reference

2

Source: https://www.techleer.com/articles/243-insight-into-the-concept-of-fuzzy-logic-in-artificial-intelligence/

What is fuzzy logic?

3

• Fuzzy logic (FL) คอื วธิกีารออกแบบใหค้อมพวิเตอรส์ามารถใชเ้หตผุลที่

คลา้ยคลงึกบัวธิกีารใหเ้หตผุลของมนุษย ์ส าหรบัประกอบการตดัสนิใจทีไ่ม่ใช ่YES กบั NO

• ปกตคิอมพวิเตอรจ์ะสง่กลบัค าตอบทีเ่ป็น TRUE กบั FALSE และมนุษยก็์มกัจะมคี าตอบทีช่ดัเจน คอื YES กบั NO แตก็่มบี่อยคร ัง้ที่ ค าตอบทีไ่ดจ้ากมนุษยอ์าจไม่ใช ่YES กบั NO แตอ่าจแสดงในรปูของคา่ระดบั เชน่ น้อย ปานกลาง มาก เราเรียกว่า “Linguistic value” เป็นตน้ หากเรามองกลบัไปทีค่อมพวิเตอร ์โดยทัว่ไปนอกจากการสง่คา่กลบัออกมาเป็น TRUE กบั FALSE ก็สามารถสง่คา่ออกมาเป็นตวัเลข เชน่ จ านวนเต็ม จ านวนจรงิ เป็นตน้ ดงัน้ันเราสามารถทีจ่ะน าความรูต้รงนีไ้ปใชต้อ่ไป

What is fuzzy logic?

4

Traditional Logic:

True False

1 0

Fuzzy Logic:

True False

0.8 0.2

“If service is good, even if the food is not excellent, the tip will be generous”

Source: http://www.dma.fi.upm.es/recursos/aplicaciones/logica_borrosa/web/fuzzy_inferencia/motivb_en.htm

“If service is good, then tip is average”

“If service is poor or food is bad, then tip is cheap”

What is fuzzy logic?

5

“If service is good, even if the food is not excellent, the tip will be generous”

Source: https://www.mathworks.com/help/fuzzy/input-output_map.png

“If service is good, then tip is average”

“If service is poor or food is bad, then tip is cheap”

What is fuzzy logic?

6Source: http://slideplayer.com/slide/3902376/13/images/5/Cold+water+%E2%80%93+Taps+and+Valves.jpg

Traditional Logic: Fuzzy Logic:

hot cold hot cold???

Source: http://mazsola.iit.uni-miskolc.hu/DATA/diploma/brutoczki_kornelia/013.gif

Binary membership function Multi-level membership function

“Fuzzy Logic is a common sense”

Application for fuzzy logic

7

• เคร ือ่งปรบัอากาศ / อปุกรณค์วบคมุความชืน้

• ตูเ้ย็น

• หมอ้หงุขา้ว

• เคร ือ่งซกัผา้

• ระบบเกยีรอ์ตัโนมตัิ

Source: https://www.canstarblue.com.au/wp-content/uploads/2016/10/Split-system-air-conditioner.jpgSource: https://tigerthailand.bentoweb.com/th/product/235703/product-235703

Source: https://www.lg.com/th/refrigerator/lg-GC-X247CSAV

Source: https://www.topvalue.com/130005814-electrolux-ewf12942.html

Air conditioner

8Source: https://www.canstarblue.com.au/wp-content/uploads/2016/10/Split-system-air-conditioner.jpg

Target

Temperature

Room

Temperature

Command

No Change

Heat

Cool

Automatic brake system

9Source: https://thetomatos.com/wp-content/uploads/2016/05/vw-bug-clipart-1.jpg

Source: http://clipart-library.com/images/kcKo6Eyxi.png

far close

Traditional Logic:

Automatic brake system

10Source: https://thetomatos.com/wp-content/uploads/2016/05/vw-bug-clipart-1.jpg

Source: http://clipart-library.com/images/kcKo6Eyxi.png

far close

Traditional Logic:

Is the car close? (0 or 1) No or Yes

Brake? (0 or 1) Off or On

Automatic brake system

11Source: https://thetomatos.com/wp-content/uploads/2016/05/vw-bug-clipart-1.jpg

Source: http://clipart-library.com/images/kcKo6Eyxi.png

far close

Is the car close? (0) No

Brake? (0) Off

Traditional Logic:

Automatic brake system

12Source: https://thetomatos.com/wp-content/uploads/2016/05/vw-bug-clipart-1.jpg

Source: http://clipart-library.com/images/kcKo6Eyxi.png

close

Traditional Logic:

Is the car close? (1) Yes

Brake? (1) On

Automatic brake system

13Source: https://thetomatos.com/wp-content/uploads/2016/05/vw-bug-clipart-1.jpg

Source: http://clipart-library.com/images/kcKo6Eyxi.png

far close

Fuzzy Logic:

Is the car close? (0 - 1) Range of No to Yes

Brake? (0 - 1) Range of Off to On

Automatic brake system

14Source: https://thetomatos.com/wp-content/uploads/2016/05/vw-bug-clipart-1.jpg

Source: http://clipart-library.com/images/kcKo6Eyxi.png

far close

Fuzzy Logic:

Is the car close? (0.3) Not very close

Brake? (0.3) Slight pressure

Automatic brake system

15Source: https://thetomatos.com/wp-content/uploads/2016/05/vw-bug-clipart-1.jpg

Source: http://clipart-library.com/images/kcKo6Eyxi.png

far close

Fuzzy Logic:

Is the car close? (0.7) Pretty close

Brake? (0.7) Fairly Heavy Pressure

Example

16Source: http://www.logicaldesigns.com/Ldfuz1.gif

Source: https://upload.wikimedia.org/wikipedia/commons/4/47/Fuzzy_control_-_input_and_output_variables_mapped_into_a_fuzzy_set.png

Why fuzzy logic?

17

• Fuzzy logic ใชจ้ดัการกบัความไม่แน่นอน (Uncertainty)

• สามารถพจิารณาระดบัของความเป็นจรงิ (Degree of truth)

• สามารถพจิารณาสว่นหน่ึงของสมาชกิทีอ่ยูใ่นเซต (Partial membership)

• แลว้เราจะบอกใหค้อมพวิเตอรร์ูไ้ดอ้ยา่งไรวา่อนันี ้อ้วน เรว็ หล่อ สวย ในเมือ่

คา่ระดบัความ อ้วน เรว็ หล่อ สวย ของแตล่ะคนน้ันอาจไม่เทา่กนั

What is the standard?

• น า้หนักของชาวยโุรป vs เอเชยี

• ความสงูของชาวยโุรป vs เอเชยี

• อายุ ความสงูและน า้หนักตวัทีเ่หมาะสม?

18

Body Mass Index: BMI

Fuzzy set (Zadeh, 1965)

• เป็นทฤษฏเีซต ทีม่นิียามดงัตอ่ไปนี้

• การเป็นสมาชกิของเซตใดๆ จะถกูก าหนดใหเ้ป็นคา่ระดบัความเป็นสมาชกิ (Degree of membership) ระหวา่ง 0 – 1

• ถา้ระดบัความเป็นสมาชกิเท่ากบั 1 แสดงวา่เป็นสมาชิกอย่างแน่นอน• ถา้ระดบัความเป็นสมาชกิเท่ากบั 0 แสดงวา่ไมไ่ด้เป็นสมาชิก

19

Membership function

• การนิยามคา่ระดบัความเป็นสมาชกิ จะขึน้อยูก่บันิยามของผูอ้อกแบบฟังกช์นัสมาชกิ (Membership function)

• ฟังกช์นัสมาชกิของ fuzzy set A บน universe of discourse X is defined as A: X -> [0, 1]

• โดยแตล่ะสมาชกิของ X จะมกีาร mapped กบัคา่ทีอ่ยูร่ะหวา่ง 0 – 1 เรยีกวา่ Degree of membership

20

Membership function

โดยทัว่ไป Membership function จะแสดงอยู่ในรปูของสมการทางคณิตศาสตร ์ซ ึง่เรามกัจะแสดงผลในรปูของกราฟ 2 มติ ิเพือ่ใหส้ามารถท าความเขา้ใจไดง้่าย

• แกน x แทน universe of discourse (ขอบเขตทีเ่ราสนใจ เชน่ น้อย ปานกลาง มาก เป็นตน้)

• แกน y แทน degree of membership between 0 and 1 (ระดบัความเป็นสมาชกิ)

21

Membership function

• รปูแบบกราฟิกทีไ่ดร้บัความนิยมคอื(a) Singleton

(b) Triangular

(c) Trapezoidal

(d) Gaussian

22Source: https://www.codeproject.com/KB/library/Fuzzy-Framework/image009.jpg

(a) (b)

(c) (d)

Singleton

23

0, x a

A(x) = 1, x = a

a

Triangular

24

a m b

0.2

0.4

0.6

0.8

1.0

Trapezoidal

25

0.2

0.4

0.6

0.8

1.0

a b c d

R-Trapezoidal

26

0.2

0.4

0.6

0.8

1.0

c d

L-Trapezoidal

27

0.2

0.4

0.6

0.8

1.0

a b

Gaussian

28

0.2

0.4

0.6

0.8

1.0

m

k : standard deviation (k > 0)

Example: Membership function

29Source: http://www.logicaldesigns.com/Ldfuz1.gif

Source: https://upload.wikimedia.org/wikipedia/commons/4/47/Fuzzy_control_-_input_and_output_variables_mapped_into_a_fuzzy_set.png

(1) เราตอ้งสรา้งสมการของ Membership function

(2) เราตอ้งทราบความเรว็ (x)

(3) แทนความเรว็ (x) ใน (1) เพือ่หาจดุตดั

(4) คา่จดุตดัใชแ้ทนระดบัของความเป็นสมาชกิเพือ่ใช ้

ใน Inference engine ตอ่ไป

Example: Membership function

30Source: http://www.logicaldesigns.com/Ldfuz1.gif

Source: https://upload.wikimedia.org/wikipedia/commons/4/47/Fuzzy_control_-_input_and_output_variables_mapped_into_a_fuzzy_set.png

ก าหนดให ้Universe of Speed >= 0

(1) slow(x) = ?, medium(x) = ?, fast(x) = ?

(2) x = 50

(3) slow(50) = 0.33, medium(50) = 0.67, fast(50) = 0

(4) เราจะไดค้า่ระดบัความเป็นสมาชกิเพือ่ใชใ้น

Inference engine ตอ่ไป

50

0.33

0.67

Non-Fuzzy

• The Tipping Problem (Non-Fuzzy)

31

Service Charge = 15% Service between = 5-25%

Depend on quality of service

From (0 – 10)

Service between = 5-25%

Depend on quality of service

from (0 – 10) and

quality of food

Fuzzy

• The Tipping Problem (Fuzzy)

32

Service Food Tip (%)

Cheap Average GenerousPoor Good Excellent

0.5

1.0

0

Standard Deviation = 1.5

The Tipping Problem

• Tipping Problem ประกอบดว้ย 3 Factors คอื• Service

• Food

• Tip

• Rules:• If the service is poor or the food is rancid, then the tip is cheap

• If the service is good, then the tip is average

• If the service is excellent or the food is delicious, then the tip is generous

33

เราจะสามารถรวมผลลพัธจ์าก กฎทุกขอ้เพือ่ตอบค าถามไดอ้ย่างไร?

The Tipping Problem

34

Input 1Service (0-10)

Input 2Food (0-10)

Rule 1:If service is poor or food is rancidThen tip is cheap

Rule 2:If service is goodThen tip is average

Rule 3:If service is excellent or food is deliciousThen tip is generous

Output

Tip (5-25%)

The Input are crisp

(non-fuzzy) numbers

limit to specify range

(fuzzification)

All rules are evaluated in parallel

using fuzzy reasoning

The results of the rules

are combined

and distilled (defuzzification)

The result is

a crisp (non-fuzzy)

number

Fuzzy Operators

• Union: AB(x) = (A (x) OR B (x))

= MAX(A (x), B (x))

• Intersection: AB(x) = (A (x) AND B (x))

= MIN(A (x), B (x))

• Complement: Ac(x) = 1 - A (x)

35

“Fuzzy Operators จะถกูน าไปใชใ้นขัน้ตอนของ Inference engine”

Fuzzy Operators: AND

A B A AND B

T T T

T F F

F T F

F F F

36

A B A AND B

1 1 1

1 0 0

0 1 0

0 0 0

A B MIN(A ,B)

1 1 1

1 0 0

0 1 0

0 0 0

A B MIN(A, B)

T T T

T F F

F T F

F F F

ก าหนดให ้T = 1, F = 0

Fuzzy Operators: OR

A B A OR B

T T T

T F T

F T T

F F F

37

A B A OR B

1 1 1

1 0 1

0 1 1

0 0 0

A B MAX(A ,B)

1 1 1

1 0 1

0 1 1

0 0 0

A B MAX(A, B)

T T T

T F T

F T T

F F F

ก าหนดให ้T = 1, F = 0

Fuzzy Operators: Complement

A NOT A

T F

F T

38

ก าหนดให ้T = 1, F = 0

A COMPLEMENT A = (1 – A)

T F

F T

A NOT A

1 0

0 1

A COMPLEMENT A = (1 – A)

1 0

0 1

Crisp set• ส าหรบั crisp set A ทีม่สีมาชกิใน Universe X,

• x A : x เป็นสมาชกิทีอ่ยู่ใน A

• x A : x ไม่เป็นสมาชกิทีอ่ยู่ใน A

• x X : x เป็นสมาชกิทีอ่ยู่ใน Universe X

• ตวัอยา่งก าหนดให ้Universe X = ความเรว็ตัง้แต ่0 – 200• Crisp set A = {25, 50, 75, 120}

• 25 A, 50 A, 75 A, 120 A, 180 A

• 25 X, 50 X, 75 X, 120 X, 180 X

39

Fuzzy logic architecture

40

Fuzzifier

Knowledge-based

DefuzzifierInference

engine

Crisp

input

Fuzzy

input

set

Fuzzy

output

set

Crisp

output

Membership

function

Fuzzy logic architecture

สถาปัตยกรรมของ Fuzzy logic ประกอบดว้ย 4 สว่นทีส่ าคญั คอื

• Fuzzification: แปลง Crisp input ใหก้ลายเป็น Fuzzy input

• Knowledge-based: ฐานความรูข้องกฎ (Rules) ทีม่าจากผูเ้ช ีย่วชาญ อยู่ในรปูของ IF-THEN

• Inference engine: ตรวจสอบ Fuzzy input กบั Rules ทีอ่ยูใ่น Knowledge-based แลว้แปลงใหอ้ยูใ่นรปูของ Fuzzy output

• Defuzzification: แปลง Fuzzy output ใหก้ลายเป็น Crisp output

41

How to develop a fuzzy logic system?

42

• Define the linguistic variables and terms (ความสงู นอ้ย ปานกลาง มาก)

• Construct the membership functions for them (น าเสนอไดใ้นรปูแบบกราฟิก)

• Construct the knowledge base of the rules (กฎในการตดัสนิใจ if-then)

• Convert crisp data into fuzzy datasets using the membership functions(Fuzzification)

• Evaluate rules in the rule base. (Inference engine using if)

• Combine results from each rule (Inference engine using then)

• Convert output data into non-fuzzy values (Defuzzification แปลงค าตอบในรปู linguistic variable ใหเ้ป็นตวัเลขทีเ่ป็นค าตอบ)

Classification of fuzzy inference methods

Fuzzy reasoning

Direct methods

Mamdani’s direct method

Takagi and Sugeno ‘s method

Simplified method

Indirect method

43

Mamdani’s Method

44

Evaluate antecedent

Obtain conclusion

Aggregate conclusions

Defuzzification

Summary

Customer review: Service = 3, Food = 8

• The Tipping Problem (Fuzzy)

45

Service Food Tip (%)

Cheap Average GenerousPoor Good Excellent

0.5

1.0

0

Standard Deviation = 1.5

0.1354

0.4111

Service = Poor (0.1354)

Service = Good (0.4111)

Food = Good (0.4)

Food = Delicious (0.75)

Tip = ???

Inference Rules

• If the service is poor or the food is rancid, then the tip is cheap

• If the service is good, then the tip is average

• If the service is excellent or the food is delicious, then the tip is generous

• Fuzzy input ทีอ่ยูห่ลงั If เราจะเรยีกวา่ Antecedent

• Fuzzy output ทีอ่ยูห่ลงั then เราจะเรยีกวา่ Consequent

46

Antecedent Consequent

Evaluate antecedent

47

0.750.75

Obtain conclusion

48

Aggregate conclusions

49

0.1354

0.4111

0.7500

Defuzzification

50

0.1354

0.4111

0.7500

Defuzzification

51

0.1354

0.4111

0.7500

Types of Defuzzification

• Centroid method (Center of gravity)

• Max-membership principle (Height method)

• Weighted average method

• Mean-max membership (Middle of Maxima)

• Center of sums

• Center of Largest area

• Etc.

52

Weighted Average Method

• เป็นวธิกีารทีเ่หมาะกบัผลลพัธข์องฟังกช์นัสมาชกิทีม่คีวามสมมาตร(Symmetrical) และมผีลลพัธใ์กลเ้คยีงกบั Centroid method

• วธิกีารนีส้ามารถค านวณคา่ผลลพัธไ์ดอ้ยา่งรวดเรว็ โดยใชค้า่น า้หนักจาก maximum membership value มาใชใ้นการค านวณ

53

𝑧∗ =σ𝜇 ҧ𝑥 ∙ ҧ𝑥

σ𝜇 ҧ𝑥ҧ𝑥 คอื คา่น ้าหนักจาก average membership value

Weighted Average Method

54

𝑧∗ =σ𝜇 ҧ𝑥 ∙ ҧ𝑥

σ𝜇 ҧ𝑥

𝑧∗ =0.1354 × 5 + 0.4111 × 12.5 + 0.75 × 20

0.1354 + 0.4111 + 0.75𝑧∗ = 16.04

𝑤ℎ𝑒𝑟𝑒 ҧ𝑥 is average membership value

0.1354

0.4111

0.7500

5 12.5 20

Pros and Cons of fuzzy logic

• Pros• ความรูท้ีไ่ดม้าจากผูเ้ช ีย่วชาญ

• เหมาะกบัระบบทีจ่ดัการกบัปัญหาทีไ่ม่ตอ้งการความถกูตอ้ง 100%

• สรา้ง และท าความเขา้ใจไดง่้าย

• ประยกุตใ์ชง้านไดห้ลากหลาย เชน่ปรมิาณยา ตอ่น ้าหนักตวัของผูป่้วยเป็นตน้

• Cons• ไม่เหมาะกบัระบบทีจ่ดัการกบัปัญหาที่

ตอ้งการความถกูตอ้ง 100%

• ท าความเขา้ใจไดย้าก ถา้ปัญหามคีวามซบัซอ้น

55

Q & A

56

Reference• https://www.tutorialspoint.com/artificial_intelligence/artificial_intelligence_fuzzy_logic_systems.htm

• https://www.youtube.com/watch?v=rln_kZbYaWc

• https://en.wikipedia.org/wiki/Fuzzy_logic

• http://www.cs.su.ac.th/~tasanawa/cs517561/is6.pdf

• http://www.dma.fi.upm.es/recursos/aplicaciones/logica_borrosa/web/fuzzy_inferencia/funpert_en.htm

• https://www.ibu.edu.ba/assets/userfiles/it/2012/eee-Fuzzy-1.ppt

• http://mike.watts.net.nz/Teaching/IIS/Lecture5.pdf

• https://www.youtube.com/watch?v=O348HnWPm7A

• https://www.youtube.com/watch?v=wBrHEXkTero

• https://www.youtube.com/watch?v=LupUhRJo_sU&t=167s

57

top related