Coder Social home page Coder Social logo

How can I add custom gradients? about ad HOT 11 OPEN

ekmett avatar ekmett commented on September 2, 2024
How can I add custom gradients?

from ad.

Comments (11)

cartazio avatar cartazio commented on September 2, 2024

#15 may help

the code in that version was

erf1 = lift1 erf $ \x -> (fromInteger1 2 /! sqrt1 pi1) *! exp1 (negate1 x *! x)

https://github.com/ekmett/ad/blob/master/src/Numeric/AD/Jacobian.hs
hass the class which is used to facilitate that

from ad.

cartazio avatar cartazio commented on September 2, 2024

point being i believe this answers your question, though please chime in if you want more examples or links / hit a new problem.

but closing for now :)

from ad.

kai-qu avatar kai-qu commented on September 2, 2024

Thanks! I have a nice minimal example working like this:

λ> import Numeric.AD
λ> import Numeric.AD.Jacobian
λ> import Numeric.AD.Internal.Forward
λ> (lift1 (\x -> x^2) (\x -> 2 * x)) (Forward 3 1)
Forward 9 6

However, the Jacobian module only seems to provide primitives for defining derivatives for scalar or two-argument functions. I'd like to define a custom gradient for a function f : R^n -> R, for example something like

liftN (\[x, y, z] -> x * y * z) (\[x, y, z] -> [y * z, x * z, x * y])

Any thoughts on how I could do this? It doesn't seem efficient to try and hack this functionality in terms of lift1.

from ad.

cartazio avatar cartazio commented on September 2, 2024

from ad.

cartazio avatar cartazio commented on September 2, 2024

@hypotext it is a gap, and its currently not quite possible to do gradients etc with "custom rules", which is a problem i think we'd both agree

from ad.

kai-qu avatar kai-qu commented on September 2, 2024

from ad.

cartazio avatar cartazio commented on September 2, 2024

ok, lets start with several sub questions

  1. what should/would this api look like?
  2. how should/would this interact with calculating higher derivatives etc?

what types would you expect/hope the interfaces to have?

from ad.

kai-qu avatar kai-qu commented on September 2, 2024

from ad.

cartazio avatar cartazio commented on September 2, 2024

ok, :)

from ad.

cartazio avatar cartazio commented on September 2, 2024

I'm honestly thinking about experimenting with writing a ghc core plugin to support better optimization for autodiff computations on ghc core level sometime this jan/feb

from ad.

dschrempf avatar dschrempf commented on September 2, 2024

Hi! May I ask about the status of this issue? I am in a similar situation as the author. Thank you!

from ad.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.