;;;====================================================== ;;; Weather Prediction Expert System for London ;;; ;;; ;;; ;;; FuzzyCLIPS Version 6.0 Example ;;; ;;; To execute, merely load, reset, and run. ;;;====================================================== (defrule rainrainrule "if it is raining it is likely to continue raining" (declare (cf .5)) ; certainty factor for rule is .5 (today rain) => (assert (tomorrow rain)) ) (defrule drydryrule "if it is dry it is likely to continue being dry" (declare (cf .5)) ; certainty factor for rule is .5 (today dry) => (assert (tomorrow dry)) ) (defrule rainclearingrule "if it is raining but not much, maybe it is clearing " (declare (cf .6)) (today rain) (rain low) => (assert (tomorrow dry)) ) (defrule raincoldclearingrule "if it is raining but not much, and it is cold out, maybe it is clearing " (declare (cf .7)) (today rain) (rain low) (temp cold) => (assert (tomorrow dry)) ) (defrule dryrainrule "if it is dry but temperature is warm - maybe we'll get rain" (declare (cf .65)) (today dry) (temp warm) => (assert (tomorrow rain)) ) (defrule dryovercastrainrule "if it is dry but temperature is warm and sky is overcast - maybe we'll get rain" (declare (cf .55)) ;; not sure why this is less certain than previous (today dry) (temp warm) (sky overcast) => (assert (tomorrow rain)) ) (defrule combineEvidenceRule " combine evidence reaching the same conclusion" ?f1 <- (tomorrow ?answ) ?f2 <- (tomorrow ?answ) ;;; same answer (test (not (eq ?f1 ?f2))) => ;;(if (not (eq ?f1 f2)) ;;then (printout t "facts " ?f1 " " ?f2 t) (bind ?cf1 (get-cf ?f1)) (bind ?cf2 (get-cf ?f2)) (printout t "one minus " (- 1 ?cf1) t) (printout t "times " (* ?cf2 (- 1 ?cf1)) t) (printout t "revised " (+ ?cf1 (* ?cf2 (- 1 ?cf1))) t) (bind ?newcf (+ ?cf1 (* ?cf2 (- 1 ?cf1)))) (retract ?f1) (retract ?f2) (disable-rule-cf-calculation) ;; turn off rule cf calculations (assert (tomorrow ?answ) cf ?newcf) (enable-rule-cf-calculation) ;; turn back on again ;;) ;; end if ) (defrule answerrule " specify the answer with certainty factor" ?f <- (tomorrow ?answ) => (printout t t " The prediction is " ?answ " with certainty factor " (get-cf ?f) t ) )