Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fuzzy Template for Scheme Language Modeling & Simulation Lab. Sungkyunkwan Univ.

Similar presentations


Presentation on theme: "Fuzzy Template for Scheme Language Modeling & Simulation Lab. Sungkyunkwan Univ."— Presentation transcript:

1 Fuzzy Template for Scheme Language Modeling & Simulation Lab. Sungkyunkwan Univ.

2 Fuzzy Rule-Based System Fuzzy Matching Inference Combining Fuzzy Conclusions Defuzzification

3 Standard Additive Model IF x is A i And y is B i THEN z is C i (1 ≤ i ≤ n) a i = the area of C i g i = the centroid of C i

4 Standard Additive Model R1:IFQuantity is Small AND ;; IF Quantity 1 =Small AND Softness is Soft ;; Softness 1 = Soft THENCycle 1 is Light ;; THEN Cycle 1 = Light R2:IFQuantity is Medium AND Softness is Soft THENCycle 2 is Light a 1 =a 2 =>the area of Cycle =Light g 1 =g 2 =the centroid of Light x=quantity (input) y=softness (input) z=cycle (output)

5 Standard Additive Model SmallNormal Small 0.63 x0x0 y0y0 gigi μ Small (x 0 )×μ Normal (y 0 )×a i μ Small (x 0 ) = 0.9 μ Normal (y 0 ) = 0.7

6 Automatic Washing Machine Laundry Quantity Laundry Softness Automated Selection Washing Cycle Washing Time

7 Membership Functions 0.00.250.50.751.0 SmallMediumLarge 0.00.250.50.751.0 SoftNormalHard Laundry QuantityLaundry Softness

8 Membership Functions 0.00.250.50.751.0 LightNormalStrong 0.00.250.50.751.0 ShortNormalLong Washing CycleWashing Time

9 Fuzzy Rules InputsOutputs QuantitySoftnessCycleTime 1SmallSoftLightShort 2MediumSoftLightNormal 3LargeSoftNormal 4SmallNormalLightNormal 5MediumNormal 6LargeNormalStrongNormal 7SmallHardNormal 8MediumHardStrongNormal 9LargeHardStrongLong

10 Linguistic Variables 0.00.250.5 1.0 Small trapezoid(x: 0.0, 0.0, 0.25, 0.5) (define quantity-small '(0.0 0.0 0.25 0.5)) 0.250.50.75 1.0 Medium triangle(x: 0.25, 0.5, 0.75) (define quantity-medium '(0.25 0.5 0.75))

11 Fuzzy Membership Functions 0.00.250.50.751.0 SmallMediumLarge Laundry Quantity (define quantity-small '(0.00 0.00 0.25 0.50)) (define quantity-medium '(0.25 0.50 0.75)) (define quantity-large '(0.50 0.75 1.00 1.00))

12 Fuzzy Rules (define-structure rule if then) (define r1 (make-rule 'if '(···) 'then '(···)) (define r2 (make-rule 'if '(···) 'then '(···)) ··· (define r9 (make-rule 'if '(···) 'then '(···)) (define rules (list r1 r2 r3 r4 r5 r6 r7 r8 r9))

13 Fuzzy Rules R1:IFLaundry Quantity is Small AND Laundry Softness is Soft THENWashing Cycle is Light AND Washing Time is Short (define r1 (make-rule 'if '((quantity quantity-small) (softness softness-soft)) 'then '((cycle cycle-light) (time time-short))))

14 Fuzzy Rules R2:IFLaundry Quantity is Medium AND Laundry Softness is Soft THENWashing Cycle is Light AND Washing Time is Normal (define r2 (make-rule 'if '((quantity quantity-medium) (softness softness-soft)) 'then '((cycle cycle-light) (time time-normal))))

15 Control Flow inference initialize-outputs execute-rule fuzzy-defuzzification execute-rule fuzzy-matching fuzzy-inference-combining fuzzy-matching matching-degree fuzzy-inference-combining fuzzy-area fuzzy-centroid'cycle 'time c t 'fuzzy-outputs 'quantity 'softness q s 'fuzzy-inputs

16 Execution Example [1] (load "fuzzy.s") OK [2] (set! fuzzy-inputs '((quantity 0.3) (softness 0.6))) ((QUANTITY 0.3) (SOFTNESS 0.6)) [3] (inference) ((CYCLE 0.39) (TIME 0.5)) [4] fuzzy-outputs ((CYCLE 0.39) (TIME 0.5))

17 Main Function (define (inference) (initialize-outputs) (map execute-rule rules) (map fuzzy-defuzzification fuzzy-outputs) fuzzy-outputs)

18 Fuzzy Outputs 'cycle 'time '( numerator denominator ) 'fuzzy-outputs 'cycle 'time ··· 'fuzzy-outputs Defuzzification 'cycle 'time ? ? 'fuzzy-outputs Initialize Outputs

19 Initializing Output Variables (define (initialize-outputs) (set! fuzzy-outputs '()) (map (lambda (x) (set! fuzzy-outputs (cons (list (car x) '(0.0 0.0)) fuzzy-outputs))) (rule-then (car rules))) #T) 'cycle 'time '(0.0 0.0) 'fuzzy-outputs

20 Rule Execution (define (execute-rule rule) (set! degree-of-match (apply * (map fuzzy-matching (rule-if rule)))) (map fuzzy-inference-combining (rule-then rule)))

21 Fuzzy Matching (define (fuzzy-matching antecedent) (matching-degree (cadr (assoc (car antecedent) fuzzy-inputs)) (eval (cadr antecedent)))) 'if 'then '( (quantity quantity-small) (softness softness-soft)) '(···) 'r1 'quantity 'softness ··· 'fuzzy-inputs

22 Fuzzy Matching 0.00.250.5 1.0 Laundry Quantity = 0.4 Degree of Match = 0.6 Medium

23 Fuzzy Matching 0.00.250.5 1.0 Small Laundry Quantity = 0.4 Degree of Match = 0.4

24 Matching Degree (define (matching-degree x membership-function) (case (length membership-function) (3 (matching-degree-triangle x membership-function)) (4 (matching-degree-trapezoid x membership-function))))

25 Matching Degree (Triangle) (define (matching-degree-triangle x membership-function) (let ((a (car membership-function)) (b (cadr membership-function)) (c (caddr membership-function))) (cond ((< x a) 0.0) ((and (<= a x) (<= x b)) (if (<> a b) (/ (- x a) (- b a)) 1.0)) ((and (<= b x) (<= x c)) (if (<> b c) (/ (- c x) (- c b)) 1.0)) ((< c x) 0.0))))

26 Matching Degree (Trapezoid) (define (matching-degree-trapezoid x membership-function) (let ((a (car membership-function)) (b (cadr membership-function)) (c (caddr membership-function)) (d (cadddr membership-function))) (cond ((< x a) 0.0) ((and (<= a x) (<= x b)) (if (<> a b) (/ (- x a) (- b a)) 1.0)) ((and (<= b x) (<= x c)) 1.0) ((and (<= c x) (<= x d)) (if (<> c d) (/ (- d x) (- d c)) 1.0)) ((< d x) 0.0))))

27 Combining Fuzzy Conclusions (define (fuzzy-inference-combining consequent) (let* ((area (fuzzy-area (eval (cadr consequent)))) (centroid (fuzzy-centroid (eval (cadr consequent)))) (conclusion (assoc (car consequent) fuzzy- outputs)) (numerator (car (cadr conclusion))) (denominator (cadr (cadr conclusion)))) (set! fuzzy-outputs (delete! conclusion fuzzy-outputs)) ···

28 Combining Fuzzy Conclusions ··· (set! fuzzy-outputs (cons (list (car conclusion) (list (+ numerator (* degree-of-match area centroid)) (+ denominator (* degree-of-match area)))) fuzzy-outputs)) #T))

29 Area (define (fuzzy-area membership-function) (case (length membership-function) (3 (fuzzy-area-triangle membership-function)) (4 (fuzzy-area-trapezoid membership-function))))

30 Centroid (define (fuzzy-centroid membership-function) (case (length membership-function) (3 (fuzzy-centroid-triangle membership-function)) (4 (fuzzy-centroid-trapezoid membership-function))))

31 Triangle

32 Area (Triangle) (define (fuzzy-area-triangle membership-function) (* 0.5 (- (caddr membership-function) (car membership-function))))

33 Centroid (Triangle) (define (fuzzy-centroid-triangle membership-function) (let* ((base (car membership-function)) (a (- (cadr membership-function) base)) (b (- (caddr membership-function) base))) (+ base (/ (+ a b) 3))))

34 Trapezoid

35 Area (Trapezoid) (define (fuzzy-area-trapezoid membership-function) (let ((a (- (caddr membership-function) (cadr membership-function))) (b (- (cadddr membership-function) (car membership-function)))) (* 0.5 (+ a b))))

36 Centroid (Trapezoid) (define (fuzzy-centroid-trapezoid membership-function) (let* ((base (car membership-function)) (a (- (caddr membership-function) (cadr membership-function))) (b (- (cadddr membership-function) base)) (c (- (cadr membership-function) base))) (+ base (/ (+ (* 2 a c) (* a a) (* c b) (* a b) (* b b)) (* 3 (+ a b))))))

37 Defuzzification (define (fuzzy-defuzzification conclusion) (let ((numerator (car (cadr conclusion))) (denominator (cadr (cadr conclusion)))) (set! fuzzy-outputs (delete! conclusion fuzzy-outputs)) (set! fuzzy-outputs (cons (list (car conclusion) (/ numerator denominator)) fuzzy-outputs)) #T))


Download ppt "Fuzzy Template for Scheme Language Modeling & Simulation Lab. Sungkyunkwan Univ."

Similar presentations


Ads by Google