clj-ml icon indicating copy to clipboard operation
clj-ml copied to clipboard

Inifinite loop when checking for nominal values

Open gireeshramji opened this issue 9 years ago • 0 comments

When setting up datasets with nominal values and subsequently using instance-to-map or instance-to-vector to inspect individual instances in the dataset, the termination condition in data/instance-value-at is not guaranteed to be met, due to the comparison between a float and an int here:

(defn instance-value-at [instance pos]
  "Returns the value of an instance attribute"
  (let [attr (.attribute instance pos)]
    (if (.isNominal attr)
      (let [val (.value instance pos)
            a (println "val " val)
            key-vals (dataset-values-at instance pos)
            key-val (loop [ks (keys key-vals)]
                      (if (= (get key-vals (first ks))
                             val)
                        (first ks)
                        (recur (rest ks))))]
        key-val)
      (.value instance pos))))

Here val is a float, while the vals of the map returned by dataset-values-at are ints. Comparing 0 to 0.0 in the terminal condition results in false leading to an infinite loop. I had this issue even with the example mentioned in the readme.

gireeshramji avatar Dec 28 '15 10:12 gireeshramji