Linear Regression Model#
- class pylit.models.lrm.LinearRegressionModel(name, tau, params)#
Bases:
object
Abstract base class for parametric linear regression models of the form
\[f(\omega) = \sum_{\boldsymbol{\alpha} \in \mathcal{I}} c_\boldsymbol{\alpha} \, K(\omega; \boldsymbol{\theta}_\boldsymbol{\alpha}),\]- where
\(\omega \in \mathbb{R}\) is the input variable,
\(\mathcal{I}\) is a multi–index set determined by the parameter configurations,
\(c_\boldsymbol{\alpha} \in \mathbb{R}\) are the model coefficients,
\(K(\cdot; \boldsymbol{\theta}_\boldsymbol{\alpha})\) is a kernel function depending on a parameter tuple \(\boldsymbol{\theta}_{\boldsymbol{\alpha}} = (\theta_{\alpha_1}, \ldots, \theta_{\alpha_p})\),
\(p = \mathrm{pdim}\) is the number of parameter groups.
- Given
a finite set of nodes \(\tau = (\tau_1, \ldots, \tau_m) \in \mathbb{R}^m\),
discrete parameter sets \(\{ \theta_{j,k} \}_{k=1}^{n_j}\) for each parameter group \(j = 1,\ldots,p\),
the model constructs the Cartesian multi–index set
\[\mathcal{I} = \{ (i_1, \ldots, i_p) \mid 1 \leq i_j \leq n_j \},\]with degree \(|\mathcal{I}| = \prod_{j=1}^p n_j\).
The regression matrix \(R \in \mathbb{R}^{m \times |\mathcal{I}|}\) is defined entrywise by
\[R_{r,\boldsymbol{\alpha}} = \mathcal{L}\big[K(\cdot; \boldsymbol{\theta}_\boldsymbol{\alpha}) \big](\tau_r),\]where \(\mathcal{L}\) denotes a Laplace-type transformation specified in
ltransform()
.The forward model at the nodes is then
\[f(\tau) = R \boldsymbol{c},\]and evaluation at arbitrary inputs \(\omega\) uses the kernel representation.
Notes
This class is abstract and should not be instantiated directly.
- Concrete subclasses must override:
kernel()
— defines \(K(\omega; \boldsymbol{\theta})\),ltransform()
— defines \(\mathcal{L}[K](\tau; \boldsymbol{\theta})\).
Coefficients \(\boldsymbol{c}\) are free variables, whereas \(R\) depends only on the chosen parameters and nodes.
- __call__(omega, matrix=False)#
Evaluate the linear regression model at given inputs.
For input vector \(\omega = (\omega_1,\ldots,\omega_n) \in \mathbb{R}^n\), the method constructs the evaluation matrix
\[E_{i,\boldsymbol{\alpha}} = K(\omega_i; \boldsymbol{\theta}_{\boldsymbol{\alpha}}),\]where \(\boldsymbol{\alpha} \in \mathcal{I}\) indexes the multi–index set of parameter combinations. The model evaluation is then
\[f(\omega) = E \boldsymbol{c},\]with coefficient vector \(\boldsymbol{c} \in \mathbb{R}^d\), where \(d = |\mathcal{I}|\).
- Parameters:
omega (
ndarray
) – One-dimensional array of inputs \(\omega\) at which the model should be evaluated.matrix (
bool
) – IfTrue
, return the evaluation matrix \(E \in \mathbb{R}^{n \times d}\) instead of the model output. Defaults toFalse
.
- Returns:
If
matrix=False
: one-dimensional array of lengthn
containing \(f(\omega)\).If
matrix=True
: two-dimensional array of shape(n, d)
containing the evaluation matrix \(E\).
- Return type:
np.ndarray
- Raises:
ValueError – If
omega
is not one-dimensional.
- __init__(name, tau, params)#
Initializes the linear regression model.
- Parameters:
name (
str
) – The name of the linear regression model.tau (
ndarray
) – The discrete time axis of the linear regression model.params (
List
[ndarray
]) – The parameters of the linear regression model.
- compute_regression_matrix()#
Compute the regression matrix.
The regression matrix \(R \in \mathbb{R}^{m \times d}\) encodes the evaluation of the Laplace-transformed kernels at the discrete time axis \(\tau\) with the given parameter grid \(\{ \boldsymbol{\theta}_{\alpha} \}\).
- Returns:
Two-dimensional array of shape
(m, d)
containing the regression matrix \(R\).- Return type:
np.ndarray
Notes
The regression matrix depends only on
tau
andparams
, but not oncoeffs
.
- forward()#
Evaluation of the Laplace-transformed model at the discrete time axis.
Computes the model values at the discrete time axis \(\tau\) using the regression matrix \(R\) and the coefficient vector \(\mathbf{c}\):
\[R \mathbf{c},\]- where
\(R\) is the regression matrix of shape
(m, d)
,\(\mathbf{c}\) is the coefficient vector of length
d
,\(m\) is the number of nodes in the discrete time axis.
- Returns:
One-dimensional array of length
m
containing the model values at the discrete time axis \(\tau\).- Return type:
np.ndarray
- kernel(omega, param)#
Evaluate a single kernel function for a given set of parameters.
The kernel function \(K(\omega; \boldsymbol{\theta})\) defines the model contribution for a specific parameter tuple \(\boldsymbol{\theta} \in \Theta\). Concrete subclasses must implement this method.
- Parameters:
omega (
ndarray
) – One-dimensional array representing the discrete frequency axis at which the kernel is evaluated.param (
List
[ndarray
]) – List of parameter arrays corresponding to the parameter tuple \(\boldsymbol{\theta}\) for this kernel.
- Return type:
ndarray
[float64
]- Returns:
Values of the kernel function \(K(\omega; \boldsymbol{\theta})\) at the input frequencies.
Notes
This method must be overridden in the concrete child class to define the actual kernel function.
- ltransform(tau, param)#
Evaluate the Laplace-transformed kernel function at the discrete time axis.
For a given parameter tuple \(\boldsymbol{\theta}\), this method computes the Laplace transform of the kernel function:
\[\mathcal{L}[K(\cdot; \boldsymbol{\theta})](\tau),\]where \(\tau\) is the discrete time axis. Concrete subclasses must implement this method to define the Laplace-transformed model function.
- Parameters:
tau (
ndarray
) – One-dimensional array representing the discrete time axis at which the Laplace transform is evaluated.param (
List
[ndarray
]) – List of parameter arrays corresponding to the parameter tuple \(\boldsymbol{\theta}\).
- Return type:
ndarray
- Returns:
Values of the Laplace-transformed kernel function at the discrete time axis.
Notes
This method must be overridden in the concrete child class to define the Laplace-transformed model.
- property coeffs: ndarray#
- property degree: int64#
- property multi_index_set: ndarray[int64]#
- property params: List[ndarray[float64]]#
- property pdim: int64#
- property regression_matrix: ndarray#
- property tau: ndarray#