gradient, jacobian, hessian

Extracts specific partial derivatives from a TPS

Syntax

grad = GTPSA.gradient(f [, include_params=bool])
GTPSA.gradient!(grad, f [, include_params=bool])

J = GTPSA.jacobian(F [, include_params=bool])
GTPSA.jacobian!(J, F [, include_params=bool])

Jt = GTPSA.jacobiant(F [, include_params=bool])
jacobiant!(Jt, F [, include_params=bool])

H = GTPSA.hessian(f [, include_params=bool])
GTPSA.hessian!(H, f [, include_params=bool])

Description

grad = GTPSA.gradient(f) extracts the gradient from the TPS f, defined as $\nabla f$

GTPSA.gradient!(grad, f) fills grad vector in-place with the gradient extracted from the TPS f


J = GTPSA.jacobian(F) extracts the Jacobian matrix from the array of TPSs F, defined as $J_{ij} = \frac{\partial F_i}{\partial x_j}$

GTPSA.jacobian!(J, F) fills the J matrix in-place with the Jacobian extracted from the array of TPSs F


Jt = GTPSA.jacobiant(F) extracts the transpose of the Jacobian matrix from the vector of TPSs F, with the Jacobian defined as $J_{ij} = \frac{\partial F_i}{\partial x_j}$

GTPSA.jacobiant!(Jt, F) fills the Jt matrix in-place with the transpose of the Jacobian extracted from the vector of TPSs F


H = GTPSA.hessian(f) extracts the Hessian matrix from the TPS f, defined as $H_{ij} = \frac{\partial^2 f}{\partial x_i\partial x_j}$

GTPSA.hessian!(H, f) fills the H matrix in-place with the Hessian extracted from the TPS f


Optional Argument

include_params can be set to true (default is false) to include the partial derivatives with respect to the parameters in any of the extraction functions above.

Examples


julia> d = Descriptor(2,10);
julia> x = vars(d);
julia> f = x[1] + 2*x[2] + 3*x[1]^2 + 4*x[1]*x[2] + 5*x[2]^2;
julia> g = 5*x[1] + 4*x[2] + 3*x[1]^2 + 2*x[1]*x[2] + x[2]^2;
julia> grad = GTPSA.gradient(f)2-element Vector{Float64}: 1.0 2.0
julia> J = GTPSA.jacobian([f, g])2×2 Matrix{Float64}: 1.0 2.0 5.0 4.0
julia> H = GTPSA.hessian(f)2×2 Matrix{Float64}: 6.0 4.0 4.0 10.0

Documentation

GTPSA.gradientFunction
GTPSA.gradient(t::TPS; include_params=false)

Extracts the first-order partial derivatives (evaluated at 0) from the TPS. The partial derivatives wrt the parameters will also be extracted when the include_params flag is set to true. Note that this function is not calculating anything - just extracting the first-order monomial coefficients already in the TPS.

Input

  • tTPS/ComplexTPS64 to extract the gradient from
  • include_params – (Optional) Extract partial derivatives wrt parameters. Default is false

Output

  • grad – Gradient of the TPS
source
GTPSA.gradient!Function
GTPSA.gradient!(result, t::TPS; include_params=false)

Extracts the first-order partial derivatives (evaluated at 0) from the TPS and fills the result vector in-place. The partial derivatives wrt the parameters will also be extracted when the include_params flag is set to true. Note that this function is not calculating anything - just extracting the first-order monomial coefficients already in the TPS.

Input

  • tTPS/ComplexTPS64 to extract the gradient from
  • include_params – (Optional) Extract partial derivatives wrt parameters. Default is false

Output

  • result – Vector to fill with the gradient of the TPS, must be 1-based indexing
source
GTPSA.jacobianFunction
GTPSA.jacobian(m::AbstractArray{<:TPS}; include_params=false)

Extracts the first-order partial derivatives (evaluated at 0) from the array of TPSs. The partial derivatives wrt the parameters will also be extracted when the include_params flag is set to true. Note that this function is not calculating anything - just extracting the first-order monomial coefficients already in the TPSs.

Input

  • m – Array of TPSs to extract the Jacobian from, must be 1-based indexing
  • include_params – (Optional) Extract partial derivatives wrt parameters. Default is false

Output

  • J – Jacobian of m
source
GTPSA.jacobian!Function
GTPSA.jacobian!(result, m::AbstractArray{<:TPS}; include_params=false)

Extracts the first-order partial derivatives (evaluated at 0) from the array of TPSs. and fills the result matrix in-place. The partial derivatives wrt the parameters will also be extracted when the include_params flag is set to true. Note that this function is not calculating anything - just extracting the first-order monomial coefficients already in the TPSs.

Input

  • m – Array of TPSs to extract the Jacobian from, must be 1-based indexing
  • include_params – (Optional) Extract partial derivatives wrt parameters. Default is false

Output

  • result – Matrix to fill with the Jacobian of m, must be 1-based indexing
source
GTPSA.jacobiantFunction
GTPSA.jacobiant(m::AbstractVector{<:TPS}; include_params=false) where {N,P,I}

Extracts the first-order partial derivatives (evaluated at 0) from the Vector of TPSs, as the transpose of the Jacobian. The partial derivatives wrt the parameters will also be extracted when the include_params flag is set to true. Note that this function is not calculating anything - just extracting the first-order monomial coefficients already in the TPSs.

Input

  • m –`Vector of TPSs to extract the Jacobian from, must be 1-based indexing
  • include_params – (Optional) Extract partial derivatives wrt parameters. Default is false

Output

  • Jt – Transpose of the Jacobian of m
source
GTPSA.jacobiant!Function
GTPSA.jacobiant!(result, m::AbstractVector{<:TPS}; include_params=false)

Extracts the first-order partial derivatives (evaluated at 0) from the Vector of TPSs, as the transpose of the Jacobian. The partial derivatives wrt the parameters will also be extracted when the include_params flag is set to true. Note that this function is not calculating anything - just extracting the first-order monomial coefficients already in the TPSs and filling result.

Input

  • m – Vector of TPSs to extract the Jacobian from, must be 1-based indexing
  • include_params – (Optional) Extract partial derivatives wrt parameters. Default is false

Output

  • result – Matrix to fill with the transpose of the Jacobian of m, must be 1-based indexing
source
GTPSA.hessianFunction
GTPSA.hessian(t::TPS; include_params=false)

Extracts the second-order partial derivatives (evaluated at 0) from the TPS. The partial derivatives wrt the parameters will also be extracted when the include_params flag is set to true. Note that this function is not calculating anything - just extracting the second-order monomial coefficients already in the TPS.

Input

  • tTPS/ComplexTPS64 to extract the Hessian from
  • include_params – (Optional) Extract partial derivatives wrt parameters. Default is false

Output

  • H – Hessian of the TPS
source
GTPSA.hessian!Function
GTPSA.hessian!(result, t::TPS; include_params=false, tmp_mono::Union{Nothing,Vector{UInt8}}=nothing, unsafe_fast::Bool=false)

Extracts the second-order partial derivatives (evaluated at 0) from the TPS and fills the result matrix in-place. The partial derivatives wrt the parameters will also be extracted when the include_params flag is set to true. Note that this function is not calculating anything - just extracting the second-order monomial coefficients already in the TPS.

Input

  • tTPS/ComplexTPS64 to extract the Hessian from
  • include_params – (Optional) Extract partial derivatives wrt parameters. Default is false
  • tmp_mono – (Optional) Vector{UInt8} to store the monomial, when different orders of truncation are used
  • unsafe_fast – (Optional) Flag to specify that "fast" indexing should be used without checking. This will give incorrect results if any variable has a TO < 2. Default is false.

Output

  • result – Matrix to fill with the Hessian of the TPS, must be 1-based indexing
source