fugw.utils#

fugw.utils.init_plan_dense(n_source, n_target, weights_source=None, weights_target=None, method='entropic')

Initialize transport plan with dense tensor.

Generate a matrix satisfying the constraints of a transport plan. In particular, marginal constraints on lines and columns are satisfied.

Parameters:
n_source: int

Number of source points

n_target: int

Number of target points

weights_source: torch.Tensor of size(n_source), optional, defaults to None

Source weights used in entropic init

weights_target: torch.Tensor of size(n_target), optional, defaults to None

Target weights used in entropic init

method: str, optional, defaults to “entropic”

Method to use for initialization. Can be “entropic”, “permutation” or “identity”. If “entropic”, weights_source and weights_target must be provided ; the initial plan is then given by the product of the two arrays. If “permutation”, the initial plan is the solution to a 1D optimal transport problem between two random arrays, which can be understood as a soft permutation between source and target points. If “identity”, the number of source and target points must be equal ; the initial plan is then the identity matrix.

Returns:
init_plan: torch.Tensor of size(n_source, n_target)
fugw.utils.load_mapping(fname, load_weights=True, device='cpu')

Load mapping from pickle file, optionally loading weights.

Parameters:
fname: str or pathlib.Path

Path to pickle file to load

load_weights: bool, optional, defaults to True

If True, load mapping weights from pickle file.

device: torch.device, default=”cpu”

Device on which to store the computed transport plan.

Returns:
mapping: fugw.mappings
fugw.utils.save_mapping(mapping, fname)

Save mapping in pickle file, separating hyperparams and weights.

Parameters:
mapping: fugw.mappings

FUGW mapping to save

fname: str or pathlib.Path

Path to pickle file to save