Export#

Export of equations to code, documents and model-exchange formats.

A discovered equation is most useful where it runs: in a control system, a spreadsheet, a simulator or a database. This module writes it as

  • source code – Python (math or NumPy), C, MATLAB/Octave, Julia;

  • an Excel formula over cell references;

  • LaTeX and SymPy;

  • PMML 4.4 (a DerivedField built from Apply elements and a regression model), readable by PMML scoring engines;

  • JSON (lossless, eqdisco.Equation.to_json()).

With protected=True (default) the code reproduces eqdisco’s protected operators exactly (division by a near-zero value gives 1, logarithm and square root of the absolute value, exponential clipped at \(e^{100}\)); with protected=False the plain mathematical functions are written.

Examples#

>>> from eqdisco import Equation
>>> from eqdisco.export import to_python, to_excel
>>> eq = Equation.from_string("2.5*T*exp(-0.1*t)", feature_names=["T", "t"])
>>> print(to_python(eq, protected=False))
import math

def f(T, t):
    return 2.5 * T * math.exp(-0.1 * t)
>>> to_excel(eq, {"T": "A2", "t": "B2"}, protected=False)
'=2.5*A2*EXP(-0.1*B2)'

Code generation (Python, NumPy, C, MATLAB, Julia, Excel, LaTeX) and PMML.

Functions#

sanitize_names(names)

Valid, unique identifiers for the variable names (y(k-1) becomes y_k_1).

to_python(model[, name, protected, numpy])

Python source (math for scalars, NumPy for arrays with numpy=True).

to_numpy_function(model)

A NumPy-vectorized callable f(X) built with sympy.lambdify() (no code is executed from text).

to_c(model[, name, protected])

C source of a function double f(double x0, ...).

to_matlab(model[, name, protected])

MATLAB/Octave function file (element-wise operators).

to_julia(model[, name, protected])

Julia one-line function.

to_excel(model, cells[, protected])

Excel formula with the variables replaced by cell references ({"T": "A2"} or a list).

to_latex(model[, lhs, digits])

LaTeX equation lhs = ....

to_pmml(model[, path, target, description])

PMML 4.4 document of the equation.

to_code(model[, lang, name, protected, ...])

Source code of a function name that evaluates the equation in language lang.