Smooth Lasso

class mrinversion.linear_model.SmoothLasso(alpha, lambda1, inverse_dimension, max_iterations=10000, tolerance=1e-05, positive=True, method='gradient_decent')[source]

Bases: GeneralL2Lasso

The linear model trained with the combined l1 and l2 priors as the regularizer. The method minimizes the objective function,

(14)\[\| {\bf Kf - s} \|^2_2 + \alpha \sum_{i=1}^{d} \| {\bf J}_i {\bf f} \|_2^2 + \lambda \| {\bf f} \|_1 ,\]

where \({\bf K} \in \mathbb{R}^{m \times n}\) is the kernel, \({\bf s} \in \mathbb{R}^{m \times m_\text{count}}\) is the known (measured) signal, and \({\bf f} \in \mathbb{R}^{n \times m_\text{count}}\) is the desired solution. The parameters, \(\alpha\) and \(\lambda\), are the hyperparameters controlling the smoothness and sparsity of the solution \({\bf f}\). The matrix \({\bf J}_i\) is given as

(15)\[{\bf J}_i = {\bf I}_{n_1} \otimes \cdots \otimes {\bf A}_{n_i} \otimes \cdots \otimes {\bf I}_{n_{d}},\]

where \({\bf I}_{n_i} \in \mathbb{R}^{n_i \times n_i}\) is the identity matrix,

(16)\[\begin{split}{\bf A}_{n_i} = \left(\begin{array}{ccccc} 1 & -1 & 0 & \cdots & \vdots \\ 0 & 1 & -1 & \cdots & \vdots \\ \vdots & \vdots & \vdots & \vdots & 0 \\ 0 & \cdots & 0 & 1 & -1 \end{array}\right) \in \mathbb{R}^{(n_i-1)\times n_i},\end{split}\]

and the symbol \(\otimes\) is the Kronecker product. The terms, \(\left(n_1, n_2, \cdots, n_d\right)\), are the number of points along the respective dimensions, with the constraint that \(\prod_{i=1}^{d}n_i = n\), where \(d\) is the total number of dimensions.

Parameters:
  • alpha (float) – The hyperparameter, \(\alpha\).

  • lambda1 (float) – The hyperparameter, \(\lambda\).

  • inverse_dimension (list) – A list of csdmpy Dimension objects representing the inverse space.

  • max_iterations (int) – The maximum number of iterations allowed when solving the problem. The default value is 10000.

  • tolerance (float) – The tolerance at which the solution is considered converged. The default value is 1e-5.

  • positive (bool) – If True, the amplitudes in the solution, \({\bf f}\), is constrained to only positive values, else the solution may contain positive and negative amplitudes. The default is True.

f

A ndarray of shape (m_count, nd, …, n1, n0) representing the solution, \({\bf f} \in \mathbb{R}^{m_\text{count} \times n_d \times \cdots n_1 \times n_0}\).

Type:

ndarray or CSDM object.

n_iter

The number of iterations required to reach the specified tolerance.

Type:

int

Methods Documentation

fit(K, s)

Fit the model using the coordinate descent method from scikit-learn.

Parameters:
  • K (ndarray) – The \(m \times n\) kernel matrix, \({\bf K}\). A numpy array of shape (m, n).

  • s (ndarray or CSDM object.) – A csdm object or an equivalent numpy array holding the signal, \({\bf s}\), as a \(m \times m_\text{count}\) matrix.

predict(K)

Predict the signal using the linear model.

Parameters:

K (ndarray) – A \(m \times n\) kernel matrix, \({\bf K}\). A numpy array of shape (m, n).

Returns:

A numpy array of shape (m, m_count) with the predicted values

Return type:

ndarray

residuals(K, s)

Return the residual as the difference the data and the predicted data(fit), following

(17)\[\text{residuals} = {\bf s - Kf^*}\]

where \({\bf f^*}\) is the optimum solution.

Parameters:
  • K (ndarray.) – A \(m \times n\) kernel matrix, \({\bf K}\). A numpy array of shape (m, n).

  • s (ndarray ot CSDM object.) – A csdm object or a \(m \times m_\text{count}\) signal matrix, \({\bf s}\).

Returns:

If s is a csdm object, returns a csdm object with the residuals. If s is a numpy array, return a \(m \times m_\text{count}\) residue matrix. csdm object

Return type:

ndarray or CSDM object.

score(K, s, sample_weights=None)

The coefficient of determination, \(R^2\), of the prediction. For more information, read scikit-learn documentation.