Common MRI Losses#

class atommic.collections.common.losses.AggregatorLoss(*args: Any, **kwargs: Any)[source]#

Bases: Loss

Aggregates multiple losses into a single loss.

Examples

>>> from atommic.collections.common.losses.aggregator import AggregatorLoss
>>> loss = AggregatorLoss(num_inputs=2)
>>> loss(loss_1=torch.tensor(1.0), loss_2=torch.tensor(2.0))
tensor(3.)
__init__(num_inputs: int = 2, weights: Optional[List[float]] = None)[source]#

Inits AggregatorLoss.

Parameters
  • num_inputs (int) – Number of losses to be summed.

  • weights (List[float]) – Weights to be applied to each loss. If None, all losses are weighted equally.

forward(**kwargs)[source]#

Computes the sum of the losses.

property input_types#

Returns definitions of module input ports.

property output_types#

Returns definitions of module output ports.

class atommic.collections.common.losses.SinkhornDistance(*args: Any, **kwargs: Any)[source]#

Bases: Loss

Given two empirical measures each with \(P_1\) locations \(x\in\mathbb{R}^{D_1}\) and \(P_2\) locations \(y\in\mathbb{R}^{D_2}\), outputs an approximation of the regularized OT cost for point clouds.

M(C, u, v)[source]#

Modified cost for logarithmic updates $M_{ij} = (-c_{ij} + u_i + v_j) / epsilon$

__init__(eps=0.1, max_iter=100, reduction='mean')[source]#

Inits SinkhornDistance.

Parameters
  • eps (float) – Regularization coefficient. Default is 0.1.

  • max_iter (int) – Maximum number of Sinkhorn iterations. Default is 100.

  • reduction (string, optional) – Specifies the reduction to apply to the output: ‘none’ | ‘mean’ | ‘sum’. ‘none’: no reduction will be applied. Default is mean.

static ave(u, u1, tau)[source]#

Barycenter subroutine, used by kinetic acceleration through extrapolation.

forward(x, y)[source]#

Forward pass of the Sinkhorn algorithm.

Parameters
Returns

The Sinkhorn distance between the two point clouds. Output shape \((N)\) or \(()\), depending on reduction

Return type

torch.Tensor