2

对于这个问题,我被分配实现一个函数,该函数在给定数据的情况下决定决策树的输出。逻辑:如果是符号,那么就是输出的值,否则,在内存中查找varname的值,如果小于等于阈值,则在left-tree中查找该值,如果大于超过阈值,在右树中查找值

决策树是: 一个符号,例如 'versicolor 或 [ varname threshold left-tree right-tree ]

这是我已经完成的,

(defun decision (tree memory)
  (if (not (equal (len tree) 0))
      (if (not (equal (first tree) (first memory)))
          (decision tree (rest memory))
          (if (<= (second tree) (second memory))
              (decision (third tree) memory)
              (decision (fourth tree) memory)))
      tree))

这是一个单元测试:

(check-expect (decision *IRIS-DECISION-TREE* 
                        (search-list-to-tree '((petal-length 2) 
                                               (petal-width 2)
                                               (sepal-length 5)))) 
              'setosa)

这是使用的常量的定义

(defconst *IRIS-DECISION-TREE*
  '(petal-length 245/100
    setosa
    (petal-width 175/100
      (petal-length 495/100
        (petal-width 165/100
          versicolor
          virginica)
        (petal-width 155/100
          virginica
          (sepal-length 695/100
            versicolor
            virginica)))
      (petal-length 485/100
        (sepal-length 595/100
          versicolor
          virginica)
        virginica))))

当函数到达递归调用时,我不断收到错误。它说“(DEFUN DECISION ...)中的ACL2错误:否:MEASURE提供了DECISION的定义。”

我测试了每个 if 语句以查看它们是否有效,并多次在我的脑海中运行代码的逻辑,似乎我可能遇到的唯一问题可能是语法错误,但一切似乎都是正确的。

4

0 回答 0