FixedPolynomials.GradientConfig
— TypeGradientConfig(f::Polynomial{T}, [x::AbstractVector{S}])
A data structure with which the gradient of a Polynomial
f
can be evaluated efficiently. Note that x
is only used to determine the output type of f(x)
.
GradientConfig(f::Polynomial{T}, [S])
Instead of a vector x
a type can also be given directly.
FixedPolynomials.GradientDiffResult
— TypeGradientDiffResult(cfg::GradientConfig)
During the computation of $∇g(x)$ we compute nearly everything we need for the evaluation of $g(x)$. GradientDiffResult allocates memory to hold both values. This structure also signals gradient!
to store $g(x)$ and $∇g(x)$.
Example
cfg = GradientConfig(g, x)
r = GradientDiffResult(cfg)
gradient!(r, g, x, cfg)
value(r) == g(x)
gradient(r) == gradient(g, x, cfg)
GradientDiffResult(grad::AbstractVector)
Allocate the memory to hold the gradient by yourself.
FixedPolynomials.JacobianConfig
— TypeJacobianConfig(F::Vector{Polynomial{T}}, [x::AbstractVector{S}])
A data structure with which the jacobian of a Vector
F
of Polynomial
s can be evaluated efficiently. Note that x
is only used to determine the output type of F(x)
.
JacobianConfig(F::Vector{Polynomial{T}}, [S])
Instead of a vector x
a type can also be given directly.
FixedPolynomials.JacobianDiffResult
— TypeJacobianDiffResult(cfg::GradientConfig)
During the computation of the jacobian $J_F(x)$ we compute nearly everything we need for the evaluation of $F(x)$. JacobianDiffResult
allocates memory to hold both values. This structure also signals jacobian!
to store $F(x)$ and $J_F(x)$.
Example
cfg = JacobianConfig(F, x)
r = JacobianDiffResult(cfg)
jacobian!(r, F, x, cfg)
value(r) == map(f -> f(x), F)
jacobian(r) == jacobian(F, x, cfg)
JacobianDiffResult(value::AbstractVector, jacobian::AbstractMatrix)
Allocate the memory to hold the value and the jacobian by yourself.
FixedPolynomials.Polynomial
— TypePolynomial(p::MultivariatePolynomials.AbstractPolynomial [, variables [, homogenized=false]])
A structure for fast evaluation of multivariate polynomials. The terms are sorted first by total degree, then lexicographically. Polynomial
has first class support for homogenous polynomials. This field indicates whether the first variable should be considered as the homogenization variable.
Polynomial{T}(p::MultivariatePolynomials.AbstractPolynomial [, variables [, homogenized=false]])
You can force a coefficient type T
. For optimal performance T
should be same type as the input to with which it will be evaluated.
Polynomial(exponents::Matrix{Int}, coefficients::Vector{T}, variables, [, homogenized=false])
You can also create a polynomial directly. Note that in exponents each column represents the exponent of a term.
Example
Poly([3 1; 1 1; 0 2 ], [-2.0, 3.0], [:x, :y, :z]) == 3.0x^2yz^2 - 2x^3y
FixedPolynomials.System
— TypeSystem(polys [, variables])
Construct a system of polynomials from the given polynomials polys
.
FixedPolynomials.coefficients
— Methodcoefficients(p::Polynomial)
Returns the coefficient vector of p
.
FixedPolynomials.config
— Methodconfig(F::Polynomial, x)
Construct a GradientConfig
for the evaluation of f
with values like x
.
FixedPolynomials.config
— Methodconfig(F::System, x)
Construct a JacobianConfig
for the evaluation of F
with values like x
.
FixedPolynomials.degree
— Methoddegree(p::Polynomial)
Returns the (total) degree of p.
FixedPolynomials.dehomogenize
— Methoddehomogenize(p::Polynomial)
Substitute 1
as for the first variable p
, if ishomogenized(p)
is false
this is just the identity.
FixedPolynomials.differentiate
— Methoddifferentiate(p::Polynomial, varindex::Int)
Differentiate p
w.r.t the varindex
th variable.
differentiate(p::Polynomial)
Differentiate p
w.r.t. all variables.
FixedPolynomials.evaluate!
— Functionevaluate!(u, F, x, cfg::JacobianConfig [, precomputed=false])
Evaluate the system F
at x
using the precomputated values in cfg
and store the result in u
. Note that this is usually signifcant faster than map!(u, f -> evaluate(f, x), F)
.
Example
cfg = JacobianConfig(F)
evaluate!(u, F, x, cfg)
With precomputed=true
we rely on the previous intermediate results in cfg
. Therefore the result is only correct if you previouls called evaluate
, or jacobian
with the same x
.
FixedPolynomials.evaluate
— Methodevaluate(g, x, cfg::GradientConfig [, precomputed=false])
Evaluate g
at x
using the precomputated values in cfg
. Note that this is usually signifcant faster than evaluate(g, x)
.
Example
cfg = GradientConfig(g)
evaluate(g, x, cfg)
With precomputed=true
we rely on the previous intermediate results in cfg
. Therefore the result is only correct if you previouls called evaluate
, or gradient
with the same x
.
FixedPolynomials.evaluate
— Methodevaluate(F, x, cfg::JacobianConfig [, precomputed=false])
Evaluate the system F
at x
using the precomputated values in cfg
. Note that this is usually signifcant faster than map(f -> evaluate(f, x), F)
. The return vector is constructed using similar(x, T)
.
Example
cfg = JacobianConfig(F)
evaluate(F, x, cfg)
With precomputed=true
we rely on the previous intermediate results in cfg
. Therefore the result is only correct if you previouls called evaluate
, or jacobian
with the same x
.
FixedPolynomials.evaluate
— Methodevaluate(p::Polynomial{T}, x::AbstractVector{T})
Evaluates p
at x
, i.e. $p(x)$. Polynomial
is also callable, i.e. you can also evaluate it via p(x)
.
FixedPolynomials.evaluate_and_jacobian!
— Methodevaluate_and_jacobian!(u, U, F, x, cfg::JacobianConfig)
Evaluate F
and its Jacobian at x
using the precomputated values in cfg
and store the result in u
and U
(Jacobian).
Example
evaluate_and_jacobian!(u, U, F, x, config(F, x))
FixedPolynomials.exponents
— Methodexponents(p::Polynomial)
Returns the exponents matrix of p
. Each column represents the exponents of a term of p
.
FixedPolynomials.gradient!
— Methodgradient!(u, g, x, cfg::GradientConfig [, precomputed=false])
Compute the gradient of g
at x
using the precomputated values in cfg
and store thre result in u.
Example
cfg = GradientConfig(g)
gradient(u, g, x, cfg)
With precomputed=true
we rely on the previous intermediate results in cfg
. Therefore the result is only correct if you previouls called evaluate
, or gradient
with the same x
.
FixedPolynomials.gradient!
— Methodgradient!(r::GradientDiffResult, g, x, cfg::GradientConfig)
Compute $g(x)$ and the gradient of g
at x
at once using the precomputated values in cfg
and store thre result in r
. This is faster than calling both values separetely.
Example
cfg = GradientConfig(g)
r = GradientDiffResult(r)
gradient!(r, g, x, cfg)
value(r) == g(x)
gradient(r) == gradient(g, x, cfg)
FixedPolynomials.homogenize
— Functionhomogenize(p::Polynomial [, variable = :x0])
Makes p
homogenous, if ishomogenized(p)
is true
this is just the identity. The homogenization variable will always be considered as the first variable of the polynomial.
FixedPolynomials.ishomogenized
— Methodishomogenized(p::Polynomial)
Checks whether p
was homogenized.
FixedPolynomials.ishomogenous
— Methodishomogenous(p::Polynomial)
Checks whether p
is a homogenous polynomial. Note that this is unaffected from the value of homogenized(p)
.
FixedPolynomials.jacobian!
— Functionjacobian!(u, F, x, cfg::JacobianConfig [, precomputed=false])
Evaluate the jacobian of F
at x
using the precomputated values in cfg
and store the result in u
.
Example
cfg = JacobianConfig(F)
jacobian!(u, F, x, cfg)
With precomputed=true
we rely on the previous intermediate results in cfg
. Therefore the result is only correct if you previouls called evaluate
, or jacobian
with the same x
.
FixedPolynomials.jacobian!
— Methodjacobian!(r::JacobianDiffResult, F, x, cfg::JacobianConfig)
Compute $F(x)$ and the jacobian of F
at x
at once using the precomputated values in cfg
and store thre result in r
. This is faster than computing both values separetely.
Example
cfg = GradientConfig(g)
r = GradientDiffResult(cfg)
gradient!(r, g, x, cfg)
value(r) == g(x)
gradient(r) == gradient(g, x, cfg)
FixedPolynomials.jacobian
— Methodjacobian(u, F, x, cfg::JacobianConfig [, precomputed=false])
Evaluate the jacobian of F
at x
using the precomputated values in cfg
. The return matrix is constructed using similar(x, T, m, n)
.
Example
cfg = JacobianConfig(F)
jacobian(F, x, cfg)
With precomputed=true
we rely on the previous intermediate results in cfg
. Therefore the result is only correct if you previouls called evaluate
, or jacobian
with the same x
.
FixedPolynomials.nterms
— Methodnterms(p::Polynomial)
Returns the number of terms of p
FixedPolynomials.nvariables
— Methodnvariables(p::Polynomial)
Returns the number of variables of p
FixedPolynomials.nvariables
— Methodnvariables(F::System)
Returns the number of variables of F
.
FixedPolynomials.scale_coefficients!
— Methodscale_coefficients!(f::Polynomial, λ)
Scale the coefficients of f
with the factor λ
.
FixedPolynomials.substitute
— Methodsubstitute(p::Polynomial, i, x)
In p
substitute for the variable with index i
the value x
. You can use this for partial evaluation of polynomial.
Example
julia> substitute(x^2+3y, 2, 5)
x^2+15
FixedPolynomials.value
— Methodvalue(r::GradientDiffResult)
Get the currently stored value in r
.
FixedPolynomials.variables
— Methodvariables(p::Polynomial)
Returns the variables of p
.
FixedPolynomials.weyldot
— Methodweyldot(f::Polynomial, g::Polynomial)
Compute the Bombieri-Weyl dot product. Note that this is only properly defined if f
and g
are homogenous.
weyldot(f::Vector{Polynomial}, g::Vector{Polynomial})
Compute the dot product for vectors of polynomials.
FixedPolynomials.weylnorm
— Methodweylnorm(f::Polynomial)
Compute the Bombieri-Weyl norm. Note that this is only properly defined if f
is homogenous.
FixedPolynomials.∇
— Method∇(p::Polynomial)
Returns the gradient vector of p
. This is the same as differentiate
.
FixedPolynomials.gradient
— Methodgradient(r::GradientDiffResult)
Get the currently stored gradient in r
.
FixedPolynomials.gradient
— Methodgradient(g, x, cfg::GradientConfig[, precomputed=false])
Compute the gradient of g
at x
using the precomputated values in cfg
. The return vector is constructed using similar(x, T)
.
Example
cfg = GradientConfig(g)
gradient(g, x, cfg)
With precomputed=true
we rely on the previous intermediate results in cfg
. Therefore the result is only correct if you previouls called evaluate
, or gradient
with the same x
.
FixedPolynomials.gradient_row!
— Methodgradient_row!(u::AbstractMatrix, x::AbstractVector, cfg::PolyConfig{T}, i)
Store the gradient in the i-th row of 'u'.
FixedPolynomials.lt_total_degree
— MethodSorts two vectory by total degree
FixedPolynomials.multinomial
— MethodComputes the multinomial coefficient (|k| \over k)