Basis
DataDrivenDiffEq.Basis — Type
struct Basis{IMPL, CTRLS} <: DataDrivenDiffEq.AbstractBasisA basis over the states with parameters, independent variable, and possible exogenous controls. It extends an AbstractSystem as defined in ModelingToolkit.jl. f can either be a Julia function which is able to use ModelingToolkit variables or a vector of eqs. It can be called with the typical SciML signature, meaning out of place with f(u,p,t) or in place with f(du, u, p, t). If control inputs are present, it is assumed that no control corresponds to zero for all inputs. The corresponding function calls are f(u,p,t,inputs) and f(du,u,p,t,inputs) and need to be specified fully.
The optional implicits declare implicit variables in the Basis, meaning variables representing the (measured) target of the system. Right now, only supported with the use of ImplicitOptimizers.
If linear_independent is set to true, a linear independent basis is created from all atom functions in f.
If simplify_eqs is set to true, simplify is called on f.
Additional keyword arguments include name, which can be used to name the basis, and observed for defining observables.
Fields
eqs: The equations of the basisunknowns: Dependent (state) variablesctrls: Control variablesps: Parametersobserved: Observediv: Independent variableimplicit: Implicit variables of the basisf: Internal function representation of the basisname: Name of the basissystems: Internal systems
Example
using ModelingToolkit
using DataDrivenDiffEq
@parameters w[1:2] t
@variables u[1:2](t)
Ψ = Basis([u; sin.(w .* u)], u, parameters = p, iv = t)Note
The keyword argument eval_expression controls the function creation behavior. eval_expression=true means that eval is used, so normal world-age behavior applies (i.e. the functions cannot be called from the function that generates them). If eval_expression=false, then construction via GeneralizedGenerated.jl is utilized to allow for same world-age evaluation. However, this can cause Julia to segfault on sufficiently large basis functions. By default eval_expression=false.
DataDrivenDiffEq.Difference — Type
Difference(t; dt, update=false)Represents a difference operator for discrete-time systems.
Fields
t: The independent variabledt: The time stepupdate: If true, represents a shift/update operator
Examples
@variables t
d = Difference(t; dt = 0.01)API
Next to ModelingToolkit's API for AbstractSystems, a Basis can be called with the following methods:
DataDrivenDiffEq.dynamics — Function
dynamics(b)
Returns the internal function representing the dynamics of the `Basis`. This can be called either inplace or out-of-place
with the typical SciML signature `f(u,p,t)` or `f(du,u,p,t)`. If control variables are defined, the function can also be called
by `f(u,p,t,control)` or `f(du,u,p,t,control)` and assumes `control .= 0` if no control is given.DataDrivenDiffEq.jacobian — Function
jacobian(x)
jacobian(x, eval_expression)
Returns a function representing the Jacobian matrix / gradient of the Basis with respect to the states as a function with the common signature f(u,p,t) for out of place and f(du, u, p, t) for in place computation. If control variables are defined, the function can also be called by f(u,p,t,control) or f(du,u,p,t,control) and assumes control .= 0 if no control is given.
If the Jacobian with respect to other variables is needed, it can be passed via a second argument.
DataDrivenDiffEq.implicit_variables — Function
implicit_variables(b)
Return the implicit variables of the basis.
DataDrivenDiffEq.states — Function
states(b)
Return the state variables represented by the basis.
states(p)
states(p, i)
states(p, i, j)
Return state measurements from the data-driven problem.
DataDrivenDiffEq.controls — Function
controls(b)
Return the control variables represented by the basis.
controls(p)
controls(p, i)
controls(p, i, j)
Return control measurements from the data-driven problem.
DataDrivenDiffEq.get_parameter_values — Function
get_parameter_values(basis::Basis) -> valuesReturn the numeric default value of each parameter in basis. Parameters without a stored default contribute zero(T), where T is the parameter's symbolic type. Symbolic wrappers are removed so the returned values can be passed to SciML problems.
Arguments
basis::Basis: symbolic basis whose parameter defaults are queried.
Returns
values::AbstractVector: parameter defaults in the order returned byModelingToolkitBase.parameters(basis).
Examples
using DataDrivenDiffEq, Symbolics
@variables x p = 2.0
basis = Basis([p * x], [x], parameters = [p])
get_parameter_values(basis) # returns [2.0]DataDrivenDiffEq.get_parameter_map — Function
get_parameter_map(basis::Basis) -> parameter_mapReturn each symbolic parameter in basis paired with its numeric default. Parameters without a stored default are paired with zero(T), where T is the parameter's symbolic type.
Arguments
basis::Basis: symbolic basis whose parameter defaults are queried.
Returns
parameter_map::AbstractVector{<:Pair}: symbolic parameters paired with unwrapped numeric values, in basis parameter order.
Examples
using DataDrivenDiffEq, Symbolics
@variables x p = 2.0
basis = Basis([p * x], [x], parameters = [p])
get_parameter_map(basis) # returns [p => 2.0]Generators
DataDrivenDiffEq.monomial_basis — Function
monomial_basis(x)
monomial_basis(x, degree)
Constructs an array containing monomial basis in the variables x up to degree c of the form [x₁, x₁^2, ... , x₁^c, x₂, x₂^2, ...].
DataDrivenDiffEq.polynomial_basis — Function
polynomial_basis(x)
polynomial_basis(x, degree)
Constructs an array containing a polynomial basis in the variables x up to degree c of the form [x₁, x₂, x₃, ..., x₁^1 * x₂^(c-1)]. Mixed terms are included.
DataDrivenDiffEq.sin_basis — Function
sin_basis(x, coefficients)
Constructs an array containing a Sine basis in the variables x with coefficients c. If c is an Int returns all coefficients from 1 to c.
DataDrivenDiffEq.cos_basis — Function
cos_basis(x, coefficients)
Constructs an array containing a Cosine basis in the variables x with coefficients c. If c is an Int returns all coefficients from 1 to c.
DataDrivenDiffEq.fourier_basis — Function
fourier_basis(x, coefficients)
Constructs an array containing a Fourier basis in the variables x with (integer) coefficients c. If c is an Int returns all coefficients from 1 to c.
DataDrivenDiffEq.chebyshev_basis — Function
chebyshev_basis(x, coefficients)
Constructs an array containing a Chebyshev basis in the variables x with coefficients c. If c is an Int returns all coefficients from 1 to c.