DerivableFunctionsBase
This is the documentation for DerivableFunctionsBase.jl.
This package provides the base functionality of DerivableFunctions.jl without loading all the backends, i.e. only for ForwardDiff.jl.
For in-depth examples and explanations, please see the Documentation of main package DerivableFunctions.jl.
DerivableFunctionsBase.DerivableFunction
DerivableFunctionsBase.Builder
DerivableFunctionsBase.GetArgLength
DerivableFunctionsBase.GetDeriv
DerivableFunctionsBase.GetDoubleJac
DerivableFunctionsBase.GetGrad
DerivableFunctionsBase.GetGrad!
DerivableFunctionsBase.GetHess
DerivableFunctionsBase.GetHess!
DerivableFunctionsBase.GetJac
DerivableFunctionsBase.GetJac!
DerivableFunctionsBase.GetMatrixJac
DerivableFunctionsBase.GetMatrixJac!
DerivableFunctionsBase.GetOutLength
DerivableFunctionsBase.GetSymbolicDerivative
DerivableFunctionsBase.KillAfter
DerivableFunctionsBase.MaximalNumberOfArguments
DerivableFunctionsBase.SymbolicPassthrough
DerivableFunctionsBase._GetArgLength
DerivableFunctionsBase.diff_backends
DerivableFunctionsBase.suff
DerivableFunctionsBase.DerivableFunction
— TypeDerivableFunction(F::Function; ADmode::Union{Val,Symbol}=Val(:Symbolic))
DerivableFunction(F::Function, testinput::Union{Number,AbstractVector{<:Number}}; ADmode::Union{Val,Symbol}=Val(:Symbolic))
DerivableFunction(F::Function, dF::Function; ADmode::Union{Val,Symbol}=Val(:Symbolic))
DerivableFunction(F::Function, dF::Function, ddF::Function)
Stores derivatives of a given function (as well as input-output dimensions) for potentially faster computations when derivatives are known.
DerivableFunctionsBase.Builder
— MethodBuilder(Fexpr::Union{<:AbstractVector{<:Num},<:Num}, args...; inplace::Bool=false, parallel::Bool=false, kwargs...)
Builds RuntimeGeneratedFunctions
from expressions via build_function().
DerivableFunctionsBase.GetArgLength
— MethodGetArgLength(F::Function; max::Int=100) -> Int
Attempts to determine input structure of F
, i.e. whether it accepts Number
s or AbstractVector
s and of what length. This is achieved by successively evaluating the function on rand(i)
until the evaluation no longer throws errors. As a result, GetArgLength
will be unable to determine the correct input structure if F
errors on rand(i)
.
Does NOT discriminate between Real
and Vector{Real}
of length one, i.e. Real
↦+1
. To disciminate between these two options, use _GetArgLength()
instead.
DerivableFunctionsBase.GetDeriv
— MethodGetDeriv(ADmode::Val, F::Function; kwargs...) -> Function
Returns a function which computes the scalar derivative of F
out-of-place via a backend specified by ADmode
.
Example:
Derivative = GetDeriv(Val(:ForwardDiff), x->exp(-x^2))
Derivative(5.0)
For available backends, see diff_backends()
.
DerivableFunctionsBase.GetDoubleJac
— FunctionGetDoubleJac(ADmode::Val, F::Function; kwargs...) -> Function
Returns a function which computes the Jacobian of the Jacobian for a vector-valued function F
out-of-place via a backend specified by ADmode
.
Example:
DoubleJacobian = GetDoubleJac(Val(:ForwardDiff), x->[x[1]^2, x[1]*x[2]^3])
DoubleJacobian(rand(2))
For available backends, see diff_backends()
.
DerivableFunctionsBase.GetGrad!
— MethodGetGrad!(ADmode::Val, F::Function; kwargs...) -> Function
Returns a function which computes gradients in-place via a backend specified by ADmode
. The function returned by GetGrad!
has argument structure (Y::AbstractVector, X::AbstractVector)
where the gradient of F
evaluated at X
is saved into Y
.
Example:
Gradient! = GetGrad!(Val(:ForwardDiff), x->x[1]^2 - x[2]^3)
Y = Vector{Float64}(undef, 2)
Gradient!(Y, rand(2))
For available backends, see diff_backends()
.
DerivableFunctionsBase.GetGrad
— MethodGetGrad(ADmode::Val, F::Function; kwargs...) -> Function
Returns a function which computes the gradient of F
out-of-place via a backend specified by ADmode
.
Example:
Gradient = GetGrad(Val(:ForwardDiff), x->x[1]^2 - x[2]^3)
Gradient(rand(2))
For available backends, see diff_backends()
.
DerivableFunctionsBase.GetHess!
— MethodGetHess!(ADmode::Val, F::Function; kwargs...) -> Function
Returns a function which computes Hessians in-place via a backend specified by ADmode
. The function returned by GetHess!
has argument structure (Y::AbstractMatrix, X::AbstractVector)
where the Hessian of F
evaluated at X
is saved into Y
.
Example:
Hessian! = GetHess!(Val(:ForwardDiff), x->x[1]^2 -x[2]^3 + x[1]*x[2])
Y = Matrix{Float64}(undef, 2, 2)
Hessian!(Y, rand(2))
For available backends, see diff_backends()
.
DerivableFunctionsBase.GetHess
— MethodGetHess(ADmode::Val, F::Function; kwargs...) -> Function
Returns a function which computes the Hessian of F
out-of-place via a backend specified by ADmode
.
Example:
Hessian = GetHess(Val(:ForwardDiff), x->x[1]^2 -x[2]^3 + x[1]*x[2])
Hessian(rand(2))
For available backends, see diff_backends()
.
DerivableFunctionsBase.GetJac!
— MethodGetJac!(ADmode::Val, F::Function; kwargs...) -> Function
Returns a function which computes Jacobians in-place via a backend specified by ADmode
. The function returned by GetJac!
has argument structure (Y::AbstractMatrix, X::AbstractVector)
where the Jacobian of F
evaluated at X
is saved into Y
.
Example:
Jacobian! = GetJac!(Val(:ForwardDiff), x->[x[1]^2, -x[2]^3, x[1]*x[2]])
Y = Matrix{Float64}(undef, 3, 2)
Jacobian!(Y, rand(2))
For available backends, see diff_backends()
.
DerivableFunctionsBase.GetJac
— MethodGetJac(ADmode::Val, F::Function; kwargs...) -> Function
Returns a function which computes the Jacobian of F
out-of-place via a backend specified by ADmode
.
Example:
Jacobian = GetJac(Val(:ForwardDiff), x->[x[1]^2, -x[2]^3, x[1]*x[2]])
Jacobian(rand(2))
For available backends, see diff_backends()
.
DerivableFunctionsBase.GetMatrixJac
— FunctionGetMatrixJac(ADmode::Val, F::Function; kwargs...) -> Function
Returns a function which computes the Jacobian of an array-valued function F
out-of-place via a backend specified by ADmode
.
Example:
Jacobian = GetMatrixJac(Val(:ForwardDiff), x->[x[1]^2 x[2]^3; x[1]*x[2] 2])
Jacobian(rand(2))
For available backends, see diff_backends()
.
DerivableFunctionsBase.GetMatrixJac!
— MethodGetMatrixJac!(ADmode::Val, F::Function; kwargs...) -> Function
Returns a function which computes Jacobians in-place for array-valued functions via a backend specified by ADmode
. The function returned by GetMatrixJac!
has argument structure (Y::AbstractArray, X::AbstractVector)
where the Jacobian of F
evaluated at X
is saved into Y
.
Example:
Jacobian! = GetMatrixJac!(Val(:ForwardDiff), x->[x[1]^2 x[2]^3; x[1]*x[2] 2])
Y = Array{Float64}(undef, 2, 2, 2)
Jacobian!(Y, rand(2))
For available backends, see diff_backends()
.
DerivableFunctionsBase.GetOutLength
— MethodGetOutLength(F::Function, input::Union{Number,AbstractVector{<:Number}})
Returns output dimensions of given F
. If it outputs arrays of more than one dimension, a tuple is returned. This can also be used to determine the approximate size of the input for mutating F
which accept 2 arguments.
Discriminates between Real
and Vector{Real}
of length one, i.e.: Real
↦-1
and x::AbstractVector{<:Real}
↦length(x)
.
DerivableFunctionsBase.GetSymbolicDerivative
— FunctionGetSymbolicDerivative(F::Function, inputdim::Int=GetArgLength(F), deriv::Symbol=:jacobian; timeout::Real=5, inplace::Bool=false, parallel::Bool=false)
Computes symbolic derivatives, including :jacobian
, :gradient
, :hessian
and :derivative
which are specified via deriv
. Special care has to be taken that the correct inputdim
is specified! Silent errors may occur otherwise.
DerivableFunctionsBase.KillAfter
— MethodKillAfter(F::Function, args...; timeout::Real=5, verbose::Bool=false, kwargs...)
Tries to evaluate a given function F
before a set timeout
limit is reached and interrupts the evaluation and returns nothing
if necessary. NOTE: The given function is evaluated via F(args...; kwargs...).
DerivableFunctionsBase.MaximalNumberOfArguments
— MethodMaximalNumberOfArguments(F::Function) -> Int
Infers argument structure of given function, i.e. whether it is of the form F(x)
or F(x,y)
or F(x,y,z)
etc. and returns maximal number of accepted arguments of all overloads of F
as integer.
DerivableFunctionsBase.SymbolicPassthrough
— FunctionExecutes symbolic derivative as specified by deriv::Symbol
.
DerivableFunctionsBase._GetArgLength
— Method_GetArgLength(F::Function; max::Int=100) -> Int
Discriminates between Real
and Vector{Real}
of length one, i.e.: Real
↦-1
and x::AbstractVector{<:Real}
↦length(x)
.
DerivableFunctionsBase.diff_backends
— MethodShows the currently loaded differentation backends available for use with DerivableFunctions.jl
.
DerivableFunctionsBase.suff
— Methodsuff(x) -> Type
If x
stores BigFloats, suff
returns BigFloat, else suff
returns Float64
.