Fuzzy Logic and its Applications - FAIR

Post on 19-Mar-2023

0 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

Transcript

PGS.TS. Trần Văn Lăng

Logic mờ và ứng dụngFuzzy Logic and its Applications

1

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Tổchứclớphọc• MonhoctrongchươngtrınhđaotaocaohoccuaTrươngĐaihocLacHo: ng(LHU),TrươngĐaihocBaRia-VungTau(BVU)

• Phonghoconline:‣ LHUhttps://meet.google.com/cvc-ommw-xke‣ BVUhttps://meet.google.com/snr-uqye-hce

• SoT tınchı:2lythuyeT t,1thưchanh• Slide:http://fair.conf.vn/~lang/lecture/fuzzy/FL&App.pdf• Chuanbitrươckhihoc:MoitrươngthưcthiPython(Jupyter,GitHub,hoacGoogleColab)

2

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Nộidunghọcphần

• Taphơpmơ,logicmơ• Cacpheptoantrentaphơpmơ• Quanhe,pheptoanvaquytaf clienkeT ttrongngưcanhlapluanmơ• Sưdunglapluanmơtrongbaitoanđie:ukhien• LuanlymơdungcholuatkeT thơpvacacđođolienquan• Phanloaidưatrenlapluanmơ• NgonngưPythontrongviecnhưngvaTnđe: đatra

3

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Mộtchútvềlịchsử• Logiccođienđato: ntaitưraT tlau,vơi2giatrichantrilaĐung(True)vaSai(False).HaigiatrinaykhongđuđediehnđatnhưngvaTnđe: mangtınhluanlytrongtheT giơithưc

• Khainiemtaphơpcungdưavaogiatrichantriđungsaiđediehntave: viecmotpha:ntưthuochaykhongthuocve: no.Tưđotaphơpđatrơthanhne:ntangquantrongtrongToanhoc

• Nam1965,GiaosưLotmiAliaskerZadeh,TrươngĐaihocCalifornia,BerkeleyđađưaralıthuyeT t“Fuzzysets”trongcongtrınh“L.A.Zadeh,FuzzySet,InformationandControls,8338-353(1965).

4

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

VềGS.LotfiA.Zadeh

• Vơikhainiemmơive: taphơp,đolamotpha:ntưkhongchıthuochoackhongthuocvaotaphơpmamơrongđechobieT tmưcđophuthuoccuanođovaotaphơp.

• Vơisưmơrongmotkhainiemne:ntanglataphơpnhưvay,ZadehđalamthayđoigoT creh ve: luanly.

• Ve: motchuttieusư,GS.Zadeh(04/02/1921)ngươiIransinhraơBaku,AzerbaijanvơitenkhaisinhlaLotmiAliaskerzadeh,LotmiAliaskerzadeh.

‣ Nam1931sinhsoT ngvahoctapơTeheran‣ Nam1943dicưđeTnMyđetieTptuchoctap

6

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Tổnghợp

‣ Tư1959lagiaosươUniversityofCalifornia,Berkleey• Conve: logicmơ:‣ 1965:SeminalPaper“FuzzyLogic”byProf.LotmiZadeh,FacultyinElectricalEngineering,U.C.Berkeley,SetstheFoundationofthe“FuzzySetTheory”

‣ 1970:FirstApplicationofFuzzyLogicinControlEngineering(Europe)‣ 1975:IntroductionofFuzzyLogicinJapan‣ 1980:EmpiricalVerimicationofFuzzyLogicinEurope

7

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

‣ 1985:BroadApplicationofFuzzyLogicinJapan

‣ 1990:BroadApplicationofFuzzyLogicinEurope

‣ 1995:BroadApplicationofFuzzyLogicintheU.S.

‣ 2000:FuzzyLogicBecomesaStandardTechnologyandIsAlsoAppliedin:

• Ư{ ngdungđatratrongcaclınhvưcnhư‣ DataandSensorSignalAnalysis‣ ApplicationofFuzzyLogicinBusinessandFinance.

8

‣ Kythuatđien,cơđientư‣ Đie:ukhienvatưđonghoa‣ CongngheHoahoc‣ Kythuatxaydưng‣ Đie:ukhiencongnghiep‣ Kythuathatnhan‣ v.v…

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Ứngdụngminhhọa

9

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Mộtchútkháiniệmlogicmờ

• Logicmơ(fuzzylogic)lanhưngluanly,lapluanđeluangiaimotcachchatchenhưnghientương/đoT itươngmơho: .

• Nhưnghientương/đoT itươngnaythươngđươcmotaba~ngcacngontưmatınhđinhtınhnhưtoT t,gioi,gia,cao,v.v…hoackemthemnhưngtrangtưnhưraT t,vocung,qua,...makhongđươcđinhlươngchınhxac.

‣ HoacranhgiơigiưacacđactınhcuađoT itươngkhongđươcphanchiaranhmach,khosoT hoachınhxacđeđinhlươngtrenmaytınh

• Logicmơdưatrentaphơpmơ(fuzzyset)đetưđogiưa2khainiemđungsaicothediehndatba~ngvohangiatrichantri.

10

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Hoacnhưngkhainiemmaranhgiơiphanloaikhongrorang;cha�nghan:• Quychuanve: đomasatđươngsa

HesoT masat Loaiđanhgia0.00 − 0.34 Vocungnguyhiem0.35 − 0.39 RaT tnguyhiem0.40 − 0.49 Nguyhiem0.50 − 0.59 TươngđoT iantoan0.60 − 0.79 Antoan

> 0.8 RaT tantoan

11

TrongtrươnghơpnayranhgiơigiưahesoT antoanvanguyhiemraT tkhophanđinh: thuocnhomnguyhiem,nhưng thuocnhomantoan

≤ 0.49≥ 0.50

Logicmờgiúpgiảiquyếtnhữngvấnđềnàykhátriệtđể

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Tậphợpmờ(FuzzySet)

• Địnhnghĩa1:Chotaphơp ,Alataphơpmơ

‣ đươcgoilakhonggianne:nhaycongoilamotvutru(universe)hoaclatapthamchieTu.ThưcchaT tXlamie:ngiatricuaham

‣ goilahamthuoc(membershipfunction)haymưcđophuthuoc(membershipdegree)đechımưcđophuthuoccuacacpha:ntưtrong vaotap labaonhieupha:ntram

‣ Tap đươcquyươcba~ngnhie:ucachbieudiehnkhacnhau;cha�nghancothevieT t ,hoac

X ⟺ ∃μA : X → [0,1]

XμA

μAX

A

AA = {(x, μA(x)))/x ∈ X} A = {μA(x)

x /x ∈ X}12

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Vídụ1• Giasưkhica:nquanlyve: tuoiđephanbietngươitretuoi,ngươitrungnienvangươigia.

• Tasưdung3taptươngưngA:tre,B:trungnien,C:gia.• đươcgoila3tapmơkhitımđươc3hamthuoc

• Giasưkhonggianne:nla ,vaquyươcra~ng:

‣ Ngươitretuoikhituoicuahoxungquanh25‣ NgươitrungnienthươngcotuoixaTpxı40‣ Conkhi60tuoitrơlencothecoilagia

A, B, C μA, μB, μC

X = {1,14,25,40,60,100}

13

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Nencothechon:

A = {01

,0.614

,125

,0

40,

060

,0

100 }B = {0

1,

014

,0.425

,1

40,

0.260

,0

100 }C = {0

1,

014

,0

25,

0.540

,1

60,

1100 }

14

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Suydiễnthêm

• Taphơpthongthươnglamottrươnghơpriengcuatapmơ,nencothebieudiehntheocachkyhieucuatapmơ

‣ Khonggianne:n đươcvieT tla .

‣ Tươngtưnhưvay,tapcon đươcvieT t ,tưđaysuyra ,cothevieT t

• Nhưvay,hamthanhvien vơitapmơ đươcđo: ngnhaT tvơinhau

X X = {(x,1)/x ∈ X}U ⊂ X U = {(x,1)/x ∈ X}

V ⊄ X V = {(x,0)/x ∈ X}μA A

15

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Vídụ2

• Trươnghơpkhonggianne:nlamottaphơpvohankhongđeTmđươc,thıhamthanhviencothebieudiehnba~ngmotbieuthưc.

‣ Cha�nghan,vơikhonggianne:n lađotuoiđươctınhraT tchily.‣ Khiđo,hamthanhviencuatapmơtuoitre cothenoisuycacgiatritainhưngđiemrơiracnentrenđetrơthanhmothamlientuc.

• ĐexaTpxıcacgiatricua , va tacothenoisuytuyeTntınhba~ngmotđươngtha�ngđiqua2điem.

• Vıducho2điemcotoađola

X

A

μA(x), ∀x ∈ [1,14), [14,25) [25,40) [40,100]

(xP, yP), (xQ, yQ)

16

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Phươngtrınhđươngtha�ngđiqua2điemnayla

Vơi thı

Vơi thı

Vơi ,thı

y = yP + (yQ − yP)x − xP

xQ − xP

P(1,0), Q(14,0.6) y = 0 + (0.6 − 0)x − 1

14 − 1=

0.613

(x − 1)

P(14,0.6), Q(25,1) y = 0.6 + (1 − 0.6)x − 14

25 − 14=

111

(0.4x + 1)

P(25,1), Q(40,0) y = 1 + (0 − 1)x − 25

40 − 25=

40 − x15

17

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Tưđaysuyra

μA(x) =

0.613 (x − 1) neTux ∈ [1,14)111 (0.4x + 1) − x neTux ∈ [14,25)40 − x

15 neTux ∈ [25,40)

0 neTux ∈ [40,100]

18

Tươngtưnhưvay,cothetımhamthanhvienchocactapmơtrungnien,gia

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Bàitập1

• Cho lakhonggianne:nve: kıchthươcphonghoccancưvaosoT lươngbangheT đuchosinhvienngo: ihoc.

• Cha�nghan,co8phonghocvơikhanangchưalamotpha:ntưcuatapXnhưsau .Xaydưngcactap:

‣ Alatapmơcacphonghocrong‣ Blatapmơcacphongcothechưa100sinhvien‣ Clatapcacphonghockhongchưaqua100sinhvien

X

X = {30,50,75,90,100,125,150,200}

19

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Cáchthứcxâydựngtậpmờ

• XaydưngtapmơthưcchaT tlaxaydưnghamthanhviencuatapđotrenmotkhonggianne:nđươcxacđinhtrươc.

• Hơnnưa,tapmơđemotanhưngkhainiemmangtınhđinhtınh,đoikhimơho: vıphuthuocvangưcanh.

‣ Cha�nghanơvungnhietđơi,khainiemnhietđocao,haykhıhaunonglenđươclươnghoaba~ngcacgiatrikhacsovơivungonđơi.

20

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Tiếpcậntrựcquan

• ViecxaydưngtapmơcothedưavaokieTnthưcvangưcanhtrưcquanđexacđinhgiatricuacachamthanhvien.

• Cha�nghan,vơivaccineModernatheosoT lieuđươccongboT cuaWHO:VaccineModernađađươcchưngminhlacohieuquaketưngaythư14saungaytiemlie:uđa:utien;mưcđohieuquala94%trongviecbaovechoT nglaidichbenhCoViD-19;vaccineAstraZenecala63%,Sinovacla51%,Pmizerkhoang96%

• Nhưvay,khanangkhongnhiehmvirusSARS-CoV-2neTutiemvaccineloaiyeTunhaT tcungbơtđiđươc51%,conneTukhongtiemcothe100%khanangbinhiehm.

21

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Tưđay,cothexaydưngtapmơđenhanđinhve: vaccinedưatrentapne:nXlacacconsoT ve: khanangđe: khangvơivirusSARS-CoV-2khitiemcacloaivaccineđanglưuhanh.

• Cha�nghan,vơi ,cocacnhanđinh:

‣ VaccinetoT t(xaTpxı94%)‣ Vaccinetrungbınh(xaTpxı63%)‣ VaccinechưatoT t(xaTpxıga:ndươi51%)

X = {51,63,94}

22

Làcăncứđểxâydựng3tậpmờ:vaccinetốt(T),vaccinetrungbình(B),vaccineyếu(Y).

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Tiếpcậntheochuyêngia

• Nha~mmucđıch:‣ ThuthapkieTnthưctưchuyengiaquacacmenhđe: ngonngư‣ Xaydưnghamtưviecxưlycacmenhđe: ngonngư

• NhưngvaTnđe: sauđaycotheđatrakhica:nsưhoh trơcuachuyengia:‣ Mưcđothanhviencuax∈XlentapmơAlabaonhieu.‣ Pha:ntưxnaocomưcđothanhvienμA(x)noh itroilentapA.

23

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Khiconhie:uchuyengiachoykieTn,mưcđothanhvientonghơpselatrungbınhcongcuacacykieTntheocachtınh

• Cha�nghanvơinchuyengia,moh ichuyengiaxaydưngtapmơ riengtrencungmotkhonggiane:nX.Khiđo,tapmơsưdungAcohamthanhvienla:

Ai, ∀i = 1,n

μA(x) =∑n

i=1 μAi(x)

n

24

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• TrongtrươnghơpkieTnthưccuacacchuyengiakhacnhau,cotheđưathemtrongsoT chotưngchuyengia

• KhiđovơichuyengiathưicotrongsoT thıđothuocđươctınh:wi

μA(x) =∑n

i=1 wiμAi(x)

∑ni=1 wi

25

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Khichıcomotchuyengia,ca:nphaikiemtracheođetranhsưmauthuahncuachınhchuyengianay.Cachthưcnhưsau:

‣ Giasưkhonggianne:nXcompha:ntư ,goi .

‣ Đat .

‣ TưđaylaTycacđothuoc

xiμi = μA(xi), ∀i = 1m

pij =μi

μj, ∀i, j = 1,m

μi = μA(xi) =1

∑mj=1 pij

, ∀i = 1,m

26

• RasoatlaiđebaođamtınhnhaT tquanba~ngcachxemxettınhđungđafncuacaccongthưcsau:

pik = pijpjk

pii = 1

pij =1pji

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Theocáchsuydiễn,dẫngiải

• DưatrennhưngkeT tquane:ntangvadưavaosưtaphơpcackieTnthưcđeđưaranhưngyeTutoT quyeT tđinh.

• KieTnthưclasưtonghơptrencơsơcacpheptoanAND,OR,NOTgiưacacthanhpha:nkieTnthưc.

• Cha�nghan,giasưco3tap(mơ)đemotatamgiaccan( ),tamgiacvuong( )vatamgiacđe:u( ).

• Khiđotamgiacvuongcanla ,tamgiacthươngla

TcTv Td

Tvc = Tv ∩ TcTt = ¬Tv ∩ ¬Tc ∩ ¬Td

27

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Giasưtaxaydưngcactapmơcho3loaitamgiacbanđa:udưavao3gocsaocho vathoađie:ukien .

• Nhưvay,khonggianne:n la

• Hamthuocchotamgiaccancothela

a, b, c a + b + c = 180o a ≥ b ≥ c ≥ 0

X

X = {t = (a, b, c)/a + b + c = 180o, a ≥ b ≥ c ≥ 0}

μc() = 1 −min{a − b, b − c}

60

28

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Cothedeh dangkiemchưng,cho

‣ NeTu ,hay thı

‣ NeTu thı ;cha�nghan,

,hay

t = (a, b, c)

a = b b = c μTc(t) = 1

a − b = 3 μTc(t) =

5760

= 0.95

a = 630, b = 60o, c = 57o a = 73o, B = 70o, c = 37o

29

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Hamthuocchotamgiacvuongcothela:

• Khiđo,‣ NeTu latamgiacvuongthưcsư,

‣ NeTu cangxa thımưcđovuongcanggiam(giatricangnhohơnsovơi1)

μv(t) = 1 −|a − 90 |

90

a = 90o

a 90o

30

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Tươngtư,cohamthuocchotamgiacđe:u

• Khiđo,neTu thıđothuocla1,conkhitamgiaccanglechkhoitrươnghơptamgiacđe:u,thıgiatrinaycangnhohơn1.

• Tưnhưnghamthuocnay,suyra‣

μd(t) = 1 −|a − c |

180a = c = 60o

μvc(t) = min{μv(t), μc(t)}

μt(t) = min{1 − μv(t),1 − μc(t),1 − μd(t)}

31

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Vídụ3

• VơiChotamgiacco ,thı

• Tưđaysuyra latamgiacvuong(gầnvuôngnhất)

a = 85o, b = 50o, c = 45o

μc(a, b, c) = 1 −min{a − b, b − c}

60= 0.91

μv(a, b, c) = 1 −min{a − 90}

90= 0.94

μd(a, b, c) = 1 −|a − c |

180= 0,70

t

32

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Phéptoántrêncùngkhônggiannền

• TrongthưcteT đegiaiquyeT tmotvaTnđe: đoikhiphaisưdungđeTnnhie:utapmơkhacnhaukeT thơplai.

• Cha�nghan,đeđanhgiananglưcve: khoahockythuatcuamothocsinhkhongphaichıcancưvaođiemmotmonhocvaconphaiphoT ihơpcacmonhoctưnhienlaivơinhau.

• Chınhvıvay,cacpheptoanAND,OR,NOTlaca:nthieT ttrongtrươnghơpnay

33

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Địnhnghĩa2:Cho2tapmơ trencungkhonggianne:n vơihamthuoctươngưngla .Khiđotapmơ cohamthuocla:

• Địnhnghĩa3:Cho2tapmơ trencungkhonggianne:n vơihamthuoctươngưngla .Khiđotapmơ cohamthuocla:

• Địnhnghĩa4:Chotapmơ trenkhonggianne:n vơihamthuocla .Khiđotapmơ cohamthuocla:

A, B XμA, μB A ∩ B

μA∩B(x) = min{μA(x), μB(x)}A, B X

μA, μB A ∪ B

μA∪B(x) = max{μA(x), μB(x)}A X μA

¬A

μ¬A(x) = 1 − μA(x)

34

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Tínhchất1:GioT ngnhưtaphơpthongthương,taphơpmơcungcocactınhchaT tnhư:

‣ ,

A ∩ B ⊂ A A ⊂ A ∪ B

A ∩ X = A, A ∪ X = X

¬(A ∪ B) = ¬A ∩ ¬B, ¬(A ∩ B) = ¬A ∪ ¬B

A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C)

35

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Lưuý:TrongĐN3,thayvıdungmin{}tacothedung:,hay

• TrongĐN4,thaychomax{},tacothedungmottrong2cachsau:

μA∩B(x) = max{0,μA(x) + μB(x) − 1}μA∩B(x) = μA(x)μB(x)

μA∪B(x) = min{1,μA(x) + μB(x)}μA∪B(x) = μA(x) + μB(x) − μA(x)μB(x)

36

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Địnhnghĩa5:Cho2tapmơ trencungkhonggianne:n vơihamthuoctươngưngla .Haitapmơ đươcgoilaba~ngnhau,kyhieu

• Địnhnghĩa6:Cho2tapmơ trencungkhonggianne:n vơihamthuoctươngưngla .Haitapmơ

• Tínhchất2:Vơi latapmơ

A, B XμA, μB A, B

A = B ⟺ μA(x) = μB(x), ∀x ∈ X

A, B XμA, μB A ⊂ B ⟺ μA(x) ≤ μB(x), ∀x ∈ X

A, B A ⊂ BvaB ⊂ A ⇔ A = B

37

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Bàitập2

• Trencơsơ2tapmơA:phonghocrong,B:phongcothechưa100sinhvien,xaydưngcactapmơ

‣ D:Cacphonghocrongmacothechưa100sinhvien( )

‣ E:Cacphonghocronghoaccothechưa100sinhvien( )

‣ F:Cacphonghockhongrong( )

A ∩ B

A ∪ B

¬A

38

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Bàitập3

• Xaydưngcactapmơsauđebosungthemcancưxettuyenvaomottrươngđaihocngoaiđiemcuahocba:

‣ Thưgiơithieucuagiaovien‣ Bailuangiơithieuve: banthan‣ MotsoT bailuankhac

39

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Phéptoántrênkhônggiannềnkhácnhau

• Trongcacpheptoanơtrentachıxettapmơtrencungmotkhonggianne:nlaX.

• Tuynhien,trongthưcteT conhie:utapmơvơikhonggianne:nkhacnhau.• TıchDescartesgiupđinhnghıavaTnđe: naynhưthưcteT đangto: ntai.Đaychınhlavieclainhie:utaphơpvơinhauđeđươcmottaphơpmơi

• SoT pha:ntưcuataphơptıchnaylatıchcuacacsoT pha:ntưcuacactaphơptaothanh.

40

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Địnhnghĩa7:Chortapmơ ,kyhieutapmơtıchDescartestrencactapthamchieTu ,hàm

thuoccuatıchcactapmơla thoa

A1, A2, . . . , ArA = A1 × A2 × . . . × Ar X = X1 × X2 × . . . × Xr

μA(x)

μA(x) = min{μA1(x1), μA2

(x2), . . . , μAr(xr)}, ∀x = (x1, x2, . . . , xr) ∈ X

41

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Vídụ4

• KhainiemgiakhongchıcancưvaotuoimaconcancưvaonhưngyeTutoT khac,cha�nghanviecđilai

• Khiđo,ngoaitapmơlơntuoiCtrenkhonggianne:nXnhưtrongvıdutrươc,

• BosungthemtapđilaichamchapDtrenkhonggianne:nYnhưsau:

X = {1,14,25,40,60,100}, C = {01

,0

14,

025

,0.540

,160

,1

100 }

42

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• VơiYnhangiatri1,5,10tươngưngvơitoT cđođi10mla1giay,5giay,10giay

• Tưđaysuyratapmơgiathatsư trenkhonggianne:n la

Y = {1,5,10} ∈ N, D = {01

,0.55

,1

10 }G = C × D X × Y

G = { 0(1,1)

,0

(14,1),

0(25,1)

,0

(40,1),

0(60,1)

,0

(100,1),

0(1,5)

,0

(14,5),

0(25,5)

,0.5

(40,5),

0.5(60,5)

,0.5

(100,5),

0(1,10)

,0

(14,10),

0(25,10)

,0.5

(40,10),

1(60,10)

,1

(100,10) }43

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Bàitập4• Đegiamđinhmotvienđaquy,ngươitacancưvaotronglương,kıchthươcvađotinhkhieT t,giasưkhonggianne:nnhưsau:

‣ Tronglương:cotapthamchieTu tınhba~ngcara

‣ Kıchthươc:tapthamchieTula

‣ ĐotınhkhieT tcungcotapthamchieTula

• TapmơgiatoT t( )cuavienđaquyphaidưatren3yeTutoT ;cha�nghan:tronglươnghơply( ),kıchthươcphuhơp( ),đotinhkhieT tcao .

• Vơi trenkhonggianne:nla

X ⊂ R+

Y = {1,2,3}Z = {1,5,10}

GA B (C)

G = A × B × C X × Y × Z

44

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Vídụ5

• GiaiphapphongbenhphoitoT tchongươitrelatiemvaccine• ChocacloaivaccinecumX={Vaxigrip,Fluarix,Amluria,Fluad}vavaccineCoVid-19Y={Pmizer,Moderna,AstraZenecca,Sputnik,Johson&Johson,Sinovac}

• Moh iloaicođactınhrieng,ca:nxacđinhgiaiphapphongbenhve: phoitoT tkhica:ntiemca2loaivaccinechongươitre.

• GiasưBlatapmơtoT tve: vaccineCoViD-19chongươitretuoi,AtapmơtoT tve: vaccinecumchongươitrecocacđothuocnhưsau:

45

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• ,

• TưđaycothechongiaiphaptoT tkhitiemca2vaccinechongươitrela:• Tapmơ trenkhonggianne:n cođothuocnhưsau:

A = {1/x1,1/x2,0.8/x3,0/x4} B = {1/y1,1/y2,0.8/y3,0.5/y4,0.6/y5,0/y6}

C = A × B X × YC = {1/(x1, y1),1/(x1, y2),0.8/(x1, y3),0.5/(x1, y4),0.6/(x1, y5),0/(x1, y6),

1/(x2, y1),1/(x2, y2),0.8/(x2, y3),0.5/(x2, y4),0.6/(x2, y5),0/(x2, y6),0.8/(x3, y1),0.8/(x3, y2),0.8/(x3, y3),0.5/(x4, y4),0.6/(x3, y5),0/(x3, y6),

0/(x4, y1),0/(x4, y2),0/(x4, y3),0/(x4, y4),0/(x4, y5),0/(x4, y6)}

46

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

MộtítvềPython

• Phienbanchınhthưcđangsưdung(June2021)laPython3.9.

• Cothecapnhattaihttps://www.python.org/downloads/source/

47

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

SửdụngPython

• DungơcheT đoconsolevơidonglenhtheokieuthongdich

48

• ThongquamotIDEnaođo,cha�nghanPyCharm

• Sưdungmottrınhsoanthaođơngian,cha�nghanNotePad(Windows),TextEdit(macOS),Nano(Linux)sauđobiendichvathưcthiơcheT đoCommandLine

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• HoacsưdungJupyter-Labđedunggiaodienwebba~ngcachkhơiđongJupyterServertrenmaycanhanthongquavieckhơiđongtrưctieTpjupyternotebook.

• Lưuy,đedungđươc,trươcđophaiinstallgoijupyter

49

• Khica:nsưdungnguo: ntainguyenaotreninternet,cothedungGoogleColabcotrongGoogleDrive

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Đethuanlơi,cacgoithưvientoT ithieuca:ncochohocpha:nđola:

• Numpyđesưdungcaccongcucuatoanhoctınhtoan,đaisoT tuyeTntınh

• Scikit-FuzzychonhưngAPIlienquanđeTntaphơpmơ

• Pandasđexưlydưlieudangbang• Matplotlibđetrưcquanhoadưlieu

50

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

TậphợpmờtrongPython

• Taphơpmơđươcxaydưngquahamthanhvien,trenmaytınhhamthanhvienchınhlagiatriphuthuoccuacacpha:ntưtrongkhonggianne:nlentapmơ.

• Tưđo,cothecoihamthanhvienlamangcacgiatricokıchthươcgioT ngvơimangkhonggianne:n.

• Cha�nghanvơitapmơphonghocrongAtrenkhonggianne:ncacphonghocvơiX = {30,50,75,90,100,125,150,200}

A = {(30,0), (50,0), (75,0), (90,0.2), (100,0.5), (125,0.8), (150,1), (200,1)}

51

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Trươctienca:nincludecacthưviensưdung

52

import numpy as np import matplotlib.pyplot as plt

• Sauđotaocacmangmotchie:ucho2taphơpXvaA.X = np.array( [30,50,75,90,100,125,150,200] ) A = np.array( [0,0,0,0.1,0.5,0.8,1,1] )

• Đehınhdung,cothetrưcquanhoathongquacachamcuaMatplotlib

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

plt.figure( figsize=(12,6) ) plt.title( "ĐỒ THỊ BIỂU DIỄN HÀM THUỘC CỦA TẬP MỜ" ) plt.plot( X,A,label="Tập mờ A = " + r"$\{\frac{0}{30},\frac{0}{50},\frac{0}{75},\frac{0.1}{90},\frac{0.5}{100},\frac{0.8}{125},\frac{1}{150},\frac{1}{200},\}$",color="blue",marker="+" ) plt.plot( X,B,label="Tập mờ B = " + r"$\{\frac{1}{30},\frac{1}{50},\frac{0.9}{75},\frac{0.8}{90},\frac{0.7}{100},\frac{0.3}{125},\frac{0.1}{150},\frac{0}{200},\}$",color="red",marker="*") plt.plot( X,C,label="Tập mờ C = " + r"$\{\frac{0}{30},\frac{0.3}{50},\frac{0.9}{75},\frac{1}{90},\frac{1}{100},\frac{0.9}{125},\frac{0.5}{150},\frac{0}{200},\}$",color="green",marker="o" ) plt.xlabel( "Không gian nền X = " + str(X) ) plt.ylabel( "Mức độ phụ thuộc: " + r"$\mu_A(x)$" ) plt.legend( loc="best" ) plt.show()

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Ơ� trendungJupyter.• TrongtrươnghơpthưcthiơcheT đodonglenh,cothelưucaclenhvaomottaptin-cha�nghanFuzzySetFromNumpy.pyvơinoidungnhưsau:

import numpy as np import matplotlib.pyplot as plt plt.figure( figsize=(12,6) ) plt.title( "ĐỒ THỊ BIỂU DIỄN HÀM THUỘC CỦA TẬP MỜ" ) plt.plot( X,A,label="Tập mờ A = " + r"$\{\frac{0}{30},\frac{0}{50},\frac{0}{75},\frac{0.1}{90},\frac{0.5}{100},\frac{0.8}{125},\frac{1}{150},\frac{1}{200},\}$",color="blue",marker="+" ) plt.plot( X,B,label="Tập mờ B = " + r"$\{\frac{1}{30},\frac{1}{50},\frac{0.9}{75},\frac{0.8}{90},\frac{0.7}{100},\frac{0.3}{125},\frac{0.1}{150},\frac{0}{200},\}$",color="red",marker="*") plt.plot( X,C,label="Tập mờ C = " + r"$\{\frac{0}{30},\frac{0.3}{50},\frac{0.9}{75},\frac{1}{90},\frac{1}{100},\frac{0.9}{125},\frac{0.5}{150},\frac{0}{200},\}$",color="green",marker="o" ) plt.xlabel( "Không gian nền X = " + str(X) ) plt.ylabel( "Mức độ phụ thuộc: " + r"$\mu_A(x)$" ) plt.legend( loc="best" ) plt.show()

55

• Lưuyra~ng,Jupytertaorataptincotenlaname.ipynb,khica:nchuyensangtaptinname.pydunglenh

jupyter nbconvert --to script name.ipynb

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Mởrộngthêm

• NhươVıdu2nhưngkhikhonggianne:ndayđachơn,đecođươchamthuoctươngưng,cothesưdunghamnoisuytronggoinumpyđecotapmơ

• Cha�nghan,thayvıXnhưtren,tadungkhonggianne:nYconhie:upha:ntưhơn,moh ipha:ntưcachnhau1giatri,tưđocothetaoratapmơBđươcnoisuytưXvaAba~ngcach

56

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science 57

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

ThưviệnScikit-Fuzzy

• LamottrongcacgoichưahamphobieTnnhaT tđegiaiquyeT tnhưngvaTnđe: cơbancuatapmơ,logicmơ.

• CothetımhieuchitieT ttaihttps://pythonhosted.org/scikit-fuzzy/overview.html

• Đeinstallhoacupgradegoinayvaoba~ngcachpython3-mpipinstallscikit-fuzzypython3-mpipinstall--upgradescikit-fuzzy

• Hoackiemtraphienbancapnhatcuacacgoiđainstallpython3-mpiplist—outdated

58

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

SửdụngScikit-Fuzzy

• TrươcheT t,ca:nincludethemgoithưvienskfuzzy,hoactưcacmoduletuytheoviecsưdungtrongchươngtrınh

• Cha�nghanđenoisuytapmơtrenkhonggianne:ndayđachơnnhưtrongvıdutrươc,sưdungcachamtrongmodulfuzzymath

• KhiđovahnnhanđươckeT tquanhưtrươnghơpdunghamnoisuyinterp()cuathưviennumpy.

59

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Mộtsốhàmthànhviêntrongskfuzzy

• Ơ� pha:ntrươcxaydưnghamthanhvientrencơsơmangdưlieulacacgiatrithuoc.KhidungScikit-Fuzzy,cungconhưnghamthanhvienđađươctaosa�ndươidangAPIcotrongthưvienđesưdung.

• Cha�nghan,hınhcongcuacacchưnhư ;hoactheohınhdangnhưhınhtamgiac,hınhthang,quachuong;hoactheođactınhnhưhamSigmoid,phanphoT iGauss,…

S, Z, Π

60

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Hàmsmf()

• Ham nayđetaohamthanhviencuatapmơtrenkhonggianne:nXvơiđo: thicopha:ntư cođothuocga:n0vapha:ntư cođothuocga:n1.

• HınhdangcuatapmơAvaBtrongchươngtrınhtrươccodangtươngtư,nencothevieT t:

‣ đeđa:uthaTpcuachưScogiatritieTnve: 0,conphıacaogiatritieTnve: 1

smf(X, a, b)a ∈ X b ∈ X

C = smf(X,75,150)

61

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• KeT tquatapmơCđươctrưcquanhoanhưhınh

62

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Tươngtưnhưvay,cohamthanhvienhınhdangchư ,chư trencungkhonggianne:nX: ,

Z Πzmf(X, a, b) pimf(X, a, b, c, d)

63

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Hamthanhviendanghınhtamgiac,hınhthang,hınhquachuongtrenkhonggianne:nX: , ,trongđo lahoanhđocua3đınhtamgiac; lahoanhđocua4đınhtaonenhınhthang

trimf(x, [a, b, c]) trapmf(X, [d, e, f, g] a, b, cd, e, f, g

64

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Hàmgbellmf(Y,u,v,a)

• Hamthanhvienhınhquachuong đươchienthưctưham

nhưlahamphoT ichuan(NormalDistrubution)đechı

sưphoT iđe:uđanđoT ixưngve: 2phıanhưquachuong.

• Đacđiem:

‣ ,hoac

‣ Vakhi

gbellmf(Y, u, v, a)μ(x) =

1

1 + x − au

2v

limx→a

μ(x) = 1 limu→∞

μ(x) = 1

x − au

> 1 & v → ∞ ⇒ μ(x) → 0

65

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• HamhınhquachuongvaphanphoT iGauss

66

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Quanhệmờ

• TrươckhiđivaolygiainhưngvaTnđe: trentapmơ,tanhınquamotchutvơinhưnggıđacotrongtaphơp.

• Khica:nxemxetđeTnmoT iquanhenaođogiưacacpha:ntưtrongtaphơpvơinhau,khainiemquanhehınhthanh.Hoacgiưacacpha:ntưcuataphơpnayvơitaphơpkhac.

• Cha�nghan,chotapcacsoT nguyen .ChobieT tcaccaptrongtap nayma .Khiđotacotapcaccap

X = {1,2,3,4,5} (a, b)X b |a

{(1,2),1,3,(1,4), (1,5), (2,4)}

67

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Rorangđaychınhlacacpha:ntưtrongtıchDescartes

• Kyhieula đechıXcoquanhe vơiY.

• Tưđaycothecoi lamotanhxađebieTncacpha:ntư thanhcaccap .

• Hay

• Trongvıdutren

X × X

XℜY ℜ

ℜ (x, y) ∈ (X, Y)(x, y) ∈ X × Y

ℜ : (X, Y) → X × Y

ℜ(X, X) = ℜ(X) = {(1,2),1,3,(1,4), (1,5), (2,4)}

68

Từđâychothấyquanhệgiữa2tậphợpcũngchínhlàtậphợp.Từđókháiniệmquanhệcóthểdùngtậphợpđểluậngiải

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Vídụ6

• Cho va tapconlamotquanhe2ngoigiưaX

vaY.

• Nhưvay,thayvıtıch cođa:yđu12pha:ntư,thıtapconcua naychıco7pha:ntư.

• Nencungcothehieura~ng:quanhegiưacactaphơpcunglamottaphơp(cha�nghantaphơpconnayco7pha:ntưcuataphơp12pha:ntư)

X = {a, b, c, d} Y = {α, β, γ}{(a, α), (a, γ), (b, α), (b, β), (c, β), (c, γ), (d, γ)}

X × Y X × Y

69

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Vơimotquanhe chotrươc(cha�nghanquanhetren2taphơp),ve: matlogictacothequyươcneTu2pha:ntưcoquanhevơinhau,thıchungcogiatrila1(giatriđung),conkhongthıchogiatrila0(giatrisai)

• Nhưvay,ham xacđinhđươctaT tcacaccap trongtap coquanhevơinhautheoquanhe .

• Lietkenhưvıdulamotcachbieudiehnquanhe nay,ronhaT tladungmatranđethehienvơiquyươckhipha:ntư coquanhevơi thıgiatrila1,ngươclaila0

fℜ : X × Y → {0,1} (a, b)X × Y ℜ

ℜx ∈ X y ∈ Y

70

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• NenvıdutrencothevieT tlaidươidangmatrannhưsau:

• Tưđay,thaychonhưnggiatrithuoctap{0,1},mơrongđecothelaTygiatritrongđoan khiđoconhưngkhainiemlienquanđeTnquanhemơ.

α β γabcd

1 0 11 1 00 1 10 0 1

[0,1]

71

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Chınhvınhưtren,nenkyhieu laanhxađechıquanhegiưa2tap ,neTunhındươigocđotaphơp,thıtacothedunglaikyhieu nayđediehntaquanhenhưlamotmatran

• Coi va ,

• Khibieudiehndươidangmatran,vieT tnhưtrongvıdutren

ℜ ⊂ X × YXvaY ℜ

xi ∈ X, ∀i = 1,r yi ∈ Y, ∀i = 1,k

ℜ = (rij) = {1,neTuxiℜyj

0,neTuxiℜyj, ∀i = i, r, j = j = 1,k

72

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Tưđochopheptamơrongkhicaccap coquanhevơinhautheoquanhe makhonghoantoanchınhxac,thıgiatricuahamnaythuoc .

• Noicachkhac,hamquanhenaycothevieT tmơrongtren2tap

• Tưđaytacoquanhemơ:lamoT ilienquangiưacactaphơpmơ.• Địnhnghĩa8(Quanhemơ):Chocackhonggianne:n ,quanhemơ trenkhonggianne:n lamottapconmơcuatıchDescartes .vơihamthuocđươcvieT tla

(a, b)ℜ [0,1]

X, Y

μℜ(x, y) = fℜ(x, y) : X × Y → [0,1]

Xi, ∀i ∈ 1,rℜ X1 × X2 × . . . × Xr

X1 × X2 × . . . × Xrμℜ : X1 × X2 × . . . × Xr → [0,1]

73

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Tínhchất3:Goi lacactapmơtươngưngtrencackhonggianne:n .Khiđotapmơ trenkhonggianne:n

cohamthuocla

• Đie:unaycothechưngminhdeh dangquaĐịnhnghĩa8ve: quanhemơvaĐịnhnghĩa7ve: hamthuoccuatıchDescartes

Ai, ∀i ∈ 1,rXi, ∀i ∈ 1,r A = A1 × A2 × . . . × Ar

X = X1 × X2 × . . . × XrμA(x) = min {μA1

(x1), μA2(x2), . . . , μAr

(xr)}, ∀x ∈ X

74

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Vídụ7

• Chokhonggianne:n lacacquoT cgiavala3loaivaccineve: WuhanCoronavirus.

• Goi laquanhethehienmưcđoquantamcuangươidantrong4quoT cgiatrong ve: cacvaccinetrong nhưsau:

X = {VI, EN, NE, CN}Y = {PF, AZ, SI}

ℜX Y

PF AZ SIVIENNECN

1 0.9 01 1 01 0.7 0.1

0.8 0.4 1

75

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Vídụ8

• ChoXlasanbaycuacacthanhphoT lơnX={Ca:nThơ(VCA),SaiGon(SGN),ĐaLat(DLI),NhaTrang(CXR),ĐaNa�ng(DAD),HueT (HUI),HaNoi(HAN),HaiPhong(HPH)}.Giasưvieccomaybaytrongmottua:n(7ngay)giưacacthanhphoT nhưsau:

‣ VCA-SGN:co4ngay,VCA-DLI:0,VCA-CXR:2,VCA-DAD:4,VCA-HUI:0,VCA-HAN:5,VCA-HPH:1

‣ SGN-DLI:5,SGN-CXR:4,SGN-DAD:7,SGN-HUI:3,SGN-HAN:7,SGN-HPH:4

76

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

‣ DLI-CXR:5,DLI-DAD:7,DLI-HUI:2,DLI-HAN:5,DLI-HPH:0‣ CXR-DAD:6,CXR-HUI:2,CXR-HAN:7,CXR-HPH:2‣ DAD-HUI:2,DAD-HAN:7,DAD-HPH:6‣ HUI-HAN:4,HUI-HPH:0‣ HAN-HPH:7

• NeTucoitrong7ngayđe:ucochuyeTnbaygiưa2thanhphoT lahơplynhaT t

77

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Thımatranquanhegiưacacsanbay(latapconcua )bieudiehndươidangmatrannhưsau:

X × X

VCA SGN DLI CXR DAD HUI HAN HPHVCASGNDLICXRDADHUIHANHPH

1 0.57 0 0.29 0.57 0 0.71 0.140.57 1 0.71 0.57 1 0.43 1 0.57

0 0.71 1 0.71 1 1 0.29 00.29 0.57 0.71 1 0.87 0.29 1 0.290.57 1 1 0.87 1 0.29 1 0.87

0 0.43 1 0.29 0.29 1 0.57 00.71 1 0.29 1 1 0.57 1 10.14 0.57 0 0.29 0.87 0 1 1

78

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Tưđaychungtacotherutraquanhe nhưngsanbaythươngxuyencocacchuyeTnbayqualaivơinhaulamatran:

1 0.57 0 0.29 0.57 0 0.71 0.140.57 1 0.71 0.57 1 0.43 1 0.57

0 0.71 1 0.71 1 1 0.29 00.29 0.57 0.71 1 0.87 0.29 1 0.290.57 1 1 0.87 1 0.29 1 0.87

0 0.43 1 0.29 0.29 1 0.57 00.71 1 0.29 1 1 0.57 1 10.14 0.57 0 0.29 0.87 0 1 1

79

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Phéptoántrêncácquanhệ

• Cho la2quanhetrentapthamchieTu(khonggianne:n)

• Vıquanhecunglataphơp,nentacungcocactınhchaT tsau:• Tínhchất4(phéptoánAND):

• Tínhchất5(phéptoánOR):

• Tínhchất6(phéptoánNOT):

ℜ1, ℜ2 X × Y

μℜ1∩ℜ2(x, y) = min {μℜ1

(x, y), μℜ2(x, y)}, ∀(x, y) ∈ X × Y

μℜ1∪ℜ2(x, y) = max {μℜ1

(x, y), μℜ2(x, y)}, ∀(x, y) ∈ X × Y

μ¬ℜ1(x, y) = μℜ1

(x, y) = 1 − μℜ1(x, y), ∀(x, y) ∈ X × Y

80

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Bàitập4

• Giasưngoaiquanhe ve: WuhanCoronavirusđađươcđưara,comotquanhe domottochưckhacđanhgianhưsau:

,

• TamuoT nphoT ihơpca2đanhgianayđecomotđanhgiachınhxachơnla

ℜ1ℜ2

ℜ1 =

1 0.9 01 1 01 0.7 0.1

0.8 0.4 1

ℜ2 =

1 0.8 00.9 1 01 0.7 0.1

0.8 0.6 0.8

81

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Liênkếtmờ

• Địnhnghĩa9:Cho3tapthamchieTu vơi2quanhemơ nhưsau:

,

QuanhelienkeT t cua2quanhenayla vơi

X, Y, Z P, Q

μP : X × Y → [0,1] μQ : Y × Z → [0,1]

L = P * Q μL : X × Y × Z → [0,1]μL(x, y, z) = min {μP(x, y), μQ(y, z)}

82

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Vídụ9

• Choquanhemơ giưangonngưsưdung vaquoT cgia , laquanhegiưaquoT cgia valoaiđo: ngtie:n

nhưsau:

,

P X = {English, French}Y = {England, France} Q Y

Z = {Pound, Euro}P = [1 0.2

0 1 ] Q = [ 1 0.10.2 0.8]

83

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• QuanhelienkeT tgiưangonngưsưdung,quoT cgiavaloaiđo: ngtie:nnhưbansau:

84

x y z P Q LEnglish England Pound 1 1 1English England Euro 1 0.1 0.1English France Pound 0.2 0.2 0.2English France Euro 0.2 0.8 0.2French England Pound 0 1 0French England Euro 0 0.1 0French France Pound 1 0.2 0.2French France Euro 1 0.8 0.8

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Hợpthànhmờ

• Địnhnghĩa10:Cho3tapthamchieTu vơi2quanhemơ cohamthuocla va ,phephơpthanhmơ cua2quanhenayla

vơi

Hay

X, Y, Z P, QμP μQ F = P ∘ Q

μF : X × Z → [0,1] μF(x, z) = max {μL(x, y, z)/y ∈ Y}, ∀(x, z) ∈ X × Z

μF(x, z) = maxy∈Y

{ min {μP(x, y), μQ(y, z)}}, ∀(x, z) ∈ X × Z

85

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• VơikeT tquatrongVıdu9,phephơpthanhmơtaoquanhegiưangonngưsưdungvaloaiđo: ngtie:nla

PoQ = [max{min{1,1}, min{0.2,0.2}} max{min{1,0.1}, min{0.2,0.8}}max{min{0,1}, min{1,0.2}} max{min{0,0.1}, min{1,0.8}} ]

PoQ = [max{1,0.2} max{0.1,0.2}max{0,0.2} max{0,0.8} ] = [ 1 0.2

0.2 0.8]

86

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Ảnhcủatậpmờ

• Địnhnghĩa12:Chotapmơ trenkhonggianne:n vamotanhxa.A� nhcua quaanhxa la ,hay theokyhieu

,trongđo

A Xf : X → Y A f B B = f(A)B = {y ∈ Y/y = f(x), ∀x ∈ A}

μB(y) = μf(A)(y) = μf(A)( f(x)) = max {μA(x)/y = f(x)}

87

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Vídụ10

• Xet vaham

• Taco quaanhxa la

• Xettap trenkhonggianne:n ,vơiAgo:m2pha:ntưla0va1.• Conghıala,pha:ntư0va1cođothuoc100%vaoA,con-2,-1,2cođothuocla0%.NenvieT tdươidanghamthuocla:

X = {−2, − 1,0,1,2} y = f(x) = |4x | + 2

Y f {10,6,2}

A X

μA(−2) = 0,μA(−1) = 0,μA(0) = 1,μA(1) = 1,μA(2) = 0

88

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• TưđaycothetınhđothuoctươngưngcuaBtrenYnhưsau:

μB(2) = max{μA(x)/2 = |4x | + 2}

= max{μA(x)/x = 0}= max{μA(0)}= 1

μB(6) = max{μA(x)/6 = |4x | + 2}

= max{μA(x)/x = 1,x = − 1}= max{μA(1), μA(−1)}= max{1,0}= 1

89

• Va

• Vay cocacpha:ntưla{2,6}

μB(10) = max{μA(x)/10 = |4x | + 2}

= max{μA(x)/x = 2,x = − 2}= max{μA(2), μA(−2)}= max{0,0}= 0

B

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Trênhàmlai(tíchDescartes)

• Tínhchất7:Choanhxa vơi latapmơtrenX,BlatapmơtrenY.GoiClaanhcuataptıch trenkhonggianne:nZ.Thı

• ĐayconđươcgoilanguyênlýmởrộngcuaZadeh

f : X × Y → Z AA × B

μC(z) = maxx∈X

{ min{μA(x), μB(y)}/z = f(x, y)}

90

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Trườnghợpflàánhxạmờ

• ThưcchaT tanhxalacunglamotquanhe,nen lamotanhxamơnghıalaxemxetanhcuamotquantapmơquanmotquanhemơ.

• A� nhcuamottapmơAtrenkhonggianne:nXlamottapmơcuakhonggianY.BaitoanđatralatımanhcuamottaphơpmơAquamotanhxamơf.

• Tínhchất8:Chomotquanhemơ ,khiđo,anhcuatapmơAlataphơpmơBthoaphephơpthanh ,trongđohamthuocla

f

ℜ : X × Y → [0,1]B = A ∘ ℜ

μB(y) = maxx∈X

{ min{μA(x), μA(y)}/B = A ∘ ℜ}

91

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Vídụ11:

• Tronglươngcuavatthechobơitapmơ

trenkhonggianne:n

• Quanhegiưatronglươngvachie:udaivatthechobơiquanhemơ :

A = {0.840

,1

50,

0.660

,0.270

,080 }

X = {40,50,60,70,80}

ℜ =

1 0.8 0.2 1 00.8 1 0.8 0.2 10.2 0.8 1 0.8 0.20.1 0.2 0.8 1 0.80 0.1 0.2 0.8 1

92

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Khiđochie:udaivattheđươcxacđinhbơitapmơ nhưsau:B = A ∘ ℜ

B = [0.8 1 0.6 0.2 0]o

1 0.8 0.2 1 00.8 1 0.8 0.2 10.2 0.8 1 0.8 0.20.1 0.2 0.8 1 0.80 0.1 0.2 0.8 1

= [0.8 1 0.8 0.8 1]

93

X = np.array( [40,50,60,70,80] ) A = np.array( [0.8,1,0.6,0.2,0] ) R = np.array( [[1.0,0.8,0.2,1.0,0.0], [0.8,1.0,0.8,0.2,1.0], [0.2,0.8,1.0,0.8,0.2], [0.1,0.2,0.8,1.0,0.8], [0.0,0.1,0.2,0.8,1.0]] ) B = fz.maxmin_composition( A,R )

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Vídụ12

• Chotapne:nX={x1,x2,x3},Y={y1,y2,y3},tapmơAA={(0.2/x1),(0.8/x2),(1/x3)}

• Vamatranquanhemơ nhưsau:

• HaytımtapmơBthoa

ℜ =0.7 1 0.40.5 0.9 0.60.2 0.6 0.3

A ∘ ℜ = B

94

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• LygiaichitieT tnhưsau:‣ Theophươngtrınhquanhemơ ,taco:

-

-

-

B = A ∘ ℜ

μB(y1) = μAoℜ(y1) = maxx∈X|

{min{μA(x), μℜ(x, y1)}}

μB(y2) = μAoℜ(y2) = maxx∈X|

{min{μA(x), μℜ(x, y2)}}

μB(y3) = μAoℜ(y3) = maxx∈X|

{min{μA(x), μℜ(x, y3)}}

95

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Tınhtoancuthehơn

μB(y1) = max { min{μA(x1), μℜ(x1, y1)}, min{μA(x2), μℜ(x2, y1)}, min{μA(x3), μℜ(x3, y1)}}= max { min{0.2,0.7}, min{0.8,0.5}, min{1,0.2}}= max {0.2,0.5,0.2}= 0.5

μB(y2) = max { min{μA(x1), μℜ(x1, y2)}, min{μA(x2), μℜ(x2, y2)}, min{μA(x3), μℜ(x3, y2)}}= max { min{0.2,1}, min{0.8,0.9}, min{1,0.6}}

= max {0.2,0.8,0.6}= 0.8

96

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Vay

μB(y3) = max { min{μA(x1), μℜ(x1, y3)}, min{μA(x2), μℜ(x2, y3)}, min{μA(x3), μℜ(x3, y3)}}= max { min{0.2,0.4}, min{0.8,0.6}, min{1,0.3}}= max {0.2,0.6,0.3}= 0.6

B = A ∘ ℜ = {0.5/y1,0.8/y2,0.6/y3}

97

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Vídụ13

• Chotapne:nX={x1,x2,x3,x4},Y={y1,y2,y3},tapmơAA={0.2/x1,0.4/x2,0.6/x3,1.0/x4}

• Vamatranquanhemơ cogiatri

• TımtapmơBthoa ={b1/y1,b2/y2,b3/y3}

ℜ =

0.1 0.6 0.80.6 0.8 0.60.8 0.6 0.50.0 0.5 0.5

A ∘ ℜ = B

98

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Taco

• VaytapmơBla(0.6/y1,0.6/y2,0.5/y3)

b1 = max { min{0.2,0.1}, min{0.4,0.6}, min{0.6,0.8}, min{1.0,0.0}}= max {0.1,0.4,0.6,0.0}= 0.6

b2 = max { min{0.2,0.6}, min{0.4,0.8}, min{0.6,0.6}, min{1.0,0.5}}= max {0.2,0.4,0.6,0.5}= 0.6

b3 = max { min{0.2,0.8}, min{0.4,0.6}, min{0.6,0.5}, min{1.0,0.5}}= max {0.2,0.4,0.5,0.5}= 0.5

99

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Vídụ14

• Chotapne:nX={x1,x2,x3,x4,x5},Y={y1,y2,y3,y4,y5},tapmơA={0/x1,0.5/x2,1/x3,0.5/x4,0/x5},B={0/y1,0.6/y2,1/y3,0.6/y4,0/y5}

• Haytaomatranquanhemơ kyhieu

• Tưđo,vơitapmơA’={0/x1,0.5/x2,0/x3,0/x4,0/x5}haytımtapmơ ,saocho

A ⇒ B ℜ

B′

B′ = A′ ∘ ℜ

100

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Cacpha:ntưcuamatranquanhemơ nhangiatri nhưsau:

• Ba~ngcachtren,

ℜ mini,j

{xi, yj}

ℜ =

0.0 0.0 0.0 0.0 0.00.0 0.5 0.5 0.5 0.00.0 0.6 1.0 0.6 0.00.0 0.5 0.5 0.5 0.00.0 0.0 0.0 0.0 0.0

B′ = {0/y1,0.5/y2,0.5/y3,0.5/y4,0/y5}

101

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Đetaoraquanhemơtincay,chungtaco

thetaphơpdưlieutưnhie:uquanhemơtınhđươc .

• Cha�nghan,chuyengiathưkcotrongsoT chuyengiala chocaccaptapmơ trenkhonggianne:ntươngưng.

ℜk

wkAk, Bk

102

A1 = np.array( [0.0,0.5,1.0,0.5,0.0] ) B1 = np.array( [0.0,0.6,1.0,0.6,0.0] ) A2 = np.array( [0.1,0.5,0.8,0.5,0.1] ) B2 = np.array( [0.0,0.6,1.0,0.6,0.0] ) A3 = np.array( [0.0,0.5,1.0,0.5,0.0] ) B3 = np.array( [0.2,0.7,0.9,0.6,0.2] )

R1 = fz.relation_min( A1,B1 ) R2 = fz.relation_min( A2,B2 ) R3 = fz.relation_min( A3,B3 )

w1, w2, w3 = 1, 3, 2 R = (w1*R1 + w2*R2 + w3*R3)/(w1 + w2 + w3)

• Nhưvıdusau

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Trựcquanhoáhàmmờcủaskfuzzy

• TronggoiScikit-FuzzycomotsoT hamve: cacpheptoancungnhưluathơpthanh.

• Cha�nghan,vơicactapmơve: tuoivađilainhưsau:

103

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• ThưchiencacpheptoanAND,ORtren2tapnayba~ngcach:

104

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Kháiniệmđiềukhiểnmờ• Đie:ukhienmơ(FuzzyControl)lamotlınhvưcưngdungđươcZadehđe: capđeTnnhưlanhưngưngdungđa:utien,ro: isauđođươccongđo: ngcacnhakhoahocChauA� uphattrien.

• ThưcchaT tđie:ukhienmơlađiềukhiểndựatrênlậpluậnmờ(FuzzyLogicControl).

• Nenmuctieucuađie:ukhienmơlaquanlycactieTntrınhtheomenhlenhthongquaviectacđonglencacđailươngmotatieTntrınhdựatrêntrithứcchuyêngiahoaccacnhàkỹthuậtcókinhnghiệm.

• Đolasưkhacbietsovơiđie:ukhienthongthươngchıdưatrencacthamsoT vatlythunhanđươc.

105

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Nguyentaf ccuađie:ukhienmơnhưhınh

106

• ConbentronghethoT ngmơ

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Nhưvay,cothenoiđie:ukhienlogicmơlamotcachtieTpcanheuristic(dodahm)macothedeh dangđưakieTnthưcvacacđactrưngtrongsuynghıcuaconngươivaoviecthieT tkeT cacbođie:ukhienphưctap

• HethoT ngnaykhongca:nphaithieT tlapmotmohınhtoanhocdươidangphươngtrınh,hephươngtrınh,motphieTmhamca:ntımcưctri,v.v...đetımthuatgiaitươngưng

• Machıca:ntuanthutheonhưngbươcnhưchomoibaitoan

107

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Đola:xacđinhcacbieTnđa:uvaovađa:uracuabođie:ukhienđemơhoa,xaydưngcactapmơ.TieTptheoladungcacluathayquytaf cđie:ukhienđươcxaydưngtheothuatngưcuangonngưtưnhien;ro: icuoT icunglagiaimơđetımragiatriro.

• Sơđo: cuamothethoT ngđie:ukhienmơnhưhınh

108

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Luậtmờ• ViecsuydiehnmơdưatrencacluatmơlavaTnđe: quantrong.• Cha�nghan,vơiquytaf csuydiễnkhẳngđịnhtronglapluancođien:

,trongđo:

‣ Luathoactrithưc: (conghıa lachanly)

‣ Cungsưkiencothat: (nghıala đung)‣ ThıkeT tluanđươc: lachanly

• Maluathaytrithưcthươngđươcdiehntaba~ngnhưngthuatngưmangtınhđinhtınh(luậtmờ)

((P ⇒ Q) ∧ P) ⇒ Q

P ⇒ Q P ⇒ Q

P P

Q

109

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Cha�nghan,cho vơiluat(mơ):

• Khicosưkienmơ xacđinhbơitapmơ trenkhonggianne:nXvavơiluatmơ thıcokeT tluanmơ vơi latapmơtrenkhonggianne:nY.

• Vıdu:Luatmơ la“cánhquạtquaynhanhthìgiónhiều”(doco2khainiemnhanhvanhiều)

‣ Luat:P=“cánhquạtquaynhanh”,Q=“giónhiều”‣ Sưkien:P=“cánhquạtquaynhanh”‣ KeT tluan:Q=“giónhiều”

P = {x = A}, Q = {y = B} P ⇒ Q

P′ = {x = A′ } A′

P ⇒ Q Q′ = {y = B′ } B′

P ⇒ Q

110

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Giơđaychıcosưkien,vơi =“cánhquạtquaykhánhanh”,thıcothekeT tluan “giókhánhiều”.

• Hienthưcba~ngngonngưcuataphơpmơ:‣ Ơ� đaycoquanhemơ trenkhonggianne:n vơihamthuoc

‣ Tưđay,vơitapmơ trenhammơ(quanhe )thı vơi

P′

Q′

ℜ = {P ⇒ Q} X × Yμℜ(x, y) = μP⇒Q(x, y) = min

(a,b)∈X×Y{μA(a), μB(b)}, ∀(x, y) ∈ X × Y

B′ ℜ B′ = A′ ∘ ℜμB′

(y) = maxa∈X

{min{μA′ (a), μℜ(a, y)}, ∀y ∈ Y

111

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Tươngtưnhưvay,vơiquytắcphủđịnh: vơisưkienmơ cokeT tluanmơ .

• Nenvơisưkienmơ ,cungvơiluatmơ ,thıcokeT tluanla

• Cha�nghan,cungvơiluatnhưtren: la“cánhquạtquaynhanhthìgiónhiều”,vavơisưkien“giókhôngnhiềulắm”thıkeT tluanla“cánhquạtquaykhôngnhanhlắm”

((P ⇒ Q) ∧ ¬Q) ⇒ ¬P¬Q ¬P

¬Q = {y = ¬B′ } P ⇒ Q¬P = {x = ¬A′ }

P ⇒ Q

112

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Bàitoánđiềukhiểnmờ• Đegiaibaitoanmơ,caclapluanmơdươidangcacluatmơthươnglienkeT tlaicungnhauquapheptoanluanly.

• Cha�nghan,cocacluat

• Trongđo lacactapmơtrenkhonggianne:n tươngưng.

x = A1 ⇒ y = B1x = A2 ⇒ y = B2. . .x = An ⇒ y = Bn

Ai, BiXi, Yi

113

• Moh iluatxacđinhmotquanhekeotheo( )giưa2tap tươngưng

• Tưđaycoquanhe mơđaidienchomotmotluat.

⇒ {Ai, Bi}

ℜ(Ai, Bi)

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Tínhchất9:Cactapmơ trongtie:nđe: cualuatđươcđactrưngbơiđothuoc ,khitie:nđe: cualuatgo:mnhie:uthanhpha:nkeT thơplaitheokieugomlaicuatıchDescartes ,thıđothuoccuaAla

• Cha�nghan,khiđanhgiamotvienđaquy,coluatmơ(Fuzzyrule)như:‣ Tronglươngcao,kıchthươclơnvatinhkhieT tthıgiacao.‣ Giasưco3tapmơ tươngưngvơitronglươngnang,kıchthươclơn,tinhkhieT tvagiacao.Thı

‣ Tưđodung lacancưnhưlatrongsoT cua đetınhtoan

AiμAi

A = A1 × A2 × . . . × AnμA(x) = min {μA1

(x1), μA2(x2), . . . , μAkn(xn)}

An, Bl, Ct, Gcμℜ(x) = min{μAc

(x1), μBl(x2), μCt

(x3)}μℜ μGc

(x)

114

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Vídụ15

• Motbaitoanthongdungthươnghayđươcminhhoachone:ntangđie:ukhienmơđolaxacđinhthơigiangiat(T)khibieT tđoban(D)valươngda:umơdınhtrenqua:nao(G).

• Thongthươngcacdưlieunaythuđươctưcacsensorquanghoc.• Giasưra~ng vaGcotapthamchieTu(haykhonggianne:n)la[0,100];conTcotapthamchieTula[0,60]

• Lapluanmơvơiquytaf c:“bẩnvàdầumởnhiềuthìgiặtlâu”.

D

115

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Bươcđa:utienđegiaiquyeT t,lathưchiencaccongviecmơ:‣ Xaydưngcactapmơ:- Banıt ,banvưa ,bannhie:u

- Da:umơıt( ),da:umơvưaphai( ),da:umơnhie:u( )

- ThơigiangiatraT tnhanh(veryfast) ,nhanh ,thơigiantrungbınh,lau ,raT tlau (verylong)

Ds Dm Dl

Gs Gm Gl

Tf TsTm Tl Tv

116

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Ba~ngPython:

117

import numpy as np import skfuzzy as fz import matplotlib.pyplot as plt

X = np.arange(0,101,1) Ds = fz.trimf( X,[0,0,50] ) Dm= fz.trimf( X,[0,50,100] ) Dl = fz.trimf( X,[50,100,100] )

plt.title( "CÁC TẬP MỜ VỀ ĐỘ BẨN" ) plt.plot( X, Ds, label = "Bẩn ít" ) plt.plot( X, Dm, label = "Trung bình" ) plt.plot( X, Dl, label = "Bẩn nhiều" ) plt.xlabel("Không gian nền X" + r"$\in [0,100]$") plt.legend(loc="best") plt.show()

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science 118

import numpy as np import skfuzzy as fz import matplotlib.pyplot as plt

### Định nghĩa tập mờ Y = np.arange(0,101,1) Gs = fz.trimf( Y,[0,0,50] ) Gm = fz.trimf( Y,[0,50,100] ) Gl = fz.trimf( Y,[50,100,100] )

### Vẽ đồ thị 3 hàm thuộc tương ứng plt.title( "CÁC TẬP MỜ VỀ LƯỢNG DẦU MỠ" ) plt.plot( Y, Gs, label = "Dầu mở ít" ) plt.plot( Y, Gm, label = "Dầu mở vừa phải" ) plt.plot( Y, Gl, label = "Dầu mở nhiều" ) plt.xlabel( "Khộng gian nền $Y \in [1,100]$" ) plt.legend( loc="best" ) plt.show()

• Tươngtưnhưđoban,cachamthanhvienve: lươngda:umơbamvaoaoqua:ncothenoisuyđehınhdung,hoacsưdungkhicodưlieudayđac.

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science 119

import numpy as np import skfuzzy as fz import matplotlib.pyplot as plt

Z = np.array( [0,4,18,32,46,60] ) Tf = fz.trapmf( Z,[0,0,4,18] ) Ts = fz.trimf( Z,[4,18,32] ) Tm = fz.trimf( Z,[18,32,46] ) Tl = fz.trimf( Z,[32,46,60] ) Tv = fz.trimf( Z,[46,60,60] )

plt.title( "CÁC TẬP MỜ VỀ THỜI GIAN GIẶT" ) plt.plot( Z, Tf, label = "Rất nhanh" ) plt.plot( Z, Ts, label = "Nhanh" ) plt.plot( Z, Tm, label = "trung bình" ) plt.plot( Z, Tl, label = "Lâu" ) plt.plot( Z, Tv, label = "Rất lâu" ) plt.xlabel( "Khộng gian nền $Z \in [0,60]$" ) plt.legend( loc="best" ) plt.show()

• Tươngtưnhưvaychocactapmơve: thơigian:

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• ChitieT tcacluatưngvơinhưngtapmơcuthe,ơđayco3tapmơve: đobanva3tapmơve: lươngda:umơdınhtrenqua:nao.

• Luat‣ (R1):NeTubannhie:uvada:umơnhie:uthıthơigiangiatraT tlau‣ (R2):NeTubanvưavada:umơnhie:uthıthơigiangiatlau‣ (R3):NeTubanıtvada:umơnhie:uthıthơigiangiatlau‣ (R4):NeTubannhie:uvada:umơvưaphaithıthơigiangiatlau‣ (R5):NeTubanvưavada:umơvưaphaithıthơigiangiattrungbınh‣ (R6):NeTubanıtvada:umơvưaphaithıthơigiangiattrungbınh

120

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

‣ (R7):NeTubannhie:uvada:umơıtthıthơigiangiattrungbınh‣ (R8):NeTubanvưavada:umơıtthıthơigiangiatnhanh‣ (R9):NeTubanıtvada:umơıtthıthơigiangiatraT tnhanh

• Co quanhemơbieudiehndươidangbangnhưsau:3 × 3 = 9

121

Ds Dm Dl

Gs Tf Ts Tm

Gm Tm Tm Tl

Gl Tl Tl Tv

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Giasưca:nbieT tthơigiangiatkhicođobanvalươngda:umơbamvaoaoqua:nla .

• Trencơsơcachamthanhvien,tasuyra ,

.

• Ba~ngPython,cothevieT t

x0, y0

μDs(x0), μDm

(x0), μDl(x0)

μGs(y0), μGm

(y0), μGl(y0)

122

x0, y0 = 40, 60 xs = fz.interp_membership( X,Ds,x0 ) xm = fz.interp_membership( X,Dm,x0 ) xl = fz.interp_membership( X,Dl,x0 )

ys = fz.interp_membership(Y,Gs,y0) ym = fz.interp_membership(Y,Gm,y0) yl = fz.interp_membership(Y,Gl,y0)

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

w1 = min {μDl(x0), μGl

(y0)}w2 = min {μDm

(x0), μGl(y0)}

w3 = min {μDs(x0), μGl

(y0)}

• TieTptheo,ca:ntımhamthuocveT thơigian,hamthuocnayđươctımba~ngcachcancưvao5hamthuoc,sưanhhươngcua5hamthuocnaycancưvaotrongsoT nhaT tđinhtheodang:

• NhưnghesoT đươctınhtư9luatquyđinhơtrennhưsau:

wi

μT(z) = w1μv(z) + w2μl(z) + w3μl(z) + w4μl(z)+w5μm(z) + w6μm(z) + w7μm(z) + w8μs(z) + w9μf(z)

wi

123

w4 = min {μDl(x0), μGm

(y0)}w5 = min {μDm

(x0), μGm(y0)}

w6 = min {μDs(x0), μGm

(y0)}

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• ĐehienthưctrongPython,vơicachesoT đươctınhquahammin().

wi

124

w7 = min {μDl(x0), μGs

(y0)}w8 = min {μDm

(x0), μGs(y0)}

w9 = min {μDs(x0), μGs

(y0)}w1 = min( xl,yl ) w2 = min( xm,yl ) w3 = min( xs,yl ) w4 = min( xl,ym ) w5 = min( xm,ym ) w6 = min( xs,ym ) w7 = min( xl,ys ) w8 = min( xm,ys ) w9 = min( xs,ys )

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• SaukhitınhxonghesoT ,tımhamthuocve: thơigian

125

• Viecgiaimơvơikhonggianne:nhưuhanđươctınhtheotrungbınhco

trongsoT : ,trươnghơpkhongrơirac:z =∑N

i=1 zμT(z)

∑Ni=1 μT(z)

z =∫ zμT(z)dz∫ μT(z)dz

T = w1*Tv + (w2+w3+w4)*Tl + (w5+w6+w7)*Tm + w8*Ts + w9*Tf

### Tử số là tích của Z với chuyển vị của T t0 = Z.dot(T.T)/T.sum()

• Vơix0=40,y0=60,tatınhđươct0-36.• Đie:uđoconghıalavơiđobanla40,lươngda:umơbamtrenqua:naola60,thıthơigiangiatla36

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Cunglưuy,tronggoithưvienskfuzzy,cohamgiaimơskfuzy.defuzz(X,mf,mode),nencothegoitrưctieTpthayvıphaitınhcactong:

126

t0 = fz.defuzz( Z,T,"centroid" )

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Vídụ16

• Ca:nmothethoT ngđie:ukhientưđongbơmnươctưbebendươi(cistern)lenbo: nchưanươc(tank)trencao.

• Giasưbevabo: ncodungtıchla ,thơigianbơmtoT iđala30phut.

• Co3tınhtrangnươctrongbe:đa:ynươc( ),convưađedung( )vabega:ncan( )

• Vơibo: ntrencao,co2tınhtrang:connươc( )vađaga:nheT t( )

• Conthơigian,cothe3trangthai:bơmlau(L),bơmvưaphai(M)vabơmnhanh(S)

2m3

Cf CmCe

Tf Te

127

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Tưđay,cothethieT tlapcachamthuocchonhưngtapmơtươngưngve: benươc(Cistern)vabo: nchưa(Tank)nhưsau:

μCf(x) = {0, 0 ≤ x ≤ 1

x − 1, 1 ≤ x ≤ 2

μCm(y)) = {x, 0 ≤ x ≤ 1

2 − x, 1 ≤ x ≤ 2

μCe(x) = {1 − x, 0 ≤ x ≤ 1

0, 1 ≤ x ≤ 2

128

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Đecocainhıntrưcquan,cotheveđo: thiba~ngcach

129

C = np.linspace( 0,2 ) Cf = [MuCf(x) for x in C] Cm = [MuCm(x) for x in C] Ce = [MuCe(x) for x in C]

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Cachamthuocchonhưngtapmơve: bo: nchưa(Tank)nhưsau:

μTf(y) = {y, 0 ≤ y ≤ 1

1, 1 ≤ y ≤ 2

μTe(y) = {1 − y, 0 ≤ y ≤ 1

0, 1 ≤ y ≤ 2

130

def MuTf(y): if 0 <= y and y <= 1: return y elif 1 <= y and y <= 2: return 1 def MuTe(y): if 0 <= y and y <= 1: return 1 - y elif 1 <= y and y <= 2: return 0

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science 131

T = np.linspace( 0,2 ) Tf = [MuTf(y) for y in T] Te = [MuTe(y) for y in T]

plt.plot( T, Tf ) plt.plot( T, Te ) plt.show()

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Ve: thơigian:

μL(t) = {0, 0 ≤ t ≤ 20t − 20

10 , 20 ≤ t ≤ 30

μM(t) =

t10 , 0 ≤ t ≤ 101, 10 ≤ t ≤ 2030 − t

10 , 20 ≤ t ≤ 30

μS(t) = {1 − t10 , 0 ≤ t ≤ 10

0, 10 ≤ t ≤ 30

132

def MuL(t): if 0 <= t and t <= 20: return 0 elif 20 <= t and t <= 30: return (t - 20)/10

def MuM(t): if 0 <= t and t <= 10: return t/10 elif 10 <= t and t <= 20: return 1 elif 20 <= t and t <= 30: return (30 - t)/10

def MuS(t): if 0 <= t and t <= 10: return 1 - t/10. elif 10 <= t and t <= 30: return 0

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science 133

Tg = np.linspace( 0,30 ) L = [MuL(t) for t in Tg] M = [MuM(t) for t in Tg] S = [MuS(t) for t in Tg]

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• TieTptheo,ca:ncacluatmơtheoquytaf c"nướctrênbồnhếtnhiềuthìbơmlâu".

‣ (R1):NeTubo: nconđa:y( )vadươibeđa:y( )thıbơmıt(S)

‣ (R2):NeTubo: nconđa:y( )vadươibeconvưa( )thıbơmıt(S)

‣ (R3):NeTubo: nconđa:y( )vadươibeđaga:ncan( )thıbơmıt(S)

‣ (R4):NeTubo: nđaga:nheT t( )vadươibeđa:y( )thıbơmlau(L)

‣ (R5):NeTubo: nđaga:nheT t( )vadươibeconvưa( )thıbơmvưa(M)

‣ (R6):NeTubo: nđaga:nheT t( )vadươibega:ncan( )thıbơmıt(S)

Tf Cf

Tf Cm

Tf Ce

Te Cf

Te Cm

Te Ce

134

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• VaTnđe: đatra:khibo: ncon vabeco ,thımaybơmhoatđongvơithơigian baolau.

• Đethưchienviecnay,ca:ntınhcactrongsoT laminimumgiưacaccapmơve: tınhtrangnươctrongbo: nvatrongbecancưvao6luatmơơtrenđecocaccapquanhe

y0 x0t0

135

w1 = min {μTf(y0), μCf

(x0)}w2 = min {μTf

(y0), μCm(x0)}

w3 = min {μTf(y0), μCe

(x0)}

w4 = min {μTe(y0), μCf

(x0)}w5 = min {μTe

(y0), μCm(x0)}

w6 = min {μTe(y0), μCe

(x0)}

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Hienthưcba~ngPythonchocactrongsoT nay

136

• Tưđay,cungdưatrencacluatmơđecohamthuocve: thơigianbơmnươc

x0,y0=1.2,5w1=min(MuTf(y0),MuCf(x0))w2=min(MuTf(y0),MuCm(x0))w3=min(MuTf(y0),MuCe(x0))w4=min(MuTe(y0),MuCf(x0))w5=min(MuTe(y0),MuCm(x0))w6=min(MuTe(y0),MuCe(x0))

defT(t):returnw1*MuS(t)+w2*MuS(t)+w3*MuS(t)+w4*MuL(t)+w5*MuM(t)+w6*MuS(t)

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Đetımrathơigianbơmkhichotrươc ,tatınhtrungbınhcotrongsoT

dưavaotıchphan

• Ba~ngPython

(x0, y0)

t0 =∫ 30

0zμT(z)dz

∫ 300

μT(z)dz

137

from scipy.integrate import quad def Tmp(t): return t*MuT(t)

tu,_ = quad( Tmp,0,30 ) mau,_ = quad( MuT,0,30 ) t0 = tu/mau print("Bồn có %.1f m3 và bể có %.1f m3, thời gian bơm: %.2f phút" % (y0,x0,t0))

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Giảibàitoánđiềukhiểnmờdùngskfuzzy• TongkeT tlai,cocacbươcchitieT tsauđay:‣ Xacđinhmie:nxacđinhcuacachamthuoc(lakhonggianne:n)‣ Xaydưngnhưngtapmơcotrongtie:nđe: cuacacluatmơ‣ Đưaluatmơvao‣ Nhapgiatrinhưladưlieunhapđe: suyđoankeT tquađa:uracotrongcackeT tluancualuatmơ

‣ TınhcactrongsoT dưavaonhưngluatmơ‣ ThieT tlaphamthanhvienve: giatrica:nsuyđoan‣ Tınhgiatrica:nsuyđoan

139

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Bàitập• Quaytrơlaivơibaitoangiamđinhđaquy.‣ Tronglương:raT tnang,nang,hơinang,nhe,quanhetrongmie:nxacđinh[0,100]

‣ Kıchthươc:raT tlơn,lơn,vưa,nho;mie:nxacđinh[0,1]‣ ĐotinhkhieT t:raT ttinhkhieT t,tinhkhieT t,đươc,te,quate;mie:nxacđinh[0,1]

‣ Gia:raT tcao,cao,vưaphai,thaTp,re;mie:nxacđinh[1,1000]‣ LuatmơdưatrenyeTutoT "trịgiácủaviênđáquýtỷlệthuậnvớitrọnglượng,kíchthướcvàđộtinhkhiết"

140

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Bàitập• Đie:ukhienmayđie:uhoakhongkhıtrongphongdưatrennhietđotrongvangoaiphongcungnhưsoT ngươicotrongphongtheoquytaf c:

‣ NeTuphongconhie:ungươi,trơinongthımayơcheT đolanh‣ NeTuphongconhie:ungươi,trơibınhthươngthımayơcheT đobınhthương‣ NeTuphongıtngươi,trơinongthımayơcheT đobınhthương‣ NeTuphongıtngươi,trơilanhthımayơcheT đonong‣ MotsoT rangbuoc:- Ngươi={2,3,5,8,12,17,23}- Nhietđotrogphongvangoaitrơi={15,20,25,30,35,40}- Mưcđie:uchınhtrenmay=[16,30]

141

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

HiệnthựcquathưviệnScikit-Fuzzy• TrongthưviecScikit-FuzzyconhưngmoduleraT tthuanlơichoviecxưly,chungtachıca:ntua:ntưtheocacbươcsauđaylacođươcmothethoT nghoanchınh.

‣ Bước1:Xaydưngkhonggianne:ntươngưng(dungmangnumpy.array([])đelưutrư).

‣ Bước2:Xacđinhđaulataptie:nđe: đaulatapkeT tluanquahamtrongmodulecontrol:fuzzy.control.Antecendent([],_),fuzzy.control.Consequent([],_)

‣ Bước3:Cothedungnumpy.arange(_,_,_)haynumpy.array([])đetaotapmơ,hoacdungmottrongcachamthanhviennhưfuzzy.trimf([],[]),fuzzy.trapmf([],[]),fuzzy.gbellmf([],[]),v.v...

142

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

‣ Bước4:Dungđeđưacacluatrulesvaoba~ngfuzzy.control.Rule(.,.)‣ Bước5:Taomohınh(model)suydiehnvơifuzzy.control.ControlSystemSimulation(fuzzy.control.ControlSystem(rules))

‣ Bước6:Nhapdưlieunhưlasưkienca:nsuyđoanthongquaphươngthưcinput()tưmodelơtren,ro: idungphươngthưccompute()đexưlysauđoxuaT tkeT tquaba~ngphươngthưcoutput()

143

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Vídụ17• QuaylaiVıdu15,cothevieT tchươngtrınhnhưsau:

144

### Xây dựng không gian nền tương ứng X = np.arange(0,101,1) Y = X Z = np.array( [0,4,18,32,46,60] )

### Xác định tiền đề và kết luận D = ctrl.Antecedent( X,"Độ bẩn" ) G = ctrl.Antecedent( Y,"Lượng dầu mở" ) T = ctrl.Consequent( Z,"Thời gian giặt" )

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

### Các tập mờ D["Bẩn ít"] = fz.trimf( D.universe,[0,0,50] ) D["Trung bình"] = fz.trimf( D.universe,[0,50,100] ) D["Bẩn nhiều"] = fz.trimf( D.universe,[50,100,100] )

G["Dầu mở ít"] = fz.trimf( G.universe,[0,0,50] ) G["Dầu mở vừa phải"] = fz.trimf( G.universe,[0,50,100] ) G["Dầu mở nhiều"] = fz.trimf( G.universe,[50,100,100] )

T["Rất nhanh"] = fz.trapmf( T.universe,[0,0,4,18] ) T["Nhanh"] = fz.trimf( T.universe,[4,18,32] ) T["Trung bình"] = fz.trimf( T.universe,[18,32,46] ) T["Lâu"] = fz.trimf( T.universe,[32,46,60] ) T["Rất lâu"] = fz.trimf( T.universe,[46,60,60] )

• Cactapmơtươngưng(Bươc3)

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Đưaluat(Bươc4)vataomohınh(Bươc5)### Đưa các luật vào R1 = ctrl.Rule( D["Bẩn ít"] & G["Dầu mở ít"], T["Rất nhanh"] ) R2 = ctrl.Rule( D["Bẩn ít"] & G["Dầu mở vừa phải"], T["Trung bình"] ) R3 = ctrl.Rule( D["Bẩn ít"] & G["Dầu mở nhiều"], T["Lâu"] ) R4 = ctrl.Rule( D["Trung bình"] & G["Dầu mở ít"], T["Nhanh"] ) R5 = ctrl.Rule( D["Trung bình"] & G["Dầu mở vừa phải"], T["Trung bình"] ) R6 = ctrl.Rule( D["Trung bình"] & G["Dầu mở nhiều"], T["Lâu"] ) R7 = ctrl.Rule( D["Bẩn nhiều"] & G["Dầu mở ít"], T["Trung bình"] ) R8 = ctrl.Rule( D["Bẩn nhiều"] & G["Dầu mở vừa phải"], T["Lâu"] ) R9 = ctrl.Rule( D["Bẩn nhiều"] & G["Dầu mở nhiều"], T["Rất lâu"] )

### Tạo mô hình đề suy diễn model = ctrl.ControlSystemSimulation(ctrl.ControlSystem([R1,R2,R3,R4,R5,R6,R7,R8,R9]))

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Xưlytrendưlieunhapro: ixuaT tkeT tqua(Bươc6)

### Đưa dữ liệu vào để xử lý rồi xuất kết quả B = float(input( "Độ bẩn của áo quần: " )) C = float(input( "Lượng dầu mở dính : " ))

model.input["Độ bẩn"] = B model.input["Lượng dầu mở"] = C

model.compute() D = model.output["Thời gian giặt"] print( "Với %.2f độ bản và %.2f lượng dầu mở trên áo quần, thời gian giặt là %2.f phút" % (B,C,D) )

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Noithem,chungtacothedungcachamthanhvienkhacnhưsau,cha�nghandunghamdangphanboGausschoDve: đobanvaGlươngda:umơ.

149

D["Bẩn ít"] = fz.gaussmf( D.universe,0,8 ) D["Trung bình"] = fz.gaussmf( D.universe,50,12 ) D["Bẩn nhiều"] = fz.gaussmf( D.universe,100,8 ) D.view()

G["Dầu mở ít"] = fz.gaussmf( G.universe,0,8 ) G["Dầu mở vừa phải"] = fz.gaussmf( G.universe,50,12 ) G["Dầu mở nhiều"] = fz.gaussmf( G.universe,100,8 ) G.view()

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Lưuy,ngoaiviecdunghamview()khidungscikit-fuzzy,đetrưcquanhoacachamthuoc,chungtacungcothedungtheocachtruye:nthoT ngđevehınh

151

plt.plot( D.universe, fz.gaussmf(D.universe,0,8)

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Vídụ18• Vơivıdu16ve: bơmnươctưbechưalenbo: nbentren

152

### Xây dựng không gian nền tương ứng C = np.arange( 0,2.01,0.01 ) T = np.linspace( 0,2 ) Tg = np.linspace( 0,30 )

### Xác định tiền đề và kết luận Cistern = ctrl.Antecedent( C, "Bề chứa" ) Tank = ctrl.Antecedent( T, "Bồn" ) Time = ctrl.Consequent( Tg, "Thời gian" )

### Các tập mờ Cistern["Đầy"] = fz.trimf( Cistern.universe,[1,2,2] ) Cistern["Còn nước"] = fz.trimf( Cistern.universe,[0,1,2] ) Cistern["Gần cạn"] = fz.trimf( Cistern.universe,[0,0,1] )

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science 153

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Tank["Đầy"] = fz.trapmf( Tank.universe,[0,1,2,2] ) Tank["Gần hết"] = fz.trimf( Tank.universe,[0,0,1] )

Time["Bơm lâu"] = fz.trimf( Time.universe,[20,30,30] ) Time["Vừa phải"] = fz.trapmf( Time.universe,[0,10,20,30] ) Time["Bơm nhanh"] = fz.trimf( Time.universe,[0,0,10] )

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Ơ� đay,đehơply"khinướcởtrênbồnđầythìkhôngcầnphảibơm".Nhưngdokhongcoluatnaymachıcoluat"khinướcởtrênbồnđầybơmnhanh".Nenđehienthưcđie:unaychungtachontheoluatla"Bơmnhanh",nhưngvơihesoT la0%

155

### Đưa các luật vào R1 = ctrl.Rule( Tank["Đầy"] & Cistern["Đầy"], Time["Bơm nhanh"]%.0 ) R2 = ctrl.Rule( Tank["Đầy"] & Cistern["Còn nước"], Time["Bơm nhanh"]%.0 ) R3 = ctrl.Rule( Tank["Đầy"] & Cistern["Gần cạn"], Time["Bơm nhanh"]%.0 ) R4 = ctrl.Rule( Tank["Gần hết"] & Cistern["Đầy"], Time["Bơm lâu"] ) R5 = ctrl.Rule( Tank["Gần hết"] & Cistern["Còn nước"], Time["Vừa phải"] ) R6 = ctrl.Rule( Tank["Gần hết"] & Cistern["Gần cạn"], Time["Bơm nhanh"] )

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• TieTptheolanhapdưlieuvaođexưlysauđođưakeT tquara

156

a = float(input( "Mực nước trong bể chứa là [0,2]: " )) model.input["Bề chứa"] = x b = float(input( "Mực nước bồn trên cao là [0,2]: " )) model.input["Bồn"] = b c = model.compute() print( "Thời gian bơm là ",c," phút" )

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Vídụ19• Xaydưngmotbođie:uchınhmaylanhtưđongcancưvaosoT ngươicotrongphong,nhietđotrongphongvanhietđobenngoaiphong.

• Cacbươcơtrencothegomthanhcacgiaiđoan:‣ Giaiđoạn1:Dưlieunhapvamie:ngiatriđetaobotie:nđe: vakeT tqua- Nhap• SoT ngươitrongphong

• Nhietđotrongphong

• Nhietđongoaitrơi

N = [1,10] ∈ ℕ

Tin = [18,30] ∈ ℕ

Tout = [20,40] ∈ ℕ

158

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

- XuaT t:• Mưcđie:uchınh

• Ba~ngPythonL = [18,27] ∈ ℕ

159

### Tạo 2 không gian nền Tiền đề và 1 không gian nền Kết luận X = np.arange( 1,11,1 ) Y = np.arange( 18,31,1 ) Z = np.arange( 20,41,1 ) W = np.arange( 18,28,1 )

N = ctrl.Antecedent( X,"So nguoi" ) Tin = ctrl.Antecedent( Y,"Nhiet do trong phong" ) Tout = ctrl.Antecedent( Z,"Nhiet do ngoai troi" ) L = ctrl.Consequent( W,"Muc dieu chinh" )

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Giaiđoạn2:xaydưngcactapmơ‣ Sốngười:co4tapmơ- I{tngươi- Trungbınh- Nhie:ungươi- RaT tnhie:u

160

N["It nguoi"] = fz.trapmf( N.universe,[1,1,2,3] ) N["Trung binh"] = fz.trapmf( N.universe,[2,3,5,6] ) N["Nhieu nguoi"] = fz.trapmf( N.universe,[5,6,7,8] ) N["Rat nhieu"] = fz.trapmf( N.universe,[7,8,10,10] ) N.view()

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Tin["Lanh"] = fz.trapmf( Tin.universe,[18,18,19,21] ) Tin["Vua"] = fz.trapmf( Tin.universe,[20,22,25,27] ) Tin["Nong"] = fz.trapmf( Tin.universe,[26,28,30,30] ) Tin.view()

‣ Nhiệtđộtrongphòng:co3tapmơ

- Lanh- Vưa- Nong

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

‣ Nhiệtđộngoàitrời:co4tapmơ:- Lanh- Vưa- Nong- RaT tnong

162

Tout["Lanh"] = fz.trapmf( Tout.universe,[20,20,21,22] )Tout["Vua"] = fz.trapmf( Tout.universe,[21,23,26,28] )Tout["Nong"] = fz.trapmf( Tout.universe,[27,29,34,36] )Tout["Rat nong"] = fz.trapmf( Tout.universe,[35,38,40,40] )Tout.view()

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

‣ Mứcđiềuchỉnh:co5tapmơ:- RaT tthaTp- ThaTp- Trungbınh- Cao- RaT tcao

163

L["Rat thap"] = fz.trimf( L.universe,[18,18,20] )L["Thap"] = fz.trimf( L.universe,[19,20,22] )L["Trung binh"] = fz.trapmf( L.universe,[21,22,23,24] )L["Cao"] = fz.trapmf( L.universe,[23,24,25,26] )L["Rat cao"] = fz.trapmf( L.universe,[25,26,27,27] )L.view()

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Giaiđoạn3:Luatmơdangifthenđươcrutratheoquytaf ccua"chuyengia"nhưsau:

‣ NeTunhietđocangnongthımưcđie:uchınhphaithaTp.‣ Nhietđo(cabenngoailahnbentrong)tylethuanvơisoT ngươicotrongphong

‣ Ba~ngngonngưPython(khongphaingonngưtưnhiennhưbınhthương)cacluatnayđươcvieT tdươidangnhưsau:

- R=ctrl.Rule(N[""]&Tin[""]&Tout[""],L[""])

164

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science 165

R1_2 = ctrl.Rule( N["It nguoi"] & Tin["Lanh"] & (Tout["Lanh"] | Tout["Vua"]), L["Rat cao"] )R3_4 = ctrl.Rule( N["It nguoi"] & Tin["Lanh"] & (Tout["Nong"] | Tout["Rat nong"]), L["Cao"] )R5 = ctrl.Rule( N["It nguoi"] & Tin["Vua"] & Tout["Lanh"], L["Rat cao"] )R6_7 = ctrl.Rule( N["It nguoi"] & Tin["Vua"] & (Tout["Vua"] | Tout["Nong"]), L["Cao"] )R8 = ctrl.Rule( N["It nguoi"] & Tin["Vua"] & Tout["Rat nong"], L["Trung binh"] )R9 = ctrl.Rule( N["It nguoi"] & Tin["Nong"] & Tout["Lanh"], L["Cao"] )R10_11 = ctrl.Rule( N["It nguoi"] & Tin["Nong"] & (Tout["Vua"] | Tout["Nong"]), L["Trung binh"] )R12 = ctrl.Rule( N["It nguoi"] & Tin["Nong"] & Tout["Rat nong"], L["Thap"] )

R13_14 = ctrl.Rule( N["Trung binh"] & Tin["Lanh"] & (Tout["Lanh"] | Tout["Vua"]), L["Rat cao"] )R15 = ctrl.Rule( N["Trung binh"] & Tin["Lanh"] & Tout["Nong"], L["Cao"] )R16 = ctrl.Rule( N["Trung binh"] & Tin["Lanh"] & Tout["Rat nong"], L["Trung binh"] )R17 = ctrl.Rule( N["Trung binh"] & Tin["Vua"] & Tout["Lanh"], L["Cao"] )R18 = ctrl.Rule( N["Trung binh"] & Tin["Vua"] & Tout["Vua"], L["Trung binh"] )R19_20 = ctrl.Rule( N["Trung binh"] & Tin["Vua"] & (Tout["Nong"] | Tout["Rat nong"]), L["Thap"] )R21 = ctrl.Rule( N["Trung binh"] & Tin["Nong"] & Tout["Lanh"], L["Cao"] )R22 = ctrl.Rule( N["Trung binh"] & Tin["Nong"] & Tout["Vua"], L["Trung binh"] )R23_24 = ctrl.Rule( N["Trung binh"] & Tin["Nong"] & (Tout["Nong"] | Tout["Rat nong"]), L["Thap"] )

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

R25 = ctrl.Rule( N["Nhieu nguoi"] & Tin["Lanh"] & Tout["Lanh"], L["Cao"] )R26_27 = ctrl.Rule( N["Nhieu nguoi"] & Tin["Lanh"] & (Tout["Vua"] | Tout["Nong"] ), L["Trung binh"])R28 = ctrl.Rule( N["Nhieu nguoi"] & Tin["Lanh"] & Tout["Rat nong"], L["Thap"] )R29_30 = ctrl.Rule( N["Nhieu nguoi"] & Tin["Vua"] & (Tout["Lanh"] | Tout["Vua"] ), L["Trung binh"] )R31_32 = ctrl.Rule( N["Nhieu nguoi"] & Tin["Vua"] & (Tout["Nong"] | Tout["Rat nong"]), L["Thap"] )R33 = ctrl.Rule( N["Nhieu nguoi"] & Tin["Nong"] & Tout["Lanh"], L["Trung binh"] )R34_35 = ctrl.Rule( N["Nhieu nguoi"] & Tin["Nong"] & (Tout["Vua"] | Tout["Nong"]), L["Thap"] )R36 = ctrl.Rule( N["Nhieu nguoi"] & Tin["Nong"] & Tout["Rat nong"], L["Rat thap"] )

R37_38 = ctrl.Rule( N["Rat nhieu"] & Tin["Lanh"] & (Tout["Lanh"] | Tout["Vua"]), L["Trung binh"])R39_40 = ctrl.Rule( N["Rat nhieu"] & Tin["Lanh"] & (Tout["Nong"] | Tout["Rat nong"]), L["Thap"] )R41 = ctrl.Rule( N["Rat nhieu"] & Tin["Vua"] & Tout["Lanh"], L["Trung binh"] )R42_43 = ctrl.Rule( N["Rat nhieu"] & Tin["Vua"] & (Tout["Vua"] | Tout["Nong"]), L["Thap"] )R44 = ctrl.Rule( N["Rat nhieu"] & Tin["Vua"] & Tout["Rat nong"], L["Rat thap"] )R45_46 = ctrl.Rule( N["Rat nhieu"] & Tin["Nong"] & (Tout["Lanh"] | Tout["Vua"]), L["Thap"] )R47_48 = ctrl.Rule( N["Rat nhieu"] & Tin["Nong"] & (Tout["Nong"] | Tout["Rat nong"]), L["Rat thap"])

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Giaiđoạn4:xaydưnghethoT ngmophongdưatrencacluatđaco

167

rules = [R1_2,R3_4,R5,R6_7,R8,R9,R10_11,R12,R13_14,R15,R16,R17,R18,R19_20,R21,R22,R23_24,R25,R26_27,R28,R29_30,R31_32,R33,R34_35,R36,R37_38,R39_40,R41,R42_43,R44,R45_46,R47_48]

model = ctrl.ControlSystemSimulation( ctrl.ControlSystem(rules) )

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Giaiđoạn5:nhapdưlieuđa:uvaola3yeTutoT :N,Tin,ToutsauđogiaimơvaxuaT tkeT tqualaL.

168

iN = int( input("Số người: ") )iTin = float( input("Nhiệt độ trong phòng: ") )iTout = float( input("Nhiệt độ bên ngoài: ") )

model.input["So nguoi"] = iNmodel.input["Nhiet do trong phong"] = iTinmodel.input["Nhiet do ngoai troi"] = iTout

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Nhapdưlieu,giasưvơiNin, Tin, Tout

169

model.compute()oL = model.output["Muc dieu chinh"]L.view( model )print( "Với %d người ở trong phòng, nhiệt độ trong phòng là %.1f và ngoài trời là %.1f thì mức điều chỉnh là %d" % (iN,iTin,iTout,oL) )

Số người: 4 Nhiệt độ trong phòng: 27 Nhiệt độ bên ngoài: 30

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• KeT tqua

170

Với 4 người ở trong phòng, nhiệt độ trong phòng là 27.0 và ngoài trời là 30.0 thì mức điều chỉnh là 20

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Vídụ20

• DưbaomưcđolaylancuabenhviemphoiCoViD-19doWuhanCoronavirusselaylan(Spread)rasaotrencacvungđialy.VieclaylancancưvaosoT ngươinhiehmbenh(ConmirmedCases),soT ngươitưvongvanguykich(Deaths&SeriousCritical)cungnhưmưcđotieTpgiapvơivungđialy(Border)conguycơcao.

• ĐegiaiquyeT t,thưchienba~ngcacbươcquanhưnggiaiđoannhư

171

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Giaiđoạn1:dưlieu‣ Dưlieunhap:- TongsoT ngươinhiehmbenh(dươngtınh):

- SoT ngươiđatưvong:

- MưcđotieTpgiap:

‣ KeT tqua- Mưcđolaylan:

XC = [1,100000] ∈ ℕ

XD = [1,10000] ∈ ℕ

XB = {1,2,3}

XS = [1,10] ∈ ℕ

172

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

# Xây dựng 4 không gian nền tương ứngXC = np.arange(1,100001)XD = np.arange(1,10001)XB = [1,2,3]XS = np.arange(1,11)

# Định nghĩa tiền đề và kết luận dựa trên các biến ngôn ngữC = ctrl.Antecedent( XC,"Cases" )D = ctrl.Antecedent( XD,"Deaths" )B = ctrl.Antecedent( XB,"Border" )S = ctrl.Consequent( XS,"Spread" )

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Giaiđoạn2:xaydưngcactapmơ‣ SoT ngươinhiehm- I{t,- Trungbınh,- Nhie:u,- RaT tnhie:u

174

C["It"] = fz.zmf( C.universe,1000,10000 )C["Trung binh"] = fz.pimf( C.universe,3000,10000,20000,60000 )C["Nhieu"] = fz.gbellmf( C.universe,8000,3,70000 )C["Rat nhieu"] = fz.smf( C.universe,65000,90000 )C.view()

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

D["It"] = fz.trapmf( D.universe,[1,1,200,500] )D["Trung binh"] = fz.trapmf( D.universe,[300,1000,2000,6000] )D["Nhieu"] = fz.trapmf( D.universe,[5000,6000,7000,8000] )D["Rat nhieu"] = fz.trapmf( D.universe,[7500,8000,10000,10000] )D.view()

‣ SoT ngươitưvong- I{t- Trungbınh- Nhie:u- RaT tnhie:u

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

B["Khong"] = fz.trimf( B.universe,[1,1,2] )B["Co"] = fz.trimf( B.universe,[1,2,3] )B["Gian tiep"] = fz.trimf( B.universe,[2,3,3] )B.view()

‣ MưcđotieTpgiap- Khong- Co- Giantiep

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Mưcđolaylan‣ Khong‣ I{t‣ Vưaphai‣ Cao‣ RaT tcao

177

S["Khong"] = fz.trimf( S.universe,[1,1,3] )S["It"] = fz.trapmf( S.universe,[2,3,4,5] )S["Vua phai"] = fz.trapmf( S.universe,[4,5,6,7] )S["Cao"] = fz.trapmf( S.universe,[6,7,8,9] )S["Rat cao"] = fz.trimf( S.universe,[8,10,10] )S.view()

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Giaiđoạn3:Luatmơ‣ SoT ngươinhiehm,hoacsoT ngươitưvongcangnhie:uthımưcđolaylancangcao

‣ TieTpgiapvơivungdichthıdeh laynhiehm• Đephukhafp,soT luatca:nco luat4 × 4 × 3 = 48

178

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

R1 = ctrl.Rule( C["It"] & D["It"] & (B["Khong"]), S["Khong"] )R2 = ctrl.Rule( C["It"] & D["It"] & (B["Co"]), S["It"] )R3 = ctrl.Rule( C["It"] & D["It"] & (B["Gian tiep"]), S["Khong"] )R4 = ctrl.Rule( C["It"] & D["Trung binh"] & (B["Khong"]), S["Khong"] )R5_6 = ctrl.Rule( C["It"] & D["Trung binh"] & (B["Co"] | B["Gian tiep"]), S["It"] )R7_8_9 = ctrl.Rule( C["It"] & D["Nhieu"] & (B["Khong"] | B["Co"] | B["Gian tiep"]), S["Vua phai"] )R10_11_12 = ctrl.Rule( C["It"] & D["Rat nhieu"] & (B["Khong"]|B["Co"]|B["Gian tiep"]), S["Vua phai"])R13 = ctrl.Rule( C["Trung binh"] & D["It"] & (B["Khong"]), S["Khong"] )R14_15 = ctrl.Rule( C["Trung binh"] & D["It"] & (B["Co"] | B["Gian tiep"]), S["It"] )R16 = ctrl.Rule( C["Trung binh"] & D["Trung binh"] & (B["Khong"]), S["It"] )R17_18 = ctrl.Rule( C["Trung binh"] & D["Trung binh"] & (B["Co"] | B["Gian tiep"]), S["Vua phai"] )R19 = ctrl.Rule( C["Trung binh"] & D["Nhieu"] & (B["Khong"]), S["Vua phai"] )R20 = ctrl.Rule( C["Trung binh"] & D["Nhieu"] & (B["Co"]), S["Cao"] )R21 = ctrl.Rule( C["Trung binh"] & D["Nhieu"] & (B["Gian tiep"]), S["It"] )

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

R22 = ctrl.Rule( C["Trung binh"] & D["Rat nhieu"] & (B["Khong"]), S["Vua phai"] )R23 = ctrl.Rule( C["Trung binh"] & D["Rat nhieu"] & (B["Co"]), S["Cao"] )R24 = ctrl.Rule( C["Trung binh"] & D["Rat nhieu"] & (B["Gian tiep"]), S["Vua phai"] )R25_26 = ctrl.Rule( C["Nhieu"] & D["It"] & (B["Khong"] | B["Co"]), S["Vua phai"] )R27 = ctrl.Rule( C["Nhieu"] & D["It"] & (B["Gian tiep"]), S["It"] )R28 = ctrl.Rule( C["Nhieu"] & D["Trung binh"] & (B["Khong"]), S["Vua phai"] )R29 = ctrl.Rule( C["Nhieu"] & D["Trung binh"] & (B["Co"]), S["Cao"] )R30 = ctrl.Rule( C["Nhieu"] & D["Trung binh"] & (B["Gian tiep"]), S["It"] )R31 = ctrl.Rule( C["Nhieu"] & D["Nhieu"] & (B["Khong"]), S["It"] )R32 = ctrl.Rule( C["Nhieu"] & D["Nhieu"] & (B["Co"]), S["Cao"] )R33 = ctrl.Rule( C["Nhieu"] & D["Nhieu"] & (B["Gian tiep"]), S["Vua phai"] )R34 = ctrl.Rule( C["Nhieu"] & D["Rat nhieu"] & (B["Khong"]), S["Cao"] )R35 = ctrl.Rule( C["Nhieu"] & D["Rat nhieu"] & (B["Co"]), S["Rat cao"] )R36 = ctrl.Rule( C["Nhieu"] & D["Rat nhieu"] & (B["Gian tiep"]), S["Cao"] )R37_38_39 = ctrl.Rule( C["Rat nhieu"] & D["It"] & (B["Khong"] | B["Co"]|B["Gian tiep"]), S["Vua phai"])R40 = ctrl.Rule( C["Rat nhieu"] & D["Trung binh"] & (B["Khong"]), S["Vua phai"] )R41 = ctrl.Rule( C["Rat nhieu"] & D["Trung binh"] & (B["Co"]), S["Cao"] )R42 = ctrl.Rule( C["Rat nhieu"] & D["Trung binh"] & (B["Gian tiep"]), S["Vua phai"] )R43 = ctrl.Rule( C["Rat nhieu"] & D["Nhieu"] & (B["Khong"]), S["Cao"] )R44 = ctrl.Rule( C["Rat nhieu"] & D["Nhieu"] & (B["Co"]), S["Rat cao"] )R45 = ctrl.Rule( C["Rat nhieu"] & D["Nhieu"] & (B["Gian tiep"]), S["Cao"] )R46 = ctrl.Rule( C["Rat nhieu"] & D["Rat nhieu"] & (B["Khong"]), S["Cao"] )R47 = ctrl.Rule( C["Rat nhieu"] & D["Rat nhieu"] & (B["Co"]), S["Rat cao"] )R48 = ctrl.Rule( C["Rat nhieu"] & D["Rat nhieu"] & (B["Gian tiep"]), S["Cao"] )

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Giaiđoạn4:xaydưnghethoT ngmophong

181

rules = [R1,R2,R3,R4,R5_6,R7_8_9,R10_11_12,R13,R14_15,R16, R17_18,R19,R20,R21,R22,R23,R24,R25_26,R27,R28,R29,R30,R31,R32,R33,R34,R35,R36,R37_38_39,R40,R41,R42,R43,R44,R45,R46,R47,R48]

model = ctrl.ControlSystemSimulation( ctrl.ControlSystem(rules) )

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Giaiđoạn5:nhapdưlieuvagiaimơ

182

iC = int( input("Số người bị nhiễm: ") )iD = int( input("Tổng số tử vong: ") )iB = int( input("Mức độ tiếp giáp (1:không, 2:có, 3:gián tiếp): ") )

model.input["Cases"] = iCmodel.input["Deaths"] = iDmodel.input["Border"] = iB

model.compute()oS = model.output["Spread"]print("Số người nhiễm %d, tử vong %d; tiếp giáp cấp độ %d. Khả năng lây lan cấp độ %d" % (iC,iD,iB,oS))S.view( model )

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Số người nhiễm 80000, tử vong 8000; tiếp giáp cấp độ 2. Khả năng lây lan cấp độ 9

Số người bị nhiễm: 80000 Tổng số tử vong: 8000 Mức độ tiếp giáp (1:không, 2:có, 3:gián tiếp): 2

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Vídụ21

• XeTphangtındung(xem“Logicmơvacacbaitoanưngdungtronglınhvưctaichınh”,TapsanTinhocQuanly,Tap3,SoT 1&2,2014,tr.27-44).

‣ Trongđonhanthan,khanangtaichınhvataisannhưlatie:nđe: đexeTphangtındung

• Đeđơngian,viecxeTphangtındungơđayđươcsuyđoantưnhânthân(nhankhauhoc),tàichínhvatàisảnđảmbảo

184

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Xếphạngtíndụngđươcphanthanh3mưctrongkhoangđiem[0,10]

‣ RuirothaTp

‣ Ruirotrungbınh

‣ Ruirocao

• Nhânthân,tàichínhvatàisảnđươcphanthanh3loaitrongkhoang[0,10]

‣ YeTu

‣ Trungbınh

‣ Manh

185

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Cactapmơcothemotanhưsau

186

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• VơisoT lieu‣ Nhanthan[0,10]:10‣ Taichinh[0,10]:3‣ Taisandambao[0,10]:5

• KeT tqua‣ Vơinhanthan10điem,taichınh3điem,taisanđambao5điem;xeTphangtınhdungla5điem

187

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Bàitập

• Đechınhxachoabaitoanđatranay,ca:ngiaiquyeT tcacbaitoancon;• Cha�nghansuyđoanve: nhânthâncancưvao4tie:nđe: la:‣ Tuoi‣ TrınhđohocvaTn

‣ Tınhtranghonnhan

‣ SoT con

188

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Suyđoanve: tàichínhcancưvao:‣ Thunhapha~ngthang

‣ Thamniencongtac‣ Loaihơpđo: nglaođong

189

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Tàisảnđambaocancưvaogiatritaisan:‣ Xehơi‣ Nhaơ

‣ Cacloaikhac

190

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Vídụ22

• Đie:ukhientưđongtoT cđoxe‣ ToT cđo(Speed)cuaxeđươcsuyđoancancưvao:

- Khıhau(Temperature)- Maybaophu(CloudCover)

‣ Trongđo,Temperature(thuoc[0,110])co4tınhtrang:

- Freezing,Cool

- Warm,Hot

191

‣ CloudCover(thuoc[0,100])co3trươnghơp

- Sunny- PartlyCloudy- Overcast

‣ ConSpeed(thuoc[0,100])chıco:

- Fast- Slow

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Chươngtrınh

192

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• KeT tqua

193

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Vídụ23• Đie:ukhientınhieuđengiaothong‣ KhiđeTngiaoloco:- SoT phươngtienđeTnchoh cođenxanh(Arrival)

- SoT phươngtienchơơđenđo(Queue)

‣ Ca:nsuyđoan:- Thơigiankeodaiđenxanh(Extension)

194

• VơiArrival(thuockhoang[0,56])vaQueue(thuockhoang[0,32])cocactrangthaisoT lươngphươngtien:

‣ RaT tıt‣ I{t‣ Bınhthương

‣ Nhie:u

‣ RaT tnhie:u

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• ThơigiankeodaiđenxanhExtensionthuockhoang[0,20]baogo:m:‣ Khongkeodai‣ Ngafn

‣ Trungbınh

‣ Dai‣ RaT tdai

195

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Luatđexưly:NeTucoquanhie:uphươngtienơhươngđeTn(đenxanh)vacomotsoT lươngnhophươngtienơhươngchơ(đenđo),thımơrongđenxanhdaihơnBınhthương

196

Rấtít Ít B.Thường Nhiều Rấtnhiều

Rấtít Khong Ngafn Trungbınh Dai RaT tdaiÍt Khong Ngafn Trungbınh Dai Dai

B.Thường Khong Khong Ngafn Trungbınh DaiNhiều Khong Khong Khong Ngafn Trungbınh

Rấtnhiều Khong Khong Khong Khong Ngafn

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Bàitập• Đie:ukhienmaygiatcocacđacđiemsau:‣ CambieTnđoban:dungtiasangchieTuquanươcchưatronglo: nggiatđexacđinhqua:naođanggiatlasachhaydơ.

‣ Tưđolamcancưca:nbaonhieulươngthuoT cgiatxa,baonhieunươc,vathơigianca:ngiat.

‣ CambieTnkhoT ilươngqua:naođelamcancưcholươngnươccungnhưlươngthuoT cgiatxa

‣ CambieTnlươngnươc:cambieTnnaycancưvaocambieTnđobanvakhoT ilươngqua:naođecođươclươngnươc.

199

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

‣ CambieTnđolươngthuoT cgiatxa:đie:ukhienmưcđothuoT cgiatxaca:nđưavao.

‣ Nhưvay,tưcambieTnkhoT ilươngqua:nao,cambieTnđoban;suyralươngthuoT cgiatxavalươngnươc;sauđotınhtoanthơigianca:ngiat

200

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Vídụ22

• Cungcothedunggiaodiendươidangkhungcưaso(window)đevieT tchươngtrınh.

• Vıduvơicaucadao"Chuồnchuồnbaythấpthìmưa, bay cao thìnắng,bayvừathìrâm",keT thơpvơi"Mâyxanhthìnắng,mâytrắngthìmưa". Viết chương trình điều khiển để "dự báo thời tiết"

201

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Giasưkhonggianne:n:‣ Xlađocao(tınhtư1đeTn9m)sovơimatđaT t‣ Ylamaucuamay(0:mautrafng,1:mauxanh,0.5:maulưngchưnggiưatrafngvaxanh)

‣ ThơitieT tT(theothangtư0đeTn10,bieTnthientưmưanhie:uchođeTnnafng).

• Tư2caucadaotren,"Đocaocuachuo: nchuo: nkhibay"(Height)va"Maucuamay"(Cloud)la2đoT itươngcualơpAntecedent,con"ThơitieT t"(Weather)lađoT itươngcualơpConsequent.

202

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Pha:nchuanbi

203

import numpy as np import skfuzzy as fz from skfuzzy import control as ctrl

X = np.arange(1,10,0.2) Y = np.arange(0,1.5,0.5) T = np.arange(0,11,0.1)

Height = ctrl.Antecedent(X,"Do cao") Cloud = ctrl.Antecedent(Y,"Mau may") Weather = ctrl.Consequent(T,"Thoi tiet")

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Xaydưngcactapmơtươngưng

204

AH = Height["Thap"] = fz.gaussmf(X,1,2) BH = Height["Vua"] = fz.gbellmf(X,1.2,2,5) CH = Height["Cao"] = fz.sigmf(X,6,2)

AC = Cloud["Trang"] = fz.zmf(Y,0,0.6) BC = Cloud["Xanh"] = fz.smf(Y,0.4,1)

AW = Weather["Mua"] = fz.zmf(T,1,4) BW = Weather["Ram"] = fz.pimf(T,2,5,7,9) CW = Weather["Nang"] = fz.smf(T,6,10)

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Cacluatvaxaydưngmohınh

205

R1 = ctrl.Rule(Height["Thap"],Weather["Mua"]) R2 = ctrl.Rule(Height["Cao"],Weather["Nang"]) R3 = ctrl.Rule(Height["Vua"],Weather["Ram"]) R4 = ctrl.Rule(Cloud["Trang"],Weather["Mua"]) R5 = ctrl.Rule(Cloud["Xanh"],Weather["Nang"])

Rules = [R1,R2,R3,R4,R5] CT = ctrl.ControlSystem(Rules) Model = ctrl.ControlSystemSimulation( CT )

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Đưadưlieuvaođexưly

206

D = input("Độ cao chuồn chuồn đang bay [1,9]: ") M = input("Màu của mây [Trắng (0), Xanh dương (1), Màu lưng chừng (0.5)] ")

Model.input["Do cao"] = float(D) Model.input["Mau may"] = float(M) Model.compute()

Out = Model.output["Thoi tiet"]

print( "Thời tiết (gần 0 thì mưa nhiều, gần 10 là nắng gắt)là %.f" % Out )

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science 207

• Xaydưngchươngtrınhđie:ukhiendươidanghamthưvienfolksongweather.

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science 208

import wx # python3 -m pip install wxPython import folksongweather as fk class MyFrame( wx.Frame ): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition,wx.Size(350, 310)) wx.StaticText( self,label='Dự báo thời tiết',pos=(20,20) ) wx.StaticText(self,label='Vị trí chuồn chuồn:',pos=(20,80)) self.height = wx.SpinCtrl( self,-1,'',(180,80),(50,-1),min=0,max=9,initial=5 ) wx.StaticText( self,label='Màu của mây:',pos=(20,110) ) self.cloud = wx.SpinCtrlDouble( self,-1,'',(180,110),(50,-1),min=0.0,max=1.0,initial=0.0,inc=0.1 ) wx.StaticText( self,label='Thời tiết là: ',pos=(20, 150) ) self.weather = wx.StaticText( self,label='',pos=(180, 150) ) dubao = wx.Button( self,1,'Dự báo',pos=(70,200) ) dubao.SetFocus() dong = wx.Button( self,2,'Đóng lại',(185, 200) ) self.Bind( wx.EVT_BUTTON,self.OnCompute,id=1 ) self.Bind( wx.EVT_BUTTON,self.OnClose,id=2 ) self.Bind( wx.EVT_CLOSE, self.OnClose ) def OnCompute( self,event ): D = self.height.GetValue() M = self.cloud.GetValue() W = fk.folksongweather(D,M) S = "%5.2f" % (W) self.weather.SetLabel( S ) def OnClose( self,event ): self.Destroy()

• ChươngtrınhvơigiaodienwindowdungthưvienwxPython

class MyApp( wx.App ): def OnInit( self ): fr = MyFrame( None,-1,"Hệ điều khiển mờ" ) fr.Show() return True ### Chương trình chính app = MyApp(0) app.MainLoop()

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Phânnhómdữliệu• Phânloại,phânnhómlamotcongviecthươnghayphaithưchienkhigapmotlươnglơnđoT itươngca:nquanly.

• Khiphanloaiconhưngpha:ntưthuocloainay,nhưngcungconcothethuocloaikhacvơisoT lươngkhongđangke,thıcoiđolaphancumhayphanchum(Clustering)

• KhiphanloaiđatđươcđeTnmưcnhưngpha:ntưtrongnhomnaykhongthuocnhomkhacthıcongviectrơthanhphanlơp(Classiyication)

• Nhưvay,mucđıchcuoT icungcuaviecphannhomđolaphanchiacacđoT itươnghaycacthanhpha:ntrongmottaphơplơnthanhtưngnhomcocungđactınhnaođo.

209

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Khisưdungcactieuchırorang,đinhlươngđươcthıbaitoantrơnenđơngian;viecphanchiathanhcacnhomdeh thưchien.

• NhưngkhitieuchıphanlơpcangchitieT t,thısetaoraraT tnhie:ulơpnencungtrơthanhvonghıatrongquanly.

• Tuynhien,trongthưcteT tieuchıđephannhomcungkhongrorang,mangtınhđinhlương.

• Dươigocnhıncuataphơp,viecphannhomcungcha�ngqualađưacacpha:ntưcocungđactınhvaotrongcungmottaphơp;nenviecưngdunglapluanmơvaoviecphannhomlamotnhuca:u.

210

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Muctieucuthecuaviecphannhom:‣ Moh inhomđươcphanphaicoıtnhaT tmotpha:ntư‣ Motpha:ntưcuataphơpca:nphanloaiphaithuocıtnhaT tmotnhom‣ KhiviecphannhomđatđeTnkeT tquaphanlơplatoT iưu‣ Tieuchuanphannhomcangrorang,cangıtcangtoT t

211

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Đelươnghoađươctieuchuanphannhomca:ncocongthưccothelươnghoađeđokhoangcachgiưacacpha:ntưtrongtaphơpdưlieuca:nphannhom.

• Giasưmoh ipha:ntưtrongtapdưlieuca:nphannhomđươcsoT hoathanhmotvectorconthanhpha:n(goila thuoctınh)

‣ Cha�nghan,mothocvientrongmotcơsơđaotaođươcsoT hoabơi4thanhpha:nnhưhovaten,ngaythangnamsinh,nơisinh,giơitınh.

n

212

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Địnhnghĩa13:Khoangcachgiưa2pha:ntưtrongkhonggian lahamthoacacđie:ukiensau:

‣ (i) ;

‣ (ii) ;

‣ (iii)

‣ (iv)

Xn

d : Xn × Xn → ℝ

d(x, y) ≥ 0,∀x, y ∈ Xn

d(x, x) = 0,∀x ∈ Xn

d(x, y) = d(y, x), ∀x, y ∈ Xn

d(x, y) ≤ d(x, z) + d(z, y), ∀x, y, z ∈ Xn

213

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Mộtsốđịnhnghĩavềkhoảngcách

• KhoangcachEuclide:

• KhoangcachManhatthan:

• KhoangcachMinskowsky:

• KhoangcachChebyshev:

d(x, y) =n

∑i=1

(xi − yi)2

d(x, y) =n

∑i=1

|xi − yi |

d(x, y) = (n

∑i=1

|xi − yi |p )

1/p

d(x, y) = maxi=1,n

|xi − yi |

214

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

•Đođocosine: ,

• Đođomax-min:

• Trongđo

d(x, y) =∑n

i=1 xiyi

(∑ni=1 x2

i )(∑ni=1 y2

i )

d(x, y) =∑n

i=1 min{xi, yi}

∑ni=1 max{xi, yi}

x = (x1, x2, . . . , xn), y = (y1, y2, . . . , yn)

215

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Phâncụmmờ(FuzzyClustering)

• Chotapdưlieugo:mNdưlieuca:nphanloai ,trongđomoh idưlieu lamotpha:ntưtrongkhonggiannchie:uvơicacthanhpha:nnhưsau:

• Phancummơ(fuzzyclustering)thưcchaT tđolaphancumvơinhưngtieuchıkhonghoantoanchınhxac,vıtrongthưcteT vơimottapdưlieu nhưtrenthıkhongthedeh dangđưamoh i vaomotcumduynhaT t.

• Phancummơhayconđươcgoilaphancumme:m(softclustering)

X = (X1, X2, . . . , XN)Xi, ∀i = 1,N

Xi = (xi1, xi2, . . . , xin), ∀i = 1,N

XXi, ∀i = 1,N

216

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• ĐoT inghichvơiphancummơlaphancumkhongmơ(non-fuzzyclustering)haycongoilaphancumcưng(hardclustering),cha�nghank-Means.

• Cha�nghanmottraitaocomauđohoặccomauxanhthıđươcphanvaobichtaochınhhoacbichtaoconsoT ng(phâncụmcứng).NhưngthưcteT cungconhưngtraitaokhonghoantoanmauđohoackhonghoantoanmauxanh(cocamauđovàcocamauxanh);mavưacomauđomacungcomauxanh.Nenviecbovaobichnaocungmangtınhga:nđung.

• Nhưvay,vơimottraitaoneTucomauđo,cotheganđactınhphanloaila1,neTukhonglamauxanhthıthuoctınhla0chotrươnghơpphancumcưng.Khiphancumme:m,traitaokhonghoantoanmauđo,cancưmưcđocothecothuoctınhla0.8.

217

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

ThuậttoánFuzzyc-Means

• Tưđay,đothuoc(hayđiemthanhvien)đươcganchotưngdưlieu.ĐiemthanhviennaychobieT tmưcđomacacđiemdưlieuthuocve: moh icum.

• TưđochothaTy,cacđiemơrıacuamotcumvơiđiemthanhvienthaTphơn,sovơicacđiemơtrungtamcuacum.

• ThuattoanFuzzyc-Means(FCM)lamottrongnhưngthuattoanđươcsưdungrongraicualoainay.Thuattoanđươcđe: xuaT tbơiJ.C.Dunn(1973)sauđođươccaitieTnđehoanthienbơiJ.C.Bezdek(1981)

218

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Thuattoannayđươcmotanhưsau:‣ ChonsoT cumla

‣ GanhesoT motcachngahunhienchotưngdưlieuđenothuocvaomotcumthưknaođotrong cum

‣ LaplaiviecsauđaychođeTnkhihesoT khongthayđoigiưa2la:nlaptınhtoan,hoacvươtquamotngươngtınhtoanchotrươc:

- Tınhlaitrongtamcuamoh icum- TınhlaihesoT chomoh idưlieu,tınhlaihesoT ve: đophuthuocvaocum

K/1 < K < N

K

219

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Moh iđiemdưlieu đươcganbơimothesoT lamưcđophuthuoccuanovaocumthưktrong cum.Kyhieula

• Điemtrongtamđươctınhla ,vơiNlasoT dưlieu,va

moh i co thanhpha:n(thuoctınh)la

• Ơ� đaymgoilahesoT mơdungđeđie:ukhienđomơ,mcanglơnđomơcangbe

XiK μk(Xi), i = 1,...,N

Ck =∑N

i=1 (μk(Xi))mXi

∑Ni=1 (μk(Xi))m

Ck n Ck = (ck1, ck2, . . . , ckn)

220

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• ThuattoanFCMcoT gafngphanchiataphưuhanpha:ntưcuavaotrong cummơvơitieuchıchotrươc

• Thuattoantrave: danhsachđiemtrongtam cuamoh icumvamatrantrongsoT cogiatrithuoc[0,1]đechımưcđophuthuoccuapha:ntư vaocumk.

• MuctieucuathuattoanFCMlacưctieuhammuctieu(ơđaysưdungkhoangcachEuclid)

X = {X1, X2, . . . , XN} K

Ck = (ck1, ck2, . . . , ckn)W = (wik), i = 1,N, k = 1,K

Xi

argminC1,C2,...,CK

N

∑i=1

K

∑k=1

wik∥Xi − Ck∥2

221

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Sovơithuattoanphancumcưngk-Means,thıc-Meanscha�ngqualamotsưmơrongba~ngcachđưavaohesoT mơp.

• Khi thıc-Meanstrơthanhk-Meansvahammuctieucuathuattoan

nayla ,vơi latapchưacac thuoc

cum ; ,điemtrongtam

m = 0

argminC1,C2,...,CK

N

∑i=1

K

∑k=1

I{Xi∈Sk}∥Xi − Ck∥2 Sk Xi

k I{Xi∈Sk} = {1, neTuXi ∈ Sk

0, ngươclaiCk =

1|Sk |

|Sk|

∑i=1

Xi

222

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

DùngPython• Đedeh hınhdung,trươcheT tchungtadungthuattoank-Meansvơihamthưvientrongmoduleclustercuagoisklearnvơidưlieuđươctaongahunhienđethưnghiem.

• Giasưcobogo:m dưlieu mamoh i cothanhpha:nđươctaongahunhiensaocho vơi

giatritrongđoan

N = 1000 X = {X1, X2, . . . , XN} Xin = 2 Xi ≠ Xj, ∀i, j = 1,...,N

[1,100]

223

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• DunghamKMeans()trongmoduleclustercuagoisklearnđehuaTnluyenvơisoT clusterchotrươcla .c = 3

224

N, n = 1000, 2X = np.random.uniform( 1,100,(N,n) )c = 3kmeans = skl.KMeans( n_clusters=c )kmeans.fit( X )kresult = kmeans.predict( X )plt.figure( figsize=(12,4) )plt.title( 'Dùng k-Means để phân cụm' )for j in range(c): plt.plot(X[kresult == j,0],X[kresult == j,1],'o',label='Nhóm '+str(j))plt.legend( loc='best')plt.show()

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• ChungtabieT tk-Meansvơiytươngthuattoannhưsau:‣ ChotrươcsoT cumK‣ LaTyKđiembaT tkytưNdưlieulamđiemtrungtam‣ TınhkhoangcachtưtaT tcadưlieuđeTncacđiemtrungtamnay‣ PhanbocacđiemdưlieunayvaocacnhomcokhoangcachđeTnđiemtrungtamlaga:nnhaT t

‣ TınhlaiđiemtrungtamcuaKnhomba~ngcachlaTytrungbınhcongkhoangcachcuacacđiemđađươcganvaonhom.

225

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• XuaT tkeT tquaphannhomvatrưcquanhoakeT tqua

226

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

VớiFCM• Dungthưvienscikit-fuzzyvơihamcmeans()trongmoduleskfuzzyvơihesoT mơ .Hamnaytrave: nhie:ugiatri,cothethamkhaothemtaiđiachıhttps://pythonhosted.org/scikit-fuzzy/api/skfuzzy.html#cmeans;nhưngơđaychılaTymotgiatriuđegiaibaitoantoT iưu

m = 2

227

• Đesosanh2keT tqua:

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

c = 3 _,u,_,_,_,_,_ = fz.cmeans( X.T,m=2,c=c,error=0.001,maxiter=1000 ) for i in u: cresult = np.argmax( u,axis=0 )plt.figure( figsize=(12,4) )

plt.figure( figsize=(12,4) ) plt.title( 'Dùng Fuzzy c-Means (FCM) để phân cụm' ) for j in range(c): plt.plot(X[cresult == j,0],X[cresult == j,1],'o',label='Nhóm '+str(j)) plt.legend( loc='best') plt.show()

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• KeT tquanhưsau:

229

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• CothetruycapđeTnkeT tquatheocachkhacđetrưcquanhoaba~ngcachxemxet trươnghơpkhacnhautrencơsơduyettoanboNdưlieuc = 3

230

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Vídụ24• Sưdungbodưlieuve: phânloạicơnđautim(Datasetforheartattackclassiyication)trenKaggle(https://www.kaggle.com/rashikrahmanpritom/heart-attack-analysis-prediction-dataset)

• Datasetversion2nayco303dongva14cotlacacthuoctınhnhư:

‣ 'age','sex','cp','trtbps','chol','mbs','restecg','thalachh','exng','oldpeak',

‣ 'slp','caa','thall','output'

231

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Cacthuoctınhnaylacacthongtinve: benhnhannhư:‣ Tuoi(age),giơitınh(sex),kieuđaungưc(cp:co4kieu0,1,2,3),‣ HuyeT taptamtrương(trtbtps),lươngcholesterol(chol),‣ ĐươnghuyeT t>120mg/dl(ybs:1true,0false),‣ Trangthaiđientamđo: (rectecg:co3trangthai0,1,2),‣ Nhiptim(thalachh),đaukhitaptheduc(exng:1co,0khong),‣ Đınhđiemđaula:ntrươc(oldpeak)‣ ...

232

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• DưlieuđươctrıchxuaT tratưtaptinheart.csvnhưsau:

233

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Taotapdưlieuvadưlieuthưgo:mcacbươcnhưsau:‣ CothelaTydatasetve: may,hoaccothechıđinhđươngdahntrưctieTpđeTntaptintươngưngba~ngcachđưavaoDataFramecuamodulePandas

‣ Sauđođưavaocacdưlieunayvaotapdưlieu ,vungcuoT icungđưavaobieTntestdungđekiemtrakeT tquasaukhiphannhom.

X

234

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science 235

importnumpyasnpimportpandasaspdimportskfuzzyasfzdataset=pd.read_csv("./heart.csv")dataset

N=len(dataset.columns)-1X=dataset.iloc[:,0:-1].valuestest=dataset.iloc[:,N].values

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• SưdungFuzzyc-Meansđephanthanh2cumvơi100la:nlap,saisoT 10−3

236

_,u,u0,d,_,iter,fpc = fz.cmeans( X.T,m=2,c=2,error=0.001,maxiter=100 ) for i in u: cresult = np.argmax( u,axis=0 )

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science 237

• Sưdungk-Meansđesosanh

kmeans = skl.KMeans( n_clusters=2 ) kmeans.fit( X ) kresult = kmeans.predict( X )

from sklearn import metrics print( "So với dữ liệu kiểm tra" ) print( "Sai số khi dùng k-Means: ", metrics.accuracy_score(test,kresult) ) print( "Sai số khi dùng FCM : ", metrics.accuracy_score(test,cresult) )

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• ChươngtrınhcothevieT t

238

import numpy as npimport pandas as pdimport skfuzzy as fzfrom sklearn import metrics

dataset = pd.read_csv( "./heart.csv" )N = len(dataset.columns)-1X = dataset.iloc[:,0:-1].values test = dataset.iloc[:,N].values

_,u,u0,d,_,iter,fpc = fz.cmeans( X.T,m=2,c=2,error=0.001,maxiter=100 )for i in u: cresult = np.argmax( u,axis=0 )

kmeans = skl.KMeans( n_clusters=2 )kmeans.fit( X )kresult = kmeans.predict( X )

print( "So với dữ liệu kiểm tra" )print( "Sai số khi dùng k-Means: ", metrics.accuracy_score(test,kresult) )print( "Sai số khi dùng FCM : ", metrics.accuracy_score(test,cresult) )

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Luậtkếthợpmờ

• TrongthưcteT luonluonto: ntaiquanhegiưacacthuoctınhcuadưlieutrongmottapdưlieu

• Cha�nghan,‣ Co80%hocsinhsoT ngơthanhthibicanthi.‣ TrongtongsoT hocsinh,co25%lahocsinhsoT ngơthanhthibicanthi‣ Nhưvay{hocsinhsoT ngơthanhthi} {canthi}comưcđophobieTnla25%,va80%đotincay

239

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• HoacmotsoT vıdukhac:‣ {ngươihutthuoT cla,soT ngơvungonhiehm} {biungthưphoi}(trongtongsoT co30%ngươihutthuoT cla,soT ngơvungonhiehm,biungthưphoi;nhưngngươihutthuoT cla,soT ngơvungonhiehmthıco75%biungthưphoi).

‣ {đơnhangmuabia} {đơnhangmuathitbokho}(TrongtongsoT giaodichcuacưahang,co20%giaodichmuacabialahnthitbokho;trong100khachhangmuabiathıco70khachhangmuathitbokho}

241

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Trongcơsơdưlieu,rutracơsơdưlieucacgiaodich(transactionaldatabase).Cha�nghan,

‣ Cacmathangtrongcưahang:bia,rươu,coca,thuoT cla,bokho• Goicacmathangnaylacachangmuc(item),kyhieu:‣ lataphangmuc,trongđomoh i lamothangmuc

‣ latapcacgiaodich(transaction),nhưvaytapgiaodichđươcđinhnghıadưatrentapcachangmuc;concac golacactapmuc(itemset)

I = {x1, x2, . . . , xn} xi, ∀i = 1,..,n

T = {Tj(Ij)/Ij ⊆ I, ∀j = 1,m}Ij

242

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Vıdu:ChotapTgo:m giaodich trentapn=5hangmucnhưsau:

m = 10 Ti, i = 1,10I = {A, B, C, D, E}

243

TID Transaction TID Transaction

T1 A,B,E T6 A,C

T2 B,D T7 B,C

T3 C,E T8 A,C

T4 B,C T9 A,B,C,E

T5 A,B,D,E T10 A,B,C

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• NeTu conhangmuc,soT tapmuccua la

• Ngươitacondungkyhieun-itemđephanbietve: soT lươnghangmuctrongcactapmucvơinhau.Cha�nghan, lacac2-item

II 2n − 1

I2, I3, I4

• Nhưvay:• ,vơi

‣ ...

T = {T1, T2, T3, T4, T5, T6, T7, T8, T9, T10}

T1(I1), I1 = {A, B, E}

T2(I2), I2 = {B, D}

T3(I3), I3 = {C, E}

T4(I4), I4 = {B, C}

T5(I5), I5 = {A, B, D, E}

244

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Địnhnghĩa14:Cho latapcacgiaodichtrencachangmuc ,vơi2tapmuc ,ma,LuatkeT thơplaluat ,trongđo ,

• Ýnghĩa:NeTumotgiaodichcochưatapmucXthınocungchưatapmucY.

T IX, Y ⊂ I ℜ : X ⇒ Y Y ≠ ∅

X ∩ Y = ∅

245

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Địnhnghĩa15(Độhỗtrợcủatậpmục):Cho latapcacgiaodichchưamgiaodichtrentapcachangmuc ,vachotapmuc .Khiđođohoh trơ(support)cuatapmuc la

• Vıdu:Vơi va nhưtrongbang

‣ ,thı

‣ ,thı

TI X ⊆ I

Xsupp(X, T) =

SoT lươnggiaodichtrongTmachưaXTongsoT giaodichtrongT

I = {A, B, C, D, E} T

X = {A, B} supp(X, T) = 4/10

Y = {A, B, C} supp(Y, T) = 2/10

246

TID Transaction TID Transaction

T1 A,B,E T6 A,C

T2 B,D T7 B,C

T3 C,E T8 A,C

T4 B,C T9 A,B,C,E

T5 A,B,D,E T10 A,B,C

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Tínhchất10:Chotapgiaodich valuatkeT thơp ,doquanhelataphơpcon cuatıchDescartesnenđộhỗtrợcủaluật trong

giaodich la:

• Địnhnghĩa16(Độtincậy):ĐotincaycualuatkeT thơp trong

giaodich la: .Hay

T ℜ : X ⇒ Yℜ X × Y ℜ

T supp(ℜ) = supp(X ⇒ Y) = supp(X ⇒ Y, T)

ℜ : X ⇒ YT conf(ℜ) = conf(X ⇒ Y) =

supp(ℜ)supp(X, T)

conf(ℜ) =supp(X ⇒ Y, T)

supp(X, T)

247

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• LuatkeT thơpcochưa3thongtinchınh‣ Luat:tie:nđe: keT tluan

‣ Đohoh trơ:tylecualuattrongtongsoT giaodich‣ Đotincay:tyle(pha:ntram)giưaluatvatie:nđe:

248

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Đie:uđochothaTytımluatkeT thơplatımraquytaf ctrongdưlieumacosưkeT thơp(association)hayquanhe(relation)vơinhauđươcbieudiehndươidangquanhekeotheo( ).LuatkeT thơpmơlaluatkeT thơpđươcbieudiehnbơiquanhemơ

• Trongtrươnghơpnay,‣ hocsinhsoT ngơthanhthi‣ ngươihutthuoT cla,soT ngơvungonhiehm‣ khachhangmuabia- Goilatie:nđe: (antecedent)

249

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

‣ canthi‣ ungthưphoi‣ muathitbokho- goilakeT tluan(consequent)

• NhưngconsoT 25%,30%,20%lađohoh trơ(support)cualuat:‣ Đochınhlatylepha:ntramgiaodichchưacatie:nđe: vakeT tqua

250

• Con80%,75%,70%lađotincay(conyidence)cualuat:

‣ Đochınhlatylepha:ntramgiaodichthoamanveT traithıcungthoamanveT phai.

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Ngoairaconcocacđođokhaccualuatnhư:đocảithiện(đođoLift),vamotsoT đođokhacnhưđođoConviction,đođoLeverage.

• Địnhnghĩa17:Độcảithiệncualuat la

• Khi :khongcomotquytaf clienkeT tnaogiưa

X ⇒ Y

lift(X ⇒ Y) =conf(X ⇒ Y)

supp(Y)∈ [0,∞)

lift(X ⇒ Y) ≤ 1 XvaY

251

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Minhhoạ• Vơibang10giaodichnhưtren,trongđo‣ A:hutthuoT c‣ B:soT ngơvungonhiehm‣ E:biungthưphoi

• Khiđo,‣ A,BvaE:co3tapmuc‣ A,B:co4tapmuc‣ E:co4tapmuc

252

TID Transaction TID Transaction

T1 A,B,E T6 A,C

T2 B,D T7 B,C

T3 C,E T8 A,C

T4 B,C T9 A,B,C,E

T5 A,B,D,E T10 A,B,C

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Tưđay,suyra‣ SoT giaodichtrong:10‣ Đohoh trơcualuat la

‣ Đotincaycualuat la

‣ Đocaithiencualuat la

A, B ⇒ E 310 = 30 %

A, B ⇒ E 34 = 75 %

A, B ⇒ E 34 / 3

10 = 104 = 2.5

253

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Địnhnghĩa17:Chotapgiaodich conhangmuc,trongđomoh ihangmuccotapmuc tươngưng.Goiminsuppcua la .Tap

muc đươcgoilatapmucphobieTn(frequentitemset))khi.

‣ Thongthương,cothechongiatriminsupptuyy.• LuatkeT thơp đươcgoilaphobieTnneTu ,khiđominsuppđươcgoilangươnghoh trơtoT ithieu.

TTi Ii T min

i=1,n{supp(Ii, T)}

Jsupp(J) ≥ minsupp

X ⇒ Y supp(X ⇒ Y) ≥ minsupp

254

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• CachangmucxuaT thientrongthưcteT thươngconhie:udangthuoctınhnhưthuoctınhnhiphan(binary),thuoctınhđinhlương(quantitative)vathuoctınhhangmuc(categorical).

• Cha�nghanvơiDatasetve: cơnđautimtrenKaggleơpha:ntrươcđươcViethoanhưbang:

255

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• ĐươcViethoathanhcaccotvơitengoinhưbang

256

• Trongđococaccotvơithuoctınhdang• Nhiphan:Giơitınh,LươngđươnghuyeT ttren120mg/dl,KeT tqua

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

‣ Dangđinhlương:Tuoi,HuyeT tap,Cholestoral,Nhiptim,PreviousPeak‣ Danghangmuc:Kieuđautim,Trangthaidientamđo: ,Slope,SoT lươngmachchınh,thall.

• ThưcchaT tdangnhiphanlatrươnghơpriengcuadanghangmuc.• KhikhaithacluatkeT thơptưdatasetthươngphainhiphanhoacacthuoctınhđinhlươngvathuoctınhdanghangmuc.

‣ Vơitrươngdưlieucokthuộctínhhạngmụchayksốrờirạccủathuộctínhdạngđịnhlượng,thıphaibieTnđoikthuoctınhnaythanhkthuoctınhnhiphan.

257

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Cha�nghan,trươngKiểuđautimco4loaiKiểu1,Kiểu2,Kiểu3,Kiểu4;đươcvieT tlainhưsau:

258

STT Tuổi Nữ Nam Kiểu1 Kiểu2 Kiểu3 Kiểu40 63 1 0 0 0 0 11 37 1 0 0 0 1 02 41 0 1 0 1 0 03 56 1 0 0 1 0 04 57 0 1 1 0 0 0

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

‣ Trươnghơptrươngdưlieudangthuộctínhdạngđịnhlượngliêntục,haythuộctínhdạngđịnhlượngrờirạcnhưngcósốlượngsốvôcùnglớn,haythuộctínhhạngmụcnhưngsốhạngmụcrấtnhiều.

‣ Trongtrươnghơpnaycungphanthanhkđoan(chothuoctınhdangđinhlương),hayktaphơp(chothuoctınhhangmuc)vơiklaconsoT hưuhan.

‣ Sauđođưave: kthuoctınhnhiphan.‣ Cha�nghanvơicactrươngnhưTuoi,HuyeT tap,Choletoral,Nhiptim

259

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Tuoiđươcnhiphanhoanhưsautheotưngđoannhưsau:

260

STT Tuổi:1-24 Tuổi:25-40 Tuổi:41-60 Tuổi:>60

0 0 0 0 1

1 0 1 0 02 0 0 1 03 0 0 1 04 0 0 1 0

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Nhậnxét• Viecnhiphanhoachıchınhxackhidưlieuđươcphanbietrorang.Cha�nghan,Giơitınh,Kieuđautim.

• Vơidưlieucothuoctınhdangđinhlươnglientuchayvocunglơnhangmuc,viecrơirachoabivaTnđe: điembiengay(sharpboundaryproblem)giưa2khoangke: nhau.

• Tưđo,thaychonhưngluatkeT thơpkieunhư:‣ <Tuoi:41-60>&<Giơitınh:Nam>&<Cholestoral:200-300>&<HuyeT tap:>150> <Benhtim:Co>

‣ KhongthuyeT tphucchonhưngngươicotuoi61,Cholestoral199⟹

261

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Tưđoca:ncoluatkeT thơpkieunhư:‣ <Tuoi:Trungnien>&<Giơitınh:Nam>&<Cholestoral:Cao>&<HuyeT tap:Cao> <Benhtim:Co>

• LuatkeT thơpkieunhưvaygoilaluatkeT thơpmơ.• Nhưvay,ve: banchaT tluattrongluatkeT thơpmơcunglaluattrongluatkeT thơp;chıkhacnhauve: cachtınhđohoh trơ,đotincayvacacđođo

262

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Chomotdatasetgo:mmmahutin vakthuoctınh

• Khiđogıatricuathuoctınh ơmahutinthưila ,kyhieula .

‣ Cha�nghan,vơidatasetnhưtren,cocacthuoctınhnhưsau

D = {D1, D2, . . . , Dm}I1, I2, . . . , Ik

Ij Di[Ij] Dij

263

• Nhưvay vơim=303mahutinvak=14thuoctınh.D

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Nhưngthuoctınhdưlieucodạngđịnhlượng(quantitative)nhưTuoi( ),HuyeT tap(I3),Cholestoral(I4),Nhiptim(I7),Đaudotaptheduc(I8),PreviousPeak(I9)ca:nphaiđươcmơhoa.

• Tưđotınhđươcdohoh trơ,đotincaycungnhưcacđođomơ• Đelamđie:unay,trươcheT tvơimoh ithuoctınh codangđinhlương,ca:nphaiđươcrơiracbơiLjtapmơ

• Kyhieutaphơpcuacactaphơpnayla .

I0

IjAj1, Aj2, . . . , AjLj

Aj = {Aj1, Aj2, . . . , AjLj}

264

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

‣ Cha�nghan,- ,vơi

- ,vơi

• Goi lakhonggianne:ncuacactapmơ (cungcothegoilakhonggianne:ncuathuoctınh .

‣ Cha�nghan, lakhonggianne:ncuacactapmơtrongtap

A0 = ATuoi = {Tre, Trungnien,Gia} L0 = 3

A4 = ACholestoral = {ThaTp, ToT t, Cao,RaT tcao} L4 = 4

Xj Ajl, ∀l = 1,...,Lj XjIj

Xj = {1,14,25,40,60,100}A0 = ATuoi

265

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Tưđaytaxaydưnghamthuoccuacactapmơ

.

• Congviecnaycothexaydưngtheochuyengia,hoactrưcquankinhnghiemhoaccothelamtưđongdưatrendưlieucotrongdataset(trongchươngtrìnhbằngPythonphíasau).

‣ Cha�nghan,cothecocachamthuoccuanhomtapmơ

‣ Tuynhien,trongtrươnghơpnaycothekhongphuhơpvơidataset

μAjl: Xj → [0,1]

Ajl, ∀l = 1,Lj

A0 = ATuoi

266

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Vềmộtsốđộđo

• TrươcheT tđolađohoh trơcuatapmucmơ• Đexetve: đohoh trơcuatapmuctrongtoanbodatasetdươigocnhıncualapluanmơ,taxemxettrươnghơpđơngianlatapmuccuathuoctınhthưj

chıco1hangmucduynhaT t,thı đươctınhquatongsoT tapmuctrongcơsơdưlieugiaotaccuadataset machưahangmucnay,sauđochiachosoT mahutintrongdataset.

X ⊂ Ij supp(X)D

supp(X) =SoT lươngtapmuctrongDmachưahangmucX

KıchthươccuaD

267

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Vơiđohoh trơmơ,trươctientınhtongmưcđoungho(vote)cuataT tcacacmahutintrongdataset,ro: isauđochiachosoT mahutincotrongdataset.

• Đie:unaychothaTyđohoh trơmơconphaithehienkhongchıanhhươngđeTnsoT mahutinhoh trơtapmuc,maconthehiencamưcđohoh trơ

• Địnhnghĩa18:Đohoh trơcuatapmuc (haycuamottapmơ )kyhieuhay :

Xj Ajlsupp(Xj, Ajl) supp(Xj)

supp(Xj, Ajl) =∑m

i=1 μAjl(Dij)

m, ∀j = 1,...,Lj

268

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Tínhchất11:Độhỗtrợmờcuacactapmuctienđe: (antecendent)trongluatkeT thơpcokkhonggianne:n tươngưngvơikthuoctınhco đươcthehienquaktapmơ chınhla

Trongđo, va

‣Chưngminh:Đie:unaycođươcdođinhnghıave: hamthuoccuatıchDescartes

X1, X2, . . . , XkI1, I2, . . . , Ik A1, A2, . . . , Ak

supp(X, A) =∑m

i=1 minj=1,k {μAj(Dij)}

mX = {X1 × X2 × . . . × Xk} A = {A1 × A2 × . . . × Ak}

269

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Choluat tươngưngvơi2thuoctınhjvak,

trongdataset ,taco

• Tínhchất12:Độtincậymờcualuat la

ℜ :< Xj : Aj > ⟹ < Yk : Bk >

D conf(ℜ) =supp(Xj ⇒ Yk)

supp(Xj)

conf(ℜ) =∑m

i=1 min {μAj(Dij), μBk

(Dik)}∑m

i=1 μAj(Dij)

270

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Tínhchất13:Choluattươngưngvơicacthuoctınhp,qvak,trongdataset ,tacođộtincậymờcualuat la

• Tínhchất14:Độcảithiệncualuat la

ℜ :< Xp : Ap > & < Xq : Aq > ⟹ < Yk : Bk >D

conf(ℜ) =∑m

i=1 min {μAp(Dip), μAq

(Diq), μBk(Dik)}

∑mi=1 min {μAp

(Dip), μAq(Diq)}

lift(ℜ) =conf(ℜ)supp(ℜ)

= =m∑m

i=1 min {μAp(Dip), μAq

(Diq), μBk(Dik)}

∑mi=1 min {μAp

(Dip), μAq(Diq)}∑m

i=1 μBk(Dik)

271

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

Tìmkhônggiannềntừdataset

• Thayvıchiathuoctınhdangđinhlươngtheochuyengia,chungtacothechoncacmoT cdưlieucotrongdatasetđetaokhonggianne:n

• Cha�nghan,vơithuoctınhTuoi,đexaydưngkhonggianne:n taca:n4dưlieuđeco ,trongđo

‣ :latuoinhonhaT tvalơnnhaT ttrongdataset

‣ :la2điemtrungtamcua2vungdưlieu.

• Chươngtrınhgiuptakhaithactưnguo: ndưlieuđaconay.

XTuoiXTuoi = {cmin, c1, c2, cmax}

cmin, cmax

c1, c2

272

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• SaukhilaTydatasetve: nhưtrongpha:nve: FCM,chungtaViethoatencacthuoctınhđedeh hınhdung

273

dataset=dataset.rename(columns={'age':'Tuoi','sex':'Giơitınh','exng':"Đaudotap",'caa':'Solươngmachchınh(0,1,2,3,4)','cp':'Kieuđautim(0,1,2,3)','trtbps':'Huye: tap','chol':'Cholestoral','mbs':'LươngđươnghuyeT t>120mg/dl(0,1)','slp':'Slope(0,1,2)','oldpeak':'PreviousPeak','restecg':'Trangthaiđientamđo: (0,1,2)','thalachh':'Nhiptim','thall':'thall(0,1,2,3)','output':'KeT tqua(0,1)'})

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• DotrongPandasđacohamdecribe()đethoT ngke,nenviecchonmin,maxcuathuoctınhkhađơngian

274

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Theobang,mahutinthư4vathư8laminvamaxcuacacthuoctınh,nenđươctınhba~ngcachcmin, cmax

275

m = dataset.shape[0] cmin, cmax = dataset.describe()["Tuổi"][3], dataset.describe()["Tuổi"][7]

• Con cothedungthưvienphannhomk-Meanscotrongsklearnnhưsau

c1, c2

Dj = dataset.values[:,0] cntr = skl.KMeans( n_clusters=2 ).fit(Dj.reshape(m,-1)).cluster_centers_ c1, c2 = int(cntr[0]), int(cntr[1])

• Cothekhitınhtoan ,khiđophaihoanvilaiđec1 > c2 c1 < c2

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Tưđaytacokhonggianne:nchothuoctınhTuoivacactapmơtươngưng

276

Xj = np.array( [cmin,c1,c2,cmax] ) Tre = fz.trimf( Xj,[cmin,cmin,c1] ) TrungNien = fz.trimf( Xj,[cmin,c1,c2] ) Gia = fz.trimf( Xj,[c2,cmax,cmax] )

• Đohoh trơcuathuoctınhmơTuoitrungnien

supp = 0 for i in range(0,m): supp += fz.interp_membership(Xj,TrungNien,Dj[i]) supp /= m

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Đexaydưngcacthuoctınhmơchocacthuoctınhkhac,taca:ncothemkieTnthưcchuyengia,keT thơpvơiphantıchsoT lieutưdatasetmotcachtưđong

‣ HuyeT tap:lađơnviđoaplưccuamaukhibiđaydoctheocacthanhđongmach.Baogo:m:

- A{ plưctamthu(aplưckhitimđaymauđi),tren150mmHglacao- A{ plưctamtrương(aplưckhitimnghıgiưanhưngla:nđap),tren85mmHglacao

‣ ChısoT huyeT tapcangcaođo: ngnghıavơiviectimphailamviecvaT tvahơnđeđưamauđikhafpcơthe.Đie:unaytaoranguycơdeh bibenhcaohuyeT taphaybiđautim.

277

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

‣ Cholesterol:ĐolươngchaT tbeotrongmau,co2loai:- LDL(low-densitylipoprotein)laloaicholesterolxaTu,goppha:nlamhınhthanhcacmangbamơđongmach;tren100mg/dllaxaTu

- HDL(high-densitylipoproteine)laloaicholesteroltoT t,giupđưacacLDLrakhoiđongmach;dươi40mg/dllakhongtoT t

‣ Khicơtheconhie:uLDL,nguycơbiđautimhoacđotquyraT tcao.

278

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

‣ Nhiptim:SoT la:nđapcuatimtrongmotphutkhiđangnghıngơi;tư60la:n/1phut–bpm-trơxuoT ngđươcxemlakhoemanh.

‣ Nhiptimđapcangnhanh(tronglucđangnghıngơi)conghıalatimphailamviecvaT tvahơnđebơmmau.

‣ NhiptimcaoselamcơthephaihoanthanhcaccongviecraT tđơngianhangngaynhưansang,mơlonbia,…laikhokhan.

‣ Đacbietkhithannhiettanglendobiviemnhiehmhayvaccinevaocơthethıthannhiettang,taonensoT t.Khithannhiettang,cơthesoT nglailamlanhngoaidađegıamnhiet;nhưngro: idobigiamlanhnencơthelainha:mtươnglalanhquanenlaitangnhietđođelamaTmlen;cưnhưvaythannhietlaitang.

279

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

‣ Mơtrongmau(Triglycerid):

- dươi200mg/dllabınhthương,

- tư200–400daTuhieucao,

- tren400bibenh

280

‣ LươngđươnghuyeT t:Thehienlươngđươngglucosecotrongmausaukhingudayhoacsaukhinhinđoikhoang8giơ.

- ToT tkhiơtrongkhoang[80mg/dl,100mg/dl]- Tren100đangtronggiaiđoanconguycơbibenh

- NeTulươngđươnghuyeT tlơnhơn126mg/dlđabitieuđươngloai1hoac2.

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Cha�nghan,taca:ntımđotincaycualuatR:<Tuoi:Gia>va<HuyeT tap:Bınhthương>⇒<Sưckhoe:ToT t>

• Theodataset,thuoctınhHuyeT tapthuocdangđinhlương,conSưckhoelathuoctınhKeT tquadangnhiphan.

• NenngoaithuộctínhmờvềTuổiGià,ca:ntaocacthuộctínhmờvềHuyếtáp,conthuoctınhSưckhoeđaơdangnhiphan,tuynhiendođenhaT tquantacungxaydưng2tapmơTốt,Xấudangcua2tapbınhthươngnhưngtheolapluanmơ.

281

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Ve: tuoi

282

cmin, cmax = dataset.describe()["Tuổi"][3], dataset.describe()["Tuổi"][7] Dp = dataset.values[:,0] cntr = skl.KMeans( n_clusters=2 ).fit(Dp.reshape(m,-1)).cluster_centers_ c1, c2 = int(cntr[0]), int(cntr[1])

if c1 > c2: t = c1 c1 = c2 c2 = t

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Thuoctınhmơtuoigia

283

Xp = np.array( [cmin,c1,c2,cmax] ) Gia = fz.trimf( Xp,[c2,cmax,cmax] )

cmin, cmax = dataset.describe()["Huyềt áp"][3],dataset.describe()["Huyềt áp"][7] Dq = dataset.values[:,3] # số 3 này là thuộc tính ở cột thứ tư cntr = skl.KMeans( n_clusters=2 ).fit(Dq.reshape(m,-1)).cluster_centers_ c1, c2 = int(cntr[0]), int(cntr[1])

• ChothuoctınhHuyeT tap

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Cungtươngtư,cocacthuoctınhmơ

284

Xq = np.array( [cmin,c1,c2,cmax] ) Thap = fz.trimf( Xq,[cmin,cmin,c1] ) BinhThuong = fz.trapmf( Xq,[cmin,c1,c2,cmax] ) Cao = fz.trimf( Xq,[c2,cmax,cmax] )

Dk = Tmp = dataset.values[:,13] # số 13 này là thuộc tính ở cột cuối cùng Xk = np.array( [0,1] ) # Xấu: 0, Tốt: 1 Tot = np.array( [0,1] ) Xau = np.array( [1,0] ) Dk = dataset.values[:,13] # số 13: thuộc tính ở cột cuối cùng

• ThuoctınhKeT tquacungphainhiphan

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Tưđaycođohoh trơ,đotincay:

285

min = lambda x,y: y if x > y else x supp = suppM = 0 for i in range(0,m): t = fz.interp_membership(Xp,Gia,Dp[i]) h = fz.interp_membership(Xq,BinhThuong,Dq[i]) u = fz.interp_membership(Xk,Tot,Dk[i]) suppM += min(t,h) supp += min(min(t,h),u) suppM /= m supp /= m

conf = supp/suppM print( "Độ hỗ trợ %.2f%%, độ tin cậy %.2f%%" %(supp*100, conf*100) )

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science

• Đocaithien

286

lift = conf/supp print( "Luật R: <Tuổi: Già> và <Huyết áp: Bình thường> ⇒ <Sức khỏe: Tốt>" ) print( "Có độ hỗ trợ %.2f%%, độ tin cậy %.2f%%, độ cải thiện %.2f" %(supp*100,conf*100,lift) )

Tran Van Lang, PhD in Mathematics-PhysicsA.Prof. in Computer Science 287

Assoc.Prof. in Computer Science, PhD. in Mathemathics-Physics Editor-in-Chief: HUFLIT Journal of Science

Deputy Editor-in-Chief: Journal of Computer Science and Cybernetics Section Editor: Electronics-Telecommunication Section, Vietnam Journal of Science and Technology

Fuzzy Logic and its ApplicationsTran Van Lang

288

top related