eqdisco.expr.Expression#
- class eqdisco.expr.Expression(nodes, feature_names=None)[source]#
Bases:
objectA symbolic expression stored as a prefix sequence of
Node.- Parameters:
- property depth#
Length of the longest root–leaf path (a leaf has depth 0).
- evaluate(X, theta=None)[source]#
Evaluate \(f(\mathbf{x}_k;\boldsymbol\theta)\) for every row of
X.- Parameters:
- Xarray_like
ofshape(N,n) - thetaarray_like,
optional Parameter values to use instead of the stored ones.
- Xarray_like
- Returns:
ndarrayofshape(N,)
- classmethod from_string(text, pset=None, feature_names=None, params=True)[source]#
Parse an infix string such as
"2*x0 + sin(x1)".Function names of the registry (
sqrt,exp,aq, …) and^for powers are understood.
- classmethod from_sympy(expr, pset=None, feature_names=None, params=True)[source]#
Build an expression from a SymPy expression.
Symbols must be feature names (or
x0, x1, ...). Numbers become parameters whenparamsis true, except integer exponents, which are expressed withsquare,cube,sqrt,invor fixed constants.
- interval(lower, upper)[source]#
Interval evaluation: bounds of \(f\) over boxes.
- Parameters:
- lower, upperarray_like
ofshape(n,)or(B,n) Lower and upper corners of one or
Bboxes.
- lower, upperarray_like
- Returns:
- lo, hi
ndarrayofshape(B,) Guaranteed (possibly loose) bounds of the expression on each box.
- lo, hi
- jacobian(X, theta=None)[source]#
Output and Jacobian \(\partial f/\partial\boldsymbol\theta\) (forward mode).
- latex(feature_names=None, digits=4)[source]#
LaTeX string (via SymPy) with
digitssignificant digits.
- static linear_combination(terms, weights, intercept=None)[source]#
Build \(w_0 + \sum_i w_i F_i\) as one expression (weights are parameters).
- property size#
Number of nodes \(|f|\).
- property theta#
Vector of parameter values \(\boldsymbol\theta\) in prefix order.
- to_string(feature_names=None, digits=4)[source]#
Infix string with the minimum of parentheses; negative terms are printed with minus signs.
- to_sympy(feature_names=None, symbolic_params=False, digits=None)[source]#
Convert to a SymPy expression.
Protected operators become their plain mathematical counterparts. With
symbolic_params=Truethe parameters are symbolstheta_0, ....
- property variables#
Sorted indices of the variables that occur in the expression.