Shortcuts

torchtraining.metrics.distance

class torchtraining.metrics.distance.Cosine(dim: int = 1, eps: float = 1e-08, reduction=<built-in method mean of type object>)[source]

Cosine distance between outputs and targets

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and regression targets. outputs should be of shape (N,F)(N, F) , where NN is the number of samples, FF is the number of features. Should contain floating point values. targets should be in the same shape outputs and be of float data type as well.

Returns

Scalar tensor

Return type

torch.Tensor

class torchtraining.metrics.distance.Pairwise(p: float = 2.0, eps: float = 1e-06, reduction=<built-in method mean of type object>)[source]

Computes the batchwise pairwise distance between vectors v1v_1 , v2v_2 using specified norm.

Parameters
  • p (float, optional) – Degree of norm. Default: 2

  • eps (float, optional) – Epsilon to avoid division by zero. Default: 1e-06

  • reduction (Callable(torch.Tensor) -> Any, optional) – One argument callable getting torch.Tensor and returning argument after specified reduction. Default: torch.mean (mean across batch, user can use torchtraining.savers.Mean to get mean across iterations/epochs).

forward(data)[source]
Parameters

data (Tuple[torch.Tensor, torch.Tensor]) – Tuple containing outputs from neural network and regression targets. outputs should be of shape (N,F)(N, F) , where NN is the number of samples, FF is the number of features. Should contain floating point values. targets should be in the same shape outputs and be of float data type as well.

Returns

If reduction is left as default {} is taken and single value returned. Otherwise whatever reduction returns.

Return type

torch.Tensor