Fix bug, not always taking lgt

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

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

Loading…
Cancel
Save