Skip to content
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

Update README.md #736

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,47 @@ top:
}
```

An example to differentiate a general function gg: R2->R3.

```julia
julia> g1(x) = cos(x[1]) + sin(x[2])
g1 (generic function with 1 method)

julia> g2(x) = x[1]^2 + x[2]^2
g2 (generic function with 1 method)

julia> g3(x) = log(x[1]) + exp(x[2])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the need for g1, g2, and g3? What do they help to demonstrate?

g3 (generic function with 1 method)

julia> gg(x) = [g1(x); g2(x); g3(x)]
gg (generic function with 1 method)

julia> x = [1.0; 2.0]
2-element Array{Float64,1}:
1.0
2.0

julia> Zygote.gradient(g1,x)
([-0.8414709848078965, -0.4161468365471424],)

julia> Zygote.gradient(g2,x)
([2.0, 4.0],)

julia> Zygote.gradient(g3,x)
([1.0, 7.38905609893065],)

julia> Zygote.forward_jacobian(gg,x)[2]
2×3 Array{Float64,2}:
-0.841471 2.0 1.0
-0.416147 4.0 7.38906

julia> Zygote.hessian(g1,x)
2×2 Array{Float64,2}:
-0.540302 0.0
0.0 -0.909297
```


"Source-to-source" means that Zygote hooks into Julia's compiler, and generates the backwards pass for you – as if you had written it by hand.

Without compromising on performance, Zygote supports the full flexibility and dynamism of the Julia language, including control flow, recursion, closures, structs, dictionaries, and more.
Expand Down