Created
March 17, 2015 15:59
-
-
Save rxacevedo/1d554c929858ff45fccc to your computer and use it in GitHub Desktop.
Incanter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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