Utilities

utils.get_unif_Vmax(mu)
Description:
Estimates the maximum variance needed for the uniform distribution to produce maximum heteroscedasticity.
Return:
vmax:the maximum uniform variance.
Return type:
float
Args:
mu:mean of the the uniform.
scale_value [optional]:
 controls scaling the Vmax to different values.

Here is the formula for estimating \(V_{max}\)

\[V_{max} = \frac{4 \mu^2}{12}\]
utils.normalize_labels(labels, labels_mean, labels_std)
Description:
Normalize the training labels as follow:
\[\widetilde{y} = \frac{(y - \overline{y})} {\sigma_y}.\]

where

\[\widetilde{y} = \text{Normalized labels, } y = \text{labels, } \overline{y} = \text{Mean of the labels, }. \sigma = \text{Standard deviation of the labels}\]
Return:
labels_norm:Normalized labels.
Return type:
1D Tensor.
Args:
labels:Training labels.
labels_mean:Emprical mean of the training labels .
labels_std:Emprical standard deviation of the training labels.
utils.normalize_features(features, features_mean, features_std, dataset='UTKFace')
Description:
Normalize the training input features as follows:
\[\widetilde{X} = \frac{(X - \overline{X})} {\sigma_x}.\]

where

\[\widetilde{X} = \text{Normalized features, } X = \text{Input features, } \overline{X} = \text{Features mean, }. \sigma = \text{Features standard deviation}\]
Return:
images_norm:Normalized Features.
Return type:
NxD Tensor
Args:
features:train data. (images)
features_mean:Mean of the features.
features_std:Standard deviation of the features.
dataset:Name of the dataset that needs to be normalized.
utils.str_to_bool(string)
Description:
Convert a string to a boolean.
Return:
True or False.
Return type:
boolean
Args:
string:A string to be converted.
utils.generate_intervals(num_dists, p=0.5)
Description:
Generates intervals for sampling noise variance distributions. The intervals are low, which assigns low sampling probablity values, and high, that assigns high values.
Return:
intervals
Return type:
Dictionary
Args:
num_dists:Number of distributions that need to have sampling intervals.
p:Interval balance factor.It controls the balance between low and high intervals.
utils.choose_distribution(intervals)
Description:
Chooses a distribution based on sampling from the intervals.
Return:
key, (an id for the sampled distribution)
Return type:
int
Args:
intervals:A dictionary of tuple values, each tuple represents an interval that is compared against when the sampling happens.
p:Interval balance factor.It controls the balance between low and high intervals.
utils.get_mean_avg_variance(noise_type, avg_variance_m, mu1, p)
Description:
Estimates the value of the mean of the second distribution, in a bi-model distribution, based on the average noise varaince mean.
Return:
mu2
Return type:
float
Args:
noise_type:Noise type.
avg_variance_m:The average of means of the noise variance distributions.
mu1:First distribution’s mean.
p:Distributions ratio.
utils.print_experiment_information(args)
Description:

Print experiment information, which consists of :

  1. Dataset information.
  2. Models informations.
  3. Commandline options information.
Return:
None
Return type:
None
Args:
args:Commandline options.
utils.filter_batch(predictions, labels, noise_var, threshold = 0.4)
Description:
Filters a batch of labels based on a noise varaince threshold.
Return:
filtered predictions, filtered labels , filtered noise_variance
Return type:
Tuple
Args:
predictions:model’s predictions.
labels:Noisy labels.
noise_var:noises variances
threshold:noise variance threshold.
utils.assert_args_mixture(args)
Description:
Check the validaty of the combination of two or more arguments.
Return:
None
Return type:
None
Args:
args:Arguments that need to be checked.