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.0julia> J = GTPSA.jacobian([f, g])2×2 Matrix{Float64}: 1.0 2.0 5.0 4.0julia> H = GTPSA.hessian(f)2×2 Matrix{Float64}: 6.0 4.0 4.0 10.0
Documentation
GTPSA.gradient — FunctionGTPSA.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
t–TPS/ComplexTPS64to extract the gradient frominclude_params– (Optional) Extract partial derivatives wrt parameters. Default is false
Output
grad– Gradient of the TPS
GTPSA.gradient! — FunctionGTPSA.gradient!(result, t::TPS; include_params=false, unsafe_inbounds=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
t–TPS/ComplexTPS64to extract the gradient frominclude_params– (Optional) Extract partial derivatives wrt parameters. Default is falseunsafe_inbounds– (Optional) Flag which, if false, ignores checking the size ofresult. The size ofresultis used to index theTPS. Default isfalse
Output
result– Vector to fill with the gradient of the TPS, must be 1-based indexing
GTPSA.jacobian — FunctionGTPSA.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 indexinginclude_params– (Optional) Extract partial derivatives wrt parameters. Default is false
Output
J– Jacobian ofm
GTPSA.jacobian! — FunctionGTPSA.jacobian!(result, m::AbstractArray{<:TPS}; include_params=false, unsafe_inbounds=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 indexinginclude_params– (Optional) Extract partial derivatives wrt parameters. Default is falseunsafe_inbounds– (Optional) Flag which, if false, ignores checking the size ofresult. The size ofresultis used to index theTPS. Default isfalse
Output
result– Matrix to fill with the Jacobian ofm, must be 1-based indexing
GTPSA.jacobiant — FunctionGTPSA.jacobiant(m::AbstractArray{<:TPS}; include_params=false) where {N,P,I}Extracts the first-order partial derivatives (evaluated at 0) from the array 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– Array of TPSs to extract the Jacobian from, must be 1-based indexinginclude_params– (Optional) Extract partial derivatives wrt parameters. Default is false
Output
Jt– Transpose of the Jacobian ofm
GTPSA.jacobiant! — FunctionGTPSA.jacobiant!(result, m::AbstractArray{<:TPS}; include_params=false, unsafe_inbounds=false)Extracts the first-order partial derivatives (evaluated at 0) from the array 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 indexinginclude_params– (Optional) Extract partial derivatives wrt parameters. Default is falseunsafe_inbounds– (Optional) Flag which, if false, ignores checking the size ofresult. The size ofresultis used to index theTPS. Default isfalse
Output
result– Matrix to fill with the transpose of the Jacobian ofm, must be 1-based indexing
GTPSA.hessian — FunctionGTPSA.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
t–TPS/ComplexTPS64to extract the Hessian frominclude_params– (Optional) Extract partial derivatives wrt parameters. Default is false
Output
H– Hessian of the TPS
GTPSA.hessian! — FunctionGTPSA.hessian!(result, t::TPS; include_params=false, tmp_mono::Union{Nothing,Vector{UInt8}}=nothing, unsafe_fast=false, unsafe_inbounds=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
t–TPS/ComplexTPS64to extract the Hessian frominclude_params– (Optional) Extract partial derivatives wrt parameters. Default is falsetmp_mono– (Optional)Vector{UInt8}to store the monomial, when different orders of truncation are usedunsafe_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 isfalse.unsafe_inbounds– (Optional) Flag which, if false, ignores checking the size ofresult. The size ofresultis used to index theTPS. Default isfalse
Output
result– Matrix to fill with the Hessian of the TPS, must be 1-based indexing