Smooth Lasso

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

Bases: mrinversion.linear_model._base_l1l2.GeneralL2Lasso

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

(10)\[\| {\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

(11)\[{\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,

(12)\[\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.

  • 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 contrained to only positive values, else the solution may contain positive and negative amplitudes. The default is True.


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}\).


ndarray or CSDM object.


The number of iterations required to reach the specified tolerance.



Methods Documentation

fit(K, s)

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

  • 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 the signal using the linear model.


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


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

Return type


residuals(K, s)

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

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

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

  • 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}\).


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.