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
sellout
left a comment
There was a problem hiding this comment.
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.
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.
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.
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.
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.
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.
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
adlibrary, 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.