Expressions#
Symbolic expressions: primitives, prefix trees, evaluation and conversion.
An expression is stored as a prefix (Polish) sequence of Node objects.
A node is a function (a Primitive with arity \(\ge 1\)), a variable
(column index of \(\mathbf{X}\)) or a constant. Constants are numeric
parameters \(\boldsymbol\theta\) unless they are marked fixed.
The module provides vectorized evaluation, forward-mode differentiation with respect to the parameters (the Jacobian used by Levenberg–Marquardt fitting), interval evaluation (used by shape constraints and safety checks), conversion to SymPy, strings and LaTeX, and parsing from strings or SymPy expressions.
Examples#
>>> import numpy as np
>>> from eqdisco.expr import Expression, PrimitiveSet
>>> pset = PrimitiveSet(n_features=2)
>>> e = Expression.from_string("2.5*x0 + sin(x1)", pset)
>>> e.size, e.depth, e.n_params
(6, 2, 1)
>>> X = np.array([[1.0, 0.0], [2.0, np.pi / 2]])
>>> np.round(e.evaluate(X), 6)
array([2.5, 6. ])
Prefix-tree expressions, primitives and primitive sets, evaluation, Jacobians, intervals, SymPy.
Classes#
|
A function node of an expression. |
|
One node of a prefix expression. |
|
Function and terminal sets of a search. |
|
A symbolic expression stored as a prefix sequence of |
Functions#
|
Add a user-defined primitive to the registry (used by parsing and JSON loading). |
|
Index one past the last node of the subtree rooted at |
|
Reject text that is not a plain arithmetic expression over known names. |
Constants#
int([x]) -> integer int(x, base=10) -> integer |
|
int([x]) -> integer int(x, base=10) -> integer |
|
int([x]) -> integer int(x, base=10) -> integer |
|
Registry of the built-in primitives, by name. |
|
Function set used when none is given. |