Fix bug, not always taking lgt

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

@ -252,59 +252,41 @@
(inc (/ nr1 nr))))) (inc (/ nr1 nr)))))
(defn estimator (defn estimator
([lm rs nrs] [lm rs nrs]
(estimator lm rs nrs false)) (fn
([lm rs nrs take-lgt?] ([x lgt?]
(fn (let [i (.indexOf rs x)]
([x] (if (= (inc i) (count rs))
(let [i (.indexOf rs x)] [(/ (* (inc x)
(if (= (inc i) (count rs))
(/ (* (inc x)
(lm (inc x))) (lm (inc x)))
(lm x)) (lm x))
(let [turing-estimate (float lgt?]
(/ (* (inc x) (let [turing-estimate (float
(nth nrs (inc i))) (/ (* (inc x)
(nth nrs i))) (nth nrs (inc i)))
r-plus-one-squared (nth nrs i)))
(Math/pow (inc x) 2) r-plus-one-squared
(Math/pow (inc x) 2)
term2
(/ (nth nrs (inc i)) term2
(Math/pow (nth nrs i) 2)) (/ (nth nrs (inc i))
(Math/pow (nth nrs i) 2))
term3
(inc (/ (nth nrs (inc i)) term3
(nth nrs i))) (inc (/ (nth nrs (inc i))
(nth nrs i)))
stdv (Math/sqrt (* r-plus-one-squared term2 term3))
lgt-estimate (/ (* (inc x) stdv (Math/sqrt (* r-plus-one-squared term2 term3))
(lm (inc x))) lgt-estimate (/ (* (inc x)
(lm x))] (lm (inc x)))
(assert (>= i 0) (str x " not found")) (lm x))]
(let [diff (Math/abs (- lgt-estimate turing-estimate)) (assert (>= i 0) (str x " not found"))
take-lgt? (or take-lgt? (let [diff (Math/abs (- lgt-estimate turing-estimate))
(< diff (* 1.95 stdv)))] lgt? (or lgt?
(println (format (str "%.2f %.2f %.2f" (< diff (* 1.95 stdv)))]
"\nstdev %.2f" (if lgt?
"\nx %.2f y %.2f" [lgt-estimate lgt?]
"\ntake-lgt? %b") [turing-estimate lgt?]))))))))
(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