Jess 和 FuzzyJ 的协助

发布于 2024-11-02 11:45:14 字数 2757 浏览 3 评论 0原文

我正在尝试学习 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)

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 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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

用心笑 2024-11-09 11:45:14

这个程序有很多小的语法错误;总的来说,杰西的翻译在指出这些问题方面做得很好。首先,在每个评论块中,您都有评论的实际文本......未评论。因此,例如,在“模糊变量”等行的开头添加一个分号。

其次,该行

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

最后一个小数点后不应有空格。

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

第四,在该行中,

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

谓词函数之前缺少“&:”——请参阅上一行。

最后,我认为该行格式

retract( ?f)

错误 - 应该是 (retract ?f)

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) .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文