Skip to content

Commit 5118be8

Browse files
Added docs
1 parent 008b591 commit 5118be8

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
This package provides a front-end for differentiation operations in Julia that allows for code which is agnostic with respect to many of the available automatic and symbolic differentiation tools available in Julia. Moreover, the differentiation operators provided by **DerivableFunctions.jl** are also overloaded to allow for passthrough of symbolic variables. That is, if symbolic types such as `Symbolics.Num` are detected, the differentiation operators automatically switch to symbolic differentiation.
99

10+
In addition to these operators, **DerivableFunctions.jl** also provides the `DFunction` type, which stores methods for the first and second derivatives to allow for more convenient and potentially more performant computations if the derivatives are known.
11+
12+
For detailed examples, please see the [**documentation**](https://RafaelArutjunjan.github.io/DerivableFunctions.jl/dev).
13+
1014
```julia
1115
julia> D = DFunction(x->[exp(x[1]^2 - x[2]), log(sin(x[2]))])
1216
(::DerivableFunction) (generic function with 1 method)

docs/make.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ makedocs(;
1515
),
1616
pages=[
1717
"Home" => "index.md",
18+
"Differentiation Operators" => "Operators.md",
19+
"DFunctions" => "DFunctions.md"
1820
],
1921
)
2022

docs/src/DFunctions.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
### DFunctions
3+
4+
The `DFunction` type stores the first and second derivatives of a given input function which is not only convenient but can enhance performance significantly. At this point, the `DFunction` type requires the given function to be out-of-place, however, this will likely be extended to in-place functions in the future.
5+
6+
Once constructed, a `DFunction` object `D` can be evaluated at `x` via the syntax `EvalF(D,x)`, `EvaldF(D,x)` and `EvalddF(D,x)`.
7+
8+
In order to construct the appropriate derivatives, the input and output dimensions of a given function `F` are assessed and the appropriate operators (`GetGrad(), GetJac()` and so on) called.
9+
10+
By default, `DFunction()` attempts to construct the derivatives symbolically, however, this can be specified via the `ADmode` keyword:
11+
```@example 2
12+
using DerivableFunctions
13+
14+
D = DFunction(x->[x^7 - sin(x), tanh(x)]; ADmode=Val(:ReverseDiff))
15+
EvalF(D, 5.), EvaldF(D, 5.), EvalddF(D, 5.)
16+
17+
using Symbolics; @variables y
18+
EvalF(D, y), EvaldF(D, y), EvalddF(D, y)
19+
```

docs/src/Operators.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
### Differentiation Operators
3+
4+
[**DerivableFunctions.jl**](https://github.com/RafaelArutjunjan/DerivableFunctions.jl) aims to provide a backend-agnostic interface for differentiation and currently allows the user to seamlessly switch between [**ForwardDiff.jl**](https://github.com/JuliaDiff/ForwardDiff.jl), [**ReverseDiff.jl**](https://github.com/JuliaDiff/ReverseDiff.jl), [**Zygote.jl**](https://github.com/FluxML/Zygote.jl), [**FiniteDifferences.jl**](https://github.com/JuliaDiff/FiniteDifferences.jl) and [**Symbolics.jl**](https://github.com/JuliaSymbolics/Symbolics.jl).
5+
6+
The desired backend is optionally specified in the first argument (default is ForwardDiff) via a `Symbol` or `Val`. The available backends can be listed via `diff_backends()`.
7+
8+
Next, the function that is to be differentiated is provided. We will illustrate this syntax using the `GetMatrixJac` method:
9+
```@example 1
10+
using DerivableFunctions
11+
Metric(x) = [exp(x[1]^3) sin(cosh(x[2])); log(sqrt(x[1])) x[1]^2*x[2]^5]
12+
Jac = GetMatrixJac(Val(:ForwardDiff), Metric)
13+
Jac([1,2.])
14+
```
15+
16+
Moreover, these operators are overloaded to allow for passthrough of symbolic variables.
17+
```@example 1
18+
using Symbolics
19+
@variables z[1:2]
20+
Jac(z)
21+
```
22+
23+
Since the function `Metric` in this example can be represented in terms of analytic expressions, it is also possible to construct its derivative symbolically:
24+
```@example 1
25+
SymJac = GetMatrixJac(Val(:Symbolic), Metric)
26+
SymJac([1,2.])
27+
```
28+
29+
Currently, [**DerivableFunctions.jl**](https://github.com/RafaelArutjunjan/DerivableFunctions.jl) exports `GetDeriv(), GetGrad(), GetHess(), GetJac()` and `GetMatrixJac()`.

0 commit comments

Comments
 (0)