Jess and FuzzyJ assistance
I'm trying to learn Jess and FuzzyJ but am having problems getting a simple program to run. I have looked at it for hours and am no quite sure why it doesn't run. If someone could point me in the right direction it would be very much appreciated.
;;;;;;;;;;;;;;;;;;;;;;;;;
Fuzzy Variables
;;;;;;;;;;;;;;;;;;;;;;;;;;
(defglobal ?*income* =
(new nrc.fuzzy.FuzzyVariable "income" 0.0 230000.00 "dollars"))
(defglobal ?*stability* =
(new n开发者_运维知识库rc.fuzzy.FuzzyVariable "stability" 0.0 1.0 "index"))
(defglobal ?*liquidity* =
(new nrc.fuzzy.FuzzyVariable "liquidity" 0.0 1.0 "index"))
(defrule initial-terms
(declare (salience 100))
=>
(import nrc.fuzzy.*)
(load-package nrc.fuzzy.jess.FuzzyFunctions)
;;;;;;;;;;;;;;;;;;;;;
Primary Terms
;;;;;;;;;;;;;;;;;;;;;;;
(?*income* addTerm "low" (new ZFuzzySet 30000.00 80000.00))
(?*income* addTerm "medium" (new PIFuzzySet 100000.00 60000.00))
(?*income* addTerm "high" (new SFuzzySet 80000.00 190000.00))
(?*stability* addTerm "low" (new ZFuzzySet .3 .5))
(?*stability* addTerm "medium" (new PIFuzzySet .6 .4))
(?*stability* addTerm "high" (new SFuzzySet .7 .9))
(?*liquidity* addTerm "low" (new ZFuzzySet .3 .5))
(?*liquidity* addTerm "medium" (new PIFuzzySet .6 .4))
(?*liquidity* addTerm "high" (new SFuzzySet .7 . 9))
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Fuzzy Rules
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defrule rule-1 "low income => liquidity very low"
(theIncome ?x &: (fuzzy-match ?x "low"))
=>
(assert(theLiquidity (new nrc.fuzzy.FuzzyValue ?*liquidity* "very low")))
(defrule rule-2 "high income & high stability => very high liquidity"
(theIncome ?x &: (fuzzy-match ?x "high"))
(theStability ?y (fuzzy-match ?y "high"))
=>
(assert(theLiquidity (new nrc.fuzzy.FuzzyValue ?*liquidity* "very high"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Defuzzification
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defrule defuzzification-and-display-liquidity
(declare (salience -1))
?f <- (theLiquidity ?z)
=>
(printout t (str-cat "Liquidity: " (?z momentDefuzzify)))
retract( ?f)
(halt))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Start up Rule/Fuzzify
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defrule assert-income-and-stability "initialization"
=>
(printout t "Enter the income(ex. 52000): ")
(bind ?income-value (float (readline t)))
(printout t "Enter the stability index(ex. 0.64): ")
(bind ?stability-value (float(readline t)))
(assert(theIncome
(new nrc.fuzzy.FuzzyValue ?*income*
(new nrc.fuzzy.TriangleFuzzySet
(- ?income-value 3000.0)
?income-value
(+ ?income-value 3000.0)))))
(assert(theStability
(new nrc.fuzzy.FuzzyValue ?*stability*
(new nrc.fuzzy.TriangleFuzzySet
(- ?stability-value 3000.0)
?stability-value
(+ ?stability-value 3000.0))))))
(reset)
(run)
There are many small syntax errors in this program; in general the Jess interpreter does a good job of pointing them out. First of all, in each of your comment blocks, you've got the actual text of the comment... not commented. So add a semicolon to the beginning of the lines like "Fuzzy Variables", for instance.
Second, on the line
(?*liquidity* addTerm "high" (new SFuzzySet .7 . 9))
there ought to be no space after that last decimal point.
Third, the rules rule-1
and rule-2
don't have enough close-parentheses at the end. Any decent programmer's editor able to format Lisp code should be able to help you fix that.
Fourth, on the line
(theStability ?y (fuzzy-match ?y "high"))
you're missing the "&:" before the predicate function -- see the previous line.
Finally, I think, the line
retract( ?f)
is malformed -- should be (retract ?f)
.
精彩评论