Jess和FuzzyJ协助

时间:2011-04-19 19:39:10

标签: fuzzy jess

我正在尝试学习Jess和FuzzyJ,但是在运行一个简单的程序时遇到了问题。我已经看了几个小时,我不确定它为什么不运行。如果有人能指出我正确的方向,那将非常感激。

;;;;;;;;;;;;;;;;;;;;;;;;;
Fuzzy Variables
;;;;;;;;;;;;;;;;;;;;;;;;;;

(defglobal ?*income* = 
    (new nrc.fuzzy.FuzzyVariable "income" 0.0 230000.00 "dollars"))
(defglobal ?*stability* =
    (new nrc.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)

1 个答案:

答案 0 :(得分:1)

此程序中存在许多小的语法错误;一般来说,Jess解释器可以很好地指出它们。首先,在每个评论区块中,您已获得评论的实际文本...未评论。因此,在行的开头添加分号,例如“模糊变量”。

第二,在线

(?*liquidity* addTerm "high" (new SFuzzySet .7 . 9))

在最后一个小数点之后应该没有空格。

第三,规则rule-1rule-2最后没有足够的括号。任何体面的程序员编辑能够格式化Lisp代码应该能够帮助你解决这个问题。

第四,在线

(theStability ?y (fuzzy-match ?y "high"))

你在谓词函数之前缺少“&amp;:” - 请参阅上一行。

最后,我想,行

retract( ?f)

格式错误 - 应为(retract ?f)