input.noise package¶
Submodules¶
input.noise.noise_process module¶
Created on 28 de mar de 2019
@author: klaus
-
class
input.noise.noise_process.
LabelNoiseProcess
(**kwargs)¶ Bases:
object
A noise process, which is used to corrupt the original, clean labels.
Currently, the following parameters are expected:
type : Specifies the type of noise. Currently, this may be
"NCAR"
: Noisy Completely at Random. The occurrence of error is independent of other random variables, including the true labels. The chance of a label being flipped to a given, different class is :math:\frac{p}{C-1}
. Requires specification of parameternoise_corruption
, which determines \(p\).
seed : Specifies the seed for reproducibility purposes.
deterministic : If True, the distribution of actual flips tries to reflect the scaled matrix of transition probabilities. This means that, while the chosen labels might differ from run to run, the number of flips is essentially fixed, we have a fixed quantity of ‘corrupted labels’.
-
__init__
(**kwargs)¶ Constructor for LabelNoiseProcess.
- Parameters
**kwargs – Key-value pairs with the configuration options.
- Raises
KeyError – If one of the required keys is not found.
-
corrupt
(Y, labeledIndexes, hook=None)¶ Corrupts a set of clean labels, obtaining the corrupted labels.
- Parameters
Y (NDArray[float].shape[N,C]) – Target belief matrix, whose rows are one-hot selecting the correct label.
labeledIndexes (NDArray[bool].shape[N]) – A boolean array, indicating which instances are to be interpreted as labeled.
hook (GSSLHook) – Optional. A hook to be called before/during/after the noise process
- Returns
Corrupted version of the target belief matrix
- Return type
(NDArray[float].shape[N,C])
input.noise.noise_utils module¶
noise_utils.py¶
Module containing utilities related to noise.
-
input.noise.noise_utils.
apply_noise
(Y, labeledIndexes, A, seed=None, deterministic=True)¶ Corrupts a set percentage of initial labels with noise.
- Parameters
Y ([NDArray[int].shape[N,C]) – Matrix encoding initial beliefs.
A ([NDArray[int].shape[C,C]) – Transition probabilities between each class.
labeledIndexes (NDArray[bool].shape[N]) – determines which indices are to be considered as labeled.
seed (float) – Optional. Used to reproduce results.
- Returns
Belief matrix after corruption.
- Return type
NDArray[int].shape[N,C]
-
input.noise.noise_utils.
transition_count_mat
(Y, A)¶ Obtains a transition count matrix for uniform noise, indicating how many instances should have their label flipped and to which class.
Specifically, this returns a matrix M such that \(M[i,j]\) is the number of instances of i-th class to be swapped to the j-th class.
- Parameters
Y ([NDArray[int].shape[N,C]) – Matrix encoding initial beliefs.
A ([NDArray[int].shape[C,C]) – Transition probabilities between each class.
- Returns
the transition count matrix.
- Return type
[NDArray[int].shape[C,C]
- Raises
ValueError – if p is an invalid percentage.
-
input.noise.noise_utils.
uniform_noise_transition_prob_mat
(Y, p)¶ Obtains the transition probabilities between each class for uniform label noise.
- Parameters
Y ([NDArray[int].shape[N,C]) – Matrix encoding initial beliefs.
p (float) – The percentage of labels to be flipped
- Returns
the transition probability matrix.
- Return type
[NDArray[int].shape[C,C]
- Raises
ValueError – if p is an invalid percentage.