Update linear regression to train/predict non-log

main
Eric Ihli 4 years ago
parent 32ac272c8a
commit f54a99258f

@ -134,13 +134,15 @@
estimate. It defines significantly different as exceeding 1.65 times the
standard deviation of the Turing estimate."
[xs ys]
(let [n (count xs)
sum-x (apply + xs)
sum-y (apply + ys)
(let [log-xs (map #(Math/log %) xs)
log-ys (map #(Math/log %) ys)
n (count xs)
sum-x (apply + log-xs)
sum-y (apply + log-ys)
mean-x (/ sum-x n)
mean-y (/ sum-y n)
err-x (map #(- % mean-x) xs)
err-y (map #(- % mean-y) ys)
err-x (map #(- % mean-x) log-xs)
err-y (map #(- % mean-y) log-ys)
err-x-sqr (map #(* % %) err-x)
m (/ (apply + (map #(apply * %) (map vector err-x err-y)))
(apply + err-x-sqr))

@ -41,10 +41,8 @@
(t/testing "The results of the linear regression model are accurate"
(let [r-coll [1 2 3 5 10]
zr-coll [20 10 5 1 2] ;; not really smoothed, but smoothing isn't under test
log-r (map #(Math/log %) r-coll)
log-zr (map #(Math/log %) zr-coll)
linear-model (math/least-squares-linear-regression log-r log-zr)
linear-results (map linear-model (map #(Math/log %) r-coll))]
linear-model (math/least-squares-linear-regression r-coll zr-coll)
linear-results (map linear-model r-coll)]
(t/is (every?
(fn [[expected predicted]]
(approx= expected predicted 0.01))
@ -55,7 +53,7 @@
4.81
2.59
1.12)
(map #(Math/pow Math/E %) linear-results)))))))
linear-results))))))
;; The below passes a sanity check in that each r* is slightly less than r.
#_(t/deftest turing-estimation

Loading…
Cancel
Save