-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
76 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
-- | Various utilities for performing AD. | ||
|
||
import "onehot" | ||
|
||
local def singular 'a (x: onehot.gen [1] a) = onehot.onehot x 0 | ||
|
||
-- | Compute the gradient of a scalar-valued function given a one-hot | ||
-- generator for its result. | ||
def grad_unit gen f x = vjp f x (singular gen) | ||
|
||
-- | Convenience function for computing the gradient of an | ||
-- 'f64'-valued differentiable function. | ||
def grad32 = grad_unit onehot.f32 | ||
|
||
-- | Convenience function for computing the gradient of an | ||
-- 'f64'-valued differentiable function. | ||
def grad64 = grad_unit onehot.f64 | ||
|
||
-- | Compute the gradient of an arbitrary differentiable function | ||
-- given a one-hot generator for its result. | ||
def grad_rev gen f x = map (vjp f x) (onehots gen) |
This file contains 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
This file contains 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