ding.utils.normalizer_helper¶
ding.utils.normalizer_helper
¶
DatasetNormalizer
¶
Overview
The DatasetNormalizer class provides functionality to normalize and unnormalize data in a dataset.
It takes a dataset as input and applies a normalizer function to each key in the dataset.
Interfaces
__init__, __repr__, normalize, unnormalize.
__init__(dataset, normalizer, path_lengths=None)
¶
Overview
Initialize the NormalizerHelper object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
- dataset (
|
obj: |
required | |
- normalizer (
|
obj: |
required | |
- path_lengths (
|
obj: |
required |
__repr__()
¶
Overview
Returns a string representation of the NormalizerHelper object. The string representation includes the key-value pairs of the normalizers stored in the NormalizerHelper object.
Returns:
- ret (:obj:str):A string representation of the NormalizerHelper object.
normalize(x, key)
¶
Overview
Normalize the input data using the specified key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
- x (
|
obj: |
required | |
- key (
|
obj |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
|
unnormalize(x, key)
¶
Overview
Unnormalizes the given value x using the specified key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
- x (
|
obj: |
required | |
- key (
|
obj |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
|
Normalizer
¶
Overview
Parent class, subclass by defining the normalize and unnormalize methods
Interfaces
__init__, __repr__, normalize, unnormalize.
__init__(X)
¶
Overview
Initialize the Normalizer object.
Arguments:
- X (:obj:np.ndarray): The data to be normalized.
__repr__()
¶
Overview
Returns a string representation of the Normalizer object.
Returns:
- ret (:obj:str): A string representation of the Normalizer object.
normalize(*args, **kwargs)
¶
Overview
Normalize the input data.
Arguments:
- args (:obj:list): The arguments passed to the normalize function.
- kwargs (:obj:dict): The keyword arguments passed to the normalize function.
unnormalize(*args, **kwargs)
¶
Overview
Unnormalize the input data.
Arguments:
- args (:obj:list): The arguments passed to the unnormalize function.
- kwargs (:obj:dict): The keyword arguments passed to the unnormalize function.
GaussianNormalizer
¶
Bases: Normalizer
Overview
A class that normalizes data to zero mean and unit variance.
Interfaces
__init__, __repr__, normalize, unnormalize.
__init__(*args, **kwargs)
¶
Overview
Initialize the GaussianNormalizer object.
Arguments:
- args (:obj:list): The arguments passed to the __init__ function of the parent class, i.e., the Normalizer class.
- kwargs (:obj:dict): The keyword arguments passed to the __init__ function of the parent class, i.e., the Normalizer class.
__repr__()
¶
Overview
Returns a string representation of the GaussianNormalizer object.
Returns:
- ret (:obj:str): A string representation of the GaussianNormalizer object.
normalize(x)
¶
Overview
Normalize the input data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
- x (
|
obj: |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
|
unnormalize(x)
¶
Overview
Unnormalize the input data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
- x (
|
obj: |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
|
CDFNormalizer
¶
Bases: Normalizer
Overview
A class that makes training data uniform (over each dimension) by transforming it with marginal CDFs.
Interfaces
__init__, __repr__, normalize, unnormalize.
__init__(X)
¶
Overview
Initialize the CDFNormalizer object.
Arguments:
- X (:obj:np.ndarray): The data to be normalized.
__repr__()
¶
Overview
Returns a string representation of the CDFNormalizer object.
Returns:
- ret (:obj:str): A string representation of the CDFNormalizer object.
wrap(fn_name, x)
¶
Overview
Wraps the given function name and applies it to the input data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
- fn_name (
|
obj: |
required | |
- x (
|
obj: |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
|
normalize(x)
¶
Overview
Normalizes the input data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
- x (
|
obj: |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
|
unnormalize(x)
¶
Overview
Unnormalizes the input data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
- x (
|
obj: |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
|
CDFNormalizer1d
¶
Overview
CDF normalizer for a single dimension. This class provides methods to normalize and unnormalize data using the Cumulative Distribution Function (CDF) approach.
Interfaces:
__init__, __repr__, normalize, unnormalize.
__init__(X)
¶
Overview
Initialize the CDFNormalizer1d object.
Arguments:
- X (:obj:np.ndarray): The data to be normalized.
__repr__()
¶
Overview
Returns a string representation of the CDFNormalizer1d object.
normalize(x)
¶
Overview
Normalize the input data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
- x (
|
obj: |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
|
unnormalize(x, eps=0.0001)
¶
Overview
Unnormalize the input data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
- x (
|
obj: |
required | |
- eps (
|
obj: |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
|
LimitsNormalizer
¶
Bases: Normalizer
Overview
A class that normalizes and unnormalizes values within specified limits. This class maps values within the range [xmin, xmax] to the range [-1, 1].
Interfaces
__init__, __repr__, normalize, unnormalize.
normalize(x)
¶
Overview
Normalizes the input values.
Argments
- x (:obj:
np.ndarray): The input values to be normalized.
Returns:
| Type | Description |
|---|---|
ndarray
|
|
unnormalize(x, eps=0.0001)
¶
Overview
Unnormalizes the input values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
- x (
|
obj: |
required | |
- eps (
|
obj: |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
|
flatten(dataset, path_lengths)
¶
Overview
Flattens dataset of { key: [ n_episodes x max_path_length x dim ] } to { key : [ (n_episodes * sum(path_lengths)) x dim ] }
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
- dataset (
|
obj: |
required | |
- path_lengths (
|
obj: |
required |
Returns:
| Type | Description |
|---|---|
dict
|
|
empirical_cdf(sample)
¶
Overview
Compute the empirical cumulative distribution function (CDF) of a given sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
- sample (
|
obj: |
required |
Returns:
| Type | Description |
|---|---|
(ndarray, ndarray)
|
|
(ndarray, ndarray)
|
|
References
- Stack Overflow: https://stackoverflow.com/a/33346366
atleast_2d(x)
¶
Overview
Ensure that the input array has at least two dimensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
- x (
|
obj: |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
|
Full Source Code
../ding/utils/normalizer_helper.py