Fix bug, not always taking lgt

main
Eric Ihli 4 years ago
parent 79fa3e2d80
commit 3bd356fa8b

@ -252,16 +252,15 @@
(inc (/ nr1 nr))))) (inc (/ nr1 nr)))))
(defn estimator (defn estimator
([lm rs nrs] [lm rs nrs]
(estimator lm rs nrs false))
([lm rs nrs take-lgt?]
(fn (fn
([x] ([x lgt?]
(let [i (.indexOf rs x)] (let [i (.indexOf rs x)]
(if (= (inc i) (count rs)) (if (= (inc i) (count rs))
(/ (* (inc x) [(/ (* (inc x)
(lm (inc x))) (lm (inc x)))
(lm x)) (lm x))
lgt?]
(let [turing-estimate (float (let [turing-estimate (float
(/ (* (inc x) (/ (* (inc x)
(nth nrs (inc i))) (nth nrs (inc i)))
@ -283,28 +282,11 @@
(lm x))] (lm x))]
(assert (>= i 0) (str x " not found")) (assert (>= i 0) (str x " not found"))
(let [diff (Math/abs (- lgt-estimate turing-estimate)) (let [diff (Math/abs (- lgt-estimate turing-estimate))
take-lgt? (or take-lgt? lgt? (or lgt?
(< diff (* 1.95 stdv)))] (< diff (* 1.95 stdv)))]
(println (format (str "%.2f %.2f %.2f" (if lgt?
"\nstdev %.2f" [lgt-estimate lgt?]
"\nx %.2f y %.2f" [turing-estimate lgt?]))))))))
"\ntake-lgt? %b")
(float (inc x)) (float (nth nrs (inc i))) (float (nth nrs i))
(float stdv)
(float turing-estimate) (float lgt-estimate)
take-lgt?))
(if take-lgt?
lgt-estimate
turing-estimate))))))
([x rs nrs]
(let [i (.indexOf rs x)]
(if take-lgt?
(/ (* (inc x)
(lm (inc x)))
(lm x))
(float (/ (* (inc x)
(nth nrs (inc i)))
(nth nrs i)))))))))
(defn sgt [rs nrs] (defn sgt [rs nrs]
(assert (and (not-empty nrs) (not-empty rs)) (assert (and (not-empty nrs) (not-empty rs))
@ -318,17 +300,19 @@
lm (least-squares-linear-regression log-rs log-zrs) lm (least-squares-linear-regression log-rs log-zrs)
lgts (map lm rs) lgts (map lm rs)
estimations (loop [coll rs estimations (loop [coll rs
lgt? false
e (estimator lm rs zrs) e (estimator lm rs zrs)
estimations []] estimations []]
(cond (cond
(empty? coll) estimations (empty? coll) estimations
:else :else
(let [estimation (e (first coll))] (let [[estimation lgt?] (e (first coll) lgt?)]
(recur (recur
(rest coll) (rest coll)
lgt?
e e
(conj estimations estimation))))) (conj estimations estimation)))))
#_#_ N* (apply + (map #(apply * %) (map vector rs estimations))) #_#_ N* (apply + (map #(apply * %) (map vector rs estimations)))
] ]
[estimations])) [estimations]))

Loading…
Cancel
Save