-
Notifications
You must be signed in to change notification settings - Fork 3
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
Naive gradient descent example #75
base: master
Are you sure you want to change the base?
Conversation
bcb3a62
to
60b73bc
Compare
79243e9
to
ba9a93d
Compare
The result shows matched results (first 10 points in minimum finding history) from Haskell and generated-C
|
and generated C file (gradient of Rosenbrock function)
|
51103de
to
9d66c45
Compare
9d66c45
to
b7c2acc
Compare
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 could also use a bunch of Haddock / comments about what it's doing and why – e.g., what does this example illustrate; why do we need f
parameters in this case (because ad
, yada yada); why is wrap_rosenbrockF
uncurried; etc.
|
||
$(Categorify.separately 'rosenbrockF [t|C.Cat|] [pure [t|C|]]) | ||
|
||
$(Categorify.separately 'dRosenbrockF [t|C.Cat|] [pure [t|C|]]) |
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.
separately
no longer exists on master. This should be Categorify.function
. Also, we don't need $(...)
on top-level splices.
|
||
$(embedFunction "rosenbrockF" wrap_rosenbrockF) | ||
|
||
$(embedFunction "dRosenbrockF" wrap_dRosenbrockF) |
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.
Same re: $(...)
on top-level splices.
|
||
dRosenbrock :: forall a. Num a => (a, a) -> (a, a) -> (a, a) | ||
dRosenbrock (a, b) (x, y) = | ||
let rosenbrock' :: forall s. Reifies s Tape => [Reverse s a] -> Reverse s a |
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.
There is a Pair
type defined in categorifier, that seems better than []
here, since it's not partial.
in (dfdx, dfdy) | ||
|
||
rosenbrockF :: KType1 f => Input f -> Output f | ||
rosenbrockF (Input (Param a b) (XY x y)) = Output $ rosenbrock (a, b) (x, y) |
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 feel like we can get rid of Input
and Output
, and just have
rosenbrockF :: KType1 f => (Param f, XY f) -> f Double
rosenbrockF (Param a b, XY x y) = rosenbrock (a, b) (x, y)
I'd rather have this be Param f -> XY f -> f Double
, but I'm guessing it needs to be uncurried for embedFunction
?
dRosenbrockF :: forall f. (KType1 f) => Input f -> XY f | ||
dRosenbrockF (Input (Param a b) (XY x y)) = | ||
let (dfdx, dfdy) = dRosenbrock (a, b) (x, y) | ||
in XY dfdx dfdy |
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.
Similar change here
dRosenbrockF :: forall f. (KType1 f) => (Param f, XY f) -> XY f
dRosenbrockF (Param a b, XY x y) = uncurry XY $ dRosenbrock (a, b) (x, y)
|
||
$(Categorify.separately 'rosenbrockF [t|C.Cat|] [pure [t|C|]]) | ||
|
||
$(Categorify.separately 'dRosenbrockF [t|C.Cat|] [pure [t|C|]]) |
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.
Orthogonal to this change, but I do want to put together an example that does something similar to this, without ad
, like
Categorify.expression @C.Cat (unD (Categorify.expression @ConCat.RAD dRosenbrockF))
to illustrate nested categorification (which may not actually work yet).
Using
ad
library, a minimum of a non-trivial function (Rosenbrock function) is computed both by pure Haskell and codegen C linked via FFI, and they are compared.