0

i want to write a project get a precise value for calorie to calculate the precise value of the then part(how much weight increased?).this is my rule:

if calorie is high then increase weight

for this i have this set for calorie:

(highCalorie (20 0)(40 .2) (60 .5) (100 .8) (180 1))

and in the other hand for value of increase weight i have this set:

 (increase(50 0) (100 .4) (120 .8) (150 1))

in other word i want to map a value for calorie to increase weight. for do this i write this code :

(deftemplate calories
   20 180 
   (high(20 0)(40 .2) (60 .5) (100 .8) (180 1))
)
(deftemplate fat
   50 150 
   (increase(50 0) (100 .4) (120 .8) (150 1))
)

; We first get a precise value for calorie and fuzzify it.

(defrule getCalorie
   (declare (salience 100))
   =>
   (printout t "Enter calorie: ")
   (bind ?t (read))
   (assert (calorie ?t))
)

(defrule fuzzifyCalorie
   (calorie ?t)
   =>
   (assert (calories (?t 0) (?t .2) (?t .5)(?t .8)(?t 1))))

; Here we add rules to prescribe amounts of increased weight

(defrule result
    (declare (salience -1))
   (calories high)
   =>
   (assert (fat increase)))

(defrule ShowPenicillin
   (declare (salience -100))
   ?f <- (fat ?p)
   =>
   (printout t "for this colrie" (moment-defuzzify ?f) " grams of fat increased to weight" crlf))

what is my mistake?

thanks alot.

zara-T
  • 91
  • 11

1 Answers1

0

Your deftemplates have missing parentheses. The corrected code is

(deftemplate calories
   20 180 
   ((high (20 0)
          (40 .2) 
          (60 .5) 
          (100 .8) 
          (180 1))))

(deftemplate fat
   50 150 
   ((increase (50 0) 
              (100 .4) 
              (120 .8) 
              (150 1))))
Gary Riley
  • 10,130
  • 2
  • 19
  • 34
  • tnx, in your code for example (20 0) is mean that validate of 20 in calories set is 0? is this true? – zara-T Jun 14 '15 at 18:55
  • I think that's what's referred to as the grade of membership. So a value of 20 would not considered to be high. There's some documentation I found here: http://alumni.cs.ucr.edu/~vladimir/cs171/quickfuzzy.pdf. – Gary Riley Jun 14 '15 at 19:03
  • i try what you said but it did not work i changed my code. and it work but i do not understand the meaning of these line? (defrule fuzzifyCalorie (calorie ?t) => (assert (calories (?t 0) (?t 1) (?t 0)))) thanks for your helps – zara-T Jun 14 '15 at 19:42
  • From what I can tell, that's the description of the fuzzy set for the fact. So if ?t were 50, you'd have (calories (50 0) (50 1) (50 0)) which means the value is definitely 50. If you specified it as (calories (40 0) (50 1) (60 0)) that would mean it was between 40 and 60 with the highest probability being 50. – Gary Riley Jun 14 '15 at 23:32