Skip to content

Instantly share code, notes, and snippets.

@x
Created August 12, 2016 08:13
Show Gist options
  • Save x/1f12307a37fe48d9d983f6295b459939 to your computer and use it in GitHub Desktop.
Save x/1f12307a37fe48d9d983f6295b459939 to your computer and use it in GitHub Desktop.
(defn new-model
[num-clicks ts]
(LiveCpmModel. num-clicks 1.0 0.0 ts))
(defrecord LiveCpmModel
[^double a ^double g ^double v ^long lua]
(estimateCpm
[this ts]
(if (= lua rounded-now)
(/ alpha gamma)
(.estimateCpm (.update this 0.0 ts))))
(stepsMissed
^long
[this ts]
(quot (- ts lua) (@options :batch-interval)))
(update
^LiveCpmModel
[this ^double num-clicks ^long ts]
(let [steps (.stepsMissed this ts)
pdil (@options :dilation-factor)
vdil (@options :velocity-dilation-factor)
_a (+ (* a (Math/pow pdil steps)) num-clicks)
_g (+ (* g (Math/pow pdil steps)) (/ (- 1.0 (Math/pow pdil steps)) (- 1.0 pdil)))
cpm-diff (- (.estimateCpm this lua) (.estimateCpm this _a _g ts))
cpm-slope (/ cpm-diff (max steps 1))
_v (+ (* (or delta-curr 0.0) (Math/pow vdil steps)) cpm-slope)]
(LiveCpmModel. _a _g _v ts))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment