mutar.ReMTW

class mutar.ReMTW(alpha=0.1, beta=0.1, M=None, epsilon=None, gamma=None, fit_intercept=True, normalize=False, concomitant=False, max_iter=2000, tol=0.0001, warm_start=False, max_iter_reweighting=100, stable=False, max_iter_ot=20, max_iter_cd=1000, tol_ot=1e-05, tol_cd=1e-05, n_jobs=1, gpu=False, positive=False, ot_threshold=0.0, tol_reweighting=0.001)[source]

A class for reweighted Multitask Wasserstein regularization.

The optimization objective for Reweighted-MTW is:

(1 / (2 * n_samples)) * ||Y - X(W+ - W-)||^2_Fro +
alpha(sum_k OT(W+_k, Wb+) + sum_k OT(W-_k, Wb-)) +
beta * (||W+||_{0.5} + ||W-||_{0.5})

Where:

OT is the Unbalanced Wasserstein distance with Kullback-Leibler
marginal relaxation.

and:

||W||_{0.5} = sum_i sum_j sqrt|w_ij|

if concomitant is set to True, ReMTW also infers the standard deviation of each task. This allows to scale beta adaptively for each task according to the level of noise.

The optimization objective for Concomitant Reweighted-MTW is:

(1 / (2 * n_samples)) * sum||Y_k - X_k(W+k - W-k)||^2 / sigma_k +
alpha(sum_k OT(W+_k, Wb+) + sum_k OT(W-_k, Wb-)) +
beta * (||W+||_{0.5} + ||W-||_{0.5}) + sum sigma_k / 2
Parameters
alphafloat, optional

Constant that multiplies the OT term. Defaults to 0.1

betafloat, optional

Constant that multiplies the L0.5 term. Defaults to 0.1

Marray, shape (n_features, n_features)

Ground metric matrix defining the Wasserstein distance.

epsilonfloat > 0, optional

OT parameter. Weight of the entropy regularization.

gammafloat > 0, optional

OT parameter. Weight of the Kullback-Leibler marginal relaxation.

fit_interceptboolean

whether to calculate the intercept for this model. If set to false, no intercept will be used in calculations (e.g. data is expected to be already centered).

normalizeboolean

This parameter is ignored when fit_intercept is set to False. If True, the regressors X will be normalized before regression by subtracting the mean and dividing by the l2-norm.

concomitantboolean, optional (default False)

If True, the concomittant version of MTW is used where the l1 penalty is adaptively scaled to the noise std estimation.

stableboolean. optional (default False)

if True, use log-domain Sinhorn stabilization from the first iter. if False, the solver will automatically switch to log-domain if numerical errors are encountered.

max_iter_reweightingint, optional

Maximum number of reweighting steps i.e outer loop iterations

callbackboolean. optional.

if True, set a printing callback function to the solver.

max_iter_otint, optional (default, 20)

maximum Sinkhorn iterations

max_iter_cdint, optional (default, 10000)

maximum coordinate descent iterations

tol_otfloat, optional (default 1e-4)

relative maximum change of the Wasserstein barycenter.

tol_cdfloat, optional (default 1e-4)

relative maximum change of the coefficients in coordinate descent.

n_jobs: int > 1, default 1

number of threads used in coordinate descents

gpu: boolean, optional (default False)

if True, Sinkhorn iterations are performed on gpus using cupy.

positiveboolean.

if True, coefficients must be positive.

max_iterint, optional

The maximum number of iterations

tolfloat, optional

The tolerance for the optimization: if the updates are smaller than tol, the optimization code checks the dual gap for optimality and continues until it is smaller than tol.

ot_thresholdfloat, optional (default 0.)

OT barycenters are computed on the support of coefs > ot_threshold. 1e-7 recommended to speed up Sinkhorn with high dimensional data.

warm_startbool, optional

When set to True, reuse the solution of the previous call to fit as initialization, otherwise, just erase the previous solution.

Attributes
coef_array, shape (n_features, n_tasks)

Parameter vector (W in the cost function formula).

intercept_array, shape (n_tasks,)

independent term in decision function.

n_iter_int

number of iterations run by the coordinate descent solver to reach the specified tolerance.

__init__(self, alpha=0.1, beta=0.1, M=None, epsilon=None, gamma=None, fit_intercept=True, normalize=False, concomitant=False, max_iter=2000, tol=0.0001, warm_start=False, max_iter_reweighting=100, stable=False, max_iter_ot=20, max_iter_cd=1000, tol_ot=1e-05, tol_cd=1e-05, n_jobs=1, gpu=False, positive=False, ot_threshold=0.0, tol_reweighting=0.001)[source]

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(self[, alpha, beta, M, epsilon, …])

Initialize self.

fit(self, X, y)

get_params(self[, deep])

Get parameters for this estimator.

predict(self, X)

Predict target given unseen data samples.

reset(self)

score(self, X, y[, sample_weight])

Returns the coefficient of determination R^2 of the prediction.

set_params(self, \*\*params)

Set the parameters of this estimator.

get_params(self, deep=True)

Get parameters for this estimator.

Parameters
deepboolean, optional

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns
paramsmapping of string to any

Parameter names mapped to their values.

predict(self, X)

Predict target given unseen data samples.

Parameters
X{array-like}, shape (n_tasks, n_samples, n_features)

The training input samples.

Returns
yndarray, shape (n_tasks, n_samples)

Returns the predicted targets.

score(self, X, y, sample_weight=None)

Returns the coefficient of determination R^2 of the prediction.

Computes a score for each regression task. The coefficient R^2 is defined as (1 - u/v), where u is the residual sum of squares ((y_true - y_pred) ** 2).sum() and v is the total sum of squares ((y_true - y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a R^2 score of 0.0.

Parameters Xarray-like, shape = (n_tasks, n_samples, n_features) Test samples.

yarray-like, shape = (n_tasks, n_samples) True values for y.

sample_weightarray-like, shape = [n_tasks, n_samples], optional Sample weights.

Returns
array-like, shape = (n_tasks)
R^2 of self.predict(X) wrt. y for each task.
set_params(self, **params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Returns
self