Functional¶
import pyblaze.nn.functional as X
The functional module provides free functions that are missing from PyTorch.
General Functions¶
Gumbel¶

pyblaze.nn.functional.
gumbel_softmax
(logits: torch.Tensor, tau=1, hard=False, eps=1e10, dim= 1)[source]¶ Numerically stable version of PyTorch’s builtin Gumbel softmax.
 Parameters
logits (torch.Tensor) – The values fed into the Gumbel softmax.
tau (float, default: 1) – Temperature parameter for the Gumbel distribution.
hard (bool, default: False) – Whether to obtain a onehot output.
eps (float, default: 1e10) – Constant for numerical stability.
dim (int, default: 1) – The dimension over which to apply the softmax.
Probability Distributions¶
Normal Distribution¶

pyblaze.nn.functional.
log_prob_standard_normal
(x)[source]¶ Computes the logprobability of observing the given data under a (multivariate) standard Normal distribution. Although this function is equivalent to the
log_prob
method of thetorch.distributions.MultivariateNormal
class, this implementation is much more efficient due to the restriction to standard Normal. Parameters
x (torch.Tensor [N, D]) – The samples whose logprobability shall be computed (number of samples N, dimensionality D).
 Returns
The logprobabilities for all samples.
 Return type
torch.Tensor [N]
GMM¶

pyblaze.nn.functional.
log_prob_standard_gmm
(x, means)[source]¶ Computes the logprobability of observing the given data under a GMM consisting of (multivariate) standard normal distributions. Each component is assigned the same weight.
 Parameters
x (torch.Tensor [N, D]) – The samples whose logprobability shall be computed (number of samples N, dimensionality D).
means (torch.Tensor [M, D]) – The means of the GMM.
 Returns
The logprobabilities for all samples.
 Return type
torch.Tensor [N]
Metrics¶
Accuracy¶

pyblaze.nn.functional.
accuracy
(y_pred, y_true)[source]¶ Computes the accuracy of the class predictions.
 Parameters
y_pred (torch.LongTensor [N] or torch.FloatTensor [N, C]) – The class predictions made by the model. Can be either specific classes or predictions for each class.
y_true (torch.LongTensor [N] or torch.FloatTensor [N, C]) – The actual classes, either given as indices or onehot vectors (more specifically, it may be any vector whose rowwise argmax values yield the class labels).
 Returns
The accuracy.
 Return type
torch.FloatTensor
Recall¶

pyblaze.nn.functional.
recall
(y_pred, y_true, c=1)[source]¶ Computes the recall score of the class predictions.
 Parameters
y_pred (torch.LongTensor [N] or torch.FloatTensor [N, C]) – The class predictions made by the model. Can be either specific classes or predictions for each class.
y_true (torch.LongTensor [N]) – The actual classes.
c (int, default: 1) – The class to calculate the recall score for. Default assumes a binary classification setting.
 Returns
The recall score.
 Return type
torch.FloatTensor
Precision¶

pyblaze.nn.functional.
precision
(y_pred, y_true, c=1)[source]¶ Computes the precision score of the class predictions.
 Parameters
y_pred (torch.LongTensor [N] or torch.FloatTensor [N, C]) – The class predictions made by the model. Can be either specific classes or predictions for each class.
y_true (torch.LongTensor [N]) – The actual classes.
c (int, default: 1) – The class to calculate the recall score for. Default assumes a binary classification setting.
 Returns
The precision score.
 Return type
torch.FloatTensor
F1 Score¶

pyblaze.nn.functional.
f1_score
(y_pred, y_true, c=1)[source]¶ Computes the F1score of the class predictions.
 Parameters
y_pred (torch.LongTensor [N] or torch.FloatTensor [N, C]) – The class predictions made by the model. Can be either specific classes or predictions for each class.
y_true (torch.LongTensor [N]) – The actual classes.
c (int, default: 1) – The class to calculate the recall score for. Default assumes a binary classification setting.
 Returns
The F1score.
 Return type
torch.FloatTensor
ROCAUC Score¶
Average Precision¶

pyblaze.nn.functional.
average_precision
(y_pred, y_true)[source]¶ Computes the average precision of the model predictions.
 Parameters
y_pred (torch.FloatTensor [N]) – The (binary) predictions made by the model.
y_trye (torch.LongTensor [N]) – The actual classes.
 Returns
The average precision.
 Return type
torch.FloatTensor