-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Springs [WIP] #1
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice!! I'd love to see a screenshot, but I'll also run this myself!
src/maturin/springs.clj
Outdated
(defn L-regression | ||
[xs ys k] | ||
(fn [[_ [slope intercept] _]] | ||
(let [preds (map (linear-func slope intercept) xs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these are definitely generalized coordinates :)
If you wanted to decompose this further, you could make a "spring" lagrangian, that takes, for position, a sequence of spring-stretches only... and then compose that with a transformation that does what you do internally, maps the
(defn line->offsets [xs ys]
(fn [[slope intercept]]
(let [preds (map (linear-func slope intercept) xs)]
(mapv - preds ys))))
Then
(defn L-regression [xs ys k]
(compose (L-springs k) (F->C (line->offsets xs ys))
should work! Just an idea...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented this, ran into a different problem, see comment below.
src/maturin/springs.clj
Outdated
(q/background 100) | ||
(q/fill color 255 255) | ||
(let [[slope intercept] (convert state)] | ||
(attach [0 intercept] [10 ((linear-func slope intercept) 10)]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is very cool. If you take my idea from above, about composing, I think you could use the exact same transformation to get positions for all of the points.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still can't get the graphics to work; the things I'm curious about (but can't experiment with at the moment) - if the drawing function only takes in the state - the intercept and the slope - how can I draw the xs and ys?
src/maturin/springs.clj
Outdated
(up 1 1) | ||
1) | ||
built (build L initial-state)] | ||
(q/defsketch regression |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to see it!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lol me too :-)
Thanks for your comments Sam! I've implemented (defn L-regression-composed [xs ys k]
(compose (L-springs k) (F->C (line->offsets xs ys)))) But now, when I call (let [L (L-regression-composed x y 1)
initial-state (up 1
(up 1 1)
1)
built (build L initial-state)]
(q/defsketch regression
:title "Regression line"
:size [500 500]
:setup (:setup built)
:update (:update built)
:draw (draw-line (:xform built))
:features [:keep-on-top]
:middleware [m/fun-mode m/navigation-2d])) I get:
When I use the original |
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any idea why Calva/cljfmt (my Clojure VSCode extension) forces the double spacing here? Same for the "fake data" comment below, but most comments don't have this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strange, I do not!!
Hey, I'll load up your code in the next couple of days and give it a run myself to see what's up here! |
Basic functionality for springs-regression animation.
Some todos:
better.clj
? ~~Add PCA animations (springs unconstrained on the rod's end)