Skip to content

Instantly share code, notes, and snippets.

@rxacevedo
Created March 17, 2015 15:59
Show Gist options
  • Select an option

  • Save rxacevedo/1d554c929858ff45fccc to your computer and use it in GitHub Desktop.

Select an option

Save rxacevedo/1d554c929858ff45fccc to your computer and use it in GitHub Desktop.
Incanter
(let [data (for [i (range 10)]
[i i])
h (fn [theta-0 theta-1]
(fn [x] (+ theta-0 (* theta-1 x))))
j (fn [theta-0 theta-1]
(* (/ 1 (* 2 (count data)))
(apply + (map (fn [[x y]]
(pow (- ((h theta-0 theta-1) x) y) 2))
data))))
thetas (for [theta-0 (range -2 2)
theta-1 (range -2 2)]
[theta-0 theta-1])
plot (charts/scatter-plot
(map first data)
(map last data)
:series-label "Points"
:x-label "X"
:y-label "Y"
:legend true)]
(view
(reduce (fn [l [r1 r2]] (charts/add-function l (h r1 r2) 0 10 :series-label (j r1 r2)))
plot
thetas)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment