API Documentation¶
This is the API documentation of the public API of multilstsq. These are the most commonly used functions when using multilstsq.
Least squares¶
-
class
multilstsq.
MultiLstSq
(problem_dimensions, n_parameters, internal_dtype=<class 'float'>)¶ Multiple least squares problems.
y = Xβ + ε
This is a class which can exist in three modes:
MODE_REGRESSION
: add data to the least square matrices to obtain the meanMODE_VARIANCE
: compute the varianceMODE_READONLY
: the object is frozen.
The mode can only be switched “forward” (it is not possible to move from
MODE_VARIANCE
toMODE_REGRESSION
for example.)-
__init__
(problem_dimensions, n_parameters, internal_dtype=<class 'float'>)¶ Create a MultiLstSq object, which is originally in
MODE_REGRESSION
.Parameters: - problem_dimensions – Tuple, size of the problem array, it can be
()
(0-dimensional), for a single least square problem, or for example(800, 600)
for 800x600 times the regression problem - n_parameters – Number of parameters of the least squares problem.
- internal_dtype –
numpy.dtype
data type of the matrices
- problem_dimensions – Tuple, size of the problem array, it can be
-
__weakref__
¶ list of weak references to the object (if defined)
-
add_data
(X, y, w=None)¶ Add data to the object (depending on the mode, for either mean or variance computation)
-
beta
¶ The linear coefficients that minimize the least squares criterion.
-
evaluate_at
(X)¶ Evaluate Xβ
-
n_observations
¶ Number of observations n.
-
n_parameters
¶ Number of parameters
-
rss
¶ Residual sum of squares
-
sigma_2
¶ Scaling parameter for the covariance matrix.
-
switch_to_read_only
()¶ Switch to read-only mode.
-
switch_to_variance
()¶ Switch to variance computation mode.
-
variance
¶ Returns the variance/covariance matrix.
Regression¶
-
class
multilstsq.
MultiRegression
(problem_dimensions, model_str, internal_dtype=<class 'float'>)¶ -
__init__
(problem_dimensions, model_str, internal_dtype=<class 'float'>)¶ Create a MultiLstSq object, which is originally in
MODE_REGRESSION
.Parameters: - problem_dimensions – Tuple, size of the problem array, it can be
()
(0-dimensional), for a single least square problem, or for example(800, 600)
for 800x600 times the regression problem - n_parameters – Number of parameters of the least squares problem.
- internal_dtype –
numpy.dtype
data type of the matrices
- problem_dimensions – Tuple, size of the problem array, it can be
-
add_data
(X, y, w=None)¶ Add data to the object (depending on the mode, for either mean or variance computation)
-
Expression evaluator¶
-
class
multilstsq.
ExprEvaluator
(expr, constants=None, enable_caller_modules=True)¶ -
__call__
(*args, **kwargs)¶ Substitute the arguments in the expression, and then evaluate it and return the resulting Python object.
The positional arguments are
zip()
’ed with thevariable_list
ofmultilstsq.ExprEvaluator.enable_call()
, which the named arguments are directly substituted.Returns: The Python object of the evaluated expression.
Raises: - RuntimeError – if positional arguments are used, but
multilstsq.ExprEvaluator.enable_call()
was not called. - ValueError – if there are undefined variables.
- RuntimeError – if positional arguments are used, but
-
__init__
(expr, constants=None, enable_caller_modules=True)¶ Initialize an ExprEvaluator object
Parameters: - expr – Expression string, should be a valid Python 3 expression
- constant – Dictionary of constants
{'constantname': value}
. - enable_caller_modules – Boolean, if
True
modules of the first frame in the stack outside of multilstsq will be included in the context of the expression
-
__repr__
()¶ Return repr(self).
-
__str__
()¶ Returns: a string corresponding to the expression
-
__weakref__
¶ list of weak references to the object (if defined)
-
constants
¶ Returns: Set of constants names (values which have a defined substitution) in the current expression
-
enable_call
(variable_list)¶ Enables calling the expression, as a simplification for calling
multilstsq.ExprEvaluator.substitute()
followed bymultilstsq.ExprEvaluator.eval()
.Parameters: variable_list – List of variables names which correspond to the arguments which will be used in multilstsq.ExprEvaluator.__call__()
-
eval
()¶ Returns: The python object which results of the expression Raises: ValueError – if at least one variable is not defined
-
reduce
()¶ Returns: A copy of the current expression, where all known part of the syntax tree are simplified. For example, reducing
a*(b+c)
with knownb
andc
, will result ina*__ExprEvaluator_0
, where__ExprEvaluator_0
is defined as a constant.
-
substitute
(expressions=None, constants=None)¶ Substitute expressions or constants in the current expression.
Parameters: - expressions – dictionary of expression to substitute. The keys can be of
str
,ast.AST
ormultilstsq.ExprEvaluator
. - constants – dictionary of constants to substitute
{'constantname': value}
Returns: New
multilstsq.ExprEvaluator
object with the substitution done.- expressions – dictionary of expression to substitute. The keys can be of
-
variables
¶ Returns: Set of variables names (values which don’t have a defined substitution) in the current expression
-