Giter VIP home page Giter VIP logo

autodiff.jl's Introduction

AutoDiff.jl

Disclaimer: In its current state, this package may not meet requirements of a general user.

This package is not registered due to the concern which may not meet requirements of a general user.

DOI

AutoDiff.jl is a basic reverse differentiation package inspired by the talk of Prof. Edelman. Similar to DualNumbers, AutoDiff provides the type BD. BD can be considered as backward-derivation. After every operation, a tuple of the result of the operation and the reverse function which will provide gradients w.r.t inputs of the operation.

using AutoDiff

f(x) = x^2

@differentiate a = 3

yfdy = f(a)
y,fdy=yfdy.f

println(y) # (:da => 6), since only a is tracked, :da is stored as a pair
println(params(fdy(1)))# That will give a dictionary of tracked variables, for this case :da => 6

Any type which is not tracked will be automatically converted to a BD type for derivative calculation. Tracked variables can be obtained easily by calling derivative function inside the params function.

Slightly more complicated example:

using AutoDiff

@differentiate i = rand(4, 1)
@differentiate w = rand(4, 4)
@differentiate o = rand(3, 4)

function f(x)
    x = w*x
    x = o*x
    return x
end

y = sum(abs2.(1.0 .-f(i)))

_dy, _rest = y.f[2](y.f[1])

params(_rest)

You may check the example folder, there are jupyter notebooks with basic usage.

autodiff.jl's People

Contributors

hiiroo avatar

Watchers

 avatar  avatar

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.