citylearn.preprocessing module

class citylearn.preprocessing.Encoder[source]

Bases: object

Base class to transform observations.

class citylearn.preprocessing.NoNormalization[source]

Bases: Encoder

Use to return observation value as-is i.e. without any transformation.

Examples

>>> x_max = 24
>>> encoder = NoNormalization()
>>> observation = 2
>>> encoder*observation
2
class citylearn.preprocessing.Normalize(x_min: float | int, x_max: float | int)[source]

Bases: Encoder

Use to transform observations to a value between x_min and x_max using min-max normalization.

Parameters:
  • x_min (Union[float, int]) – Minimum observation value.

  • x_max (Union[float, int]) – Maximum observation value.

Notes

The transformation returns two values \(x_{sin}\) and \(x_{sin}\) defined as:

\[x = \frac{x - x_{min}}{x_{max} - x_{min}}\]

Examples

>>> x_min = 0
>>> x_max = 24
>>> encoder = Normalize(x_min, x_max)
>>> observation = 2
>>> encoder*observation
0.08333333333333333
class citylearn.preprocessing.OnehotEncoding(classes: List[float] | List[int] | List[str])[source]

Bases: Encoder

Use to transform unordered categorical observations e.g. boolean daylight savings e.t.c.

Parameters:

classes (Union[List[float], List[int], List[str]]) – Observation categories.

Examples

>>> classes = [1, 2, 3, 4]
>>> encoder = OnehotEncoding(classes)
# identity_matrix = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]
>>> observation = 2
>>> encoder*observation
[0, 1, 0, 0]
class citylearn.preprocessing.PeriodicNormalization(x_max: float | int)[source]

Bases: Encoder

Use to transform observations that are cyclical/periodic e.g. hour-of-day, day-of-week, e.t.c.

Parameters:

x_max (Union[float, int]) – Maximum observation value.

Notes

The transformation returns two values \(x_{sin}\) and \(x_{sin}\) defined as:

\[ \begin{align}\begin{aligned}x_{sin} = sin(\frac{2 \cdot \pi \cdot x}{x_{max}})\\x_{cos} = cos(\frac{2 \cdot \pi \cdot x}{x_{max}})\end{aligned}\end{align} \]

Examples

>>> x_max = 24
>>> encoder = PeriodicNormalization(x_max)
>>> observation = 2
>>> encoder*observation
array([0.75, 0.9330127])
class citylearn.preprocessing.RemoveFeature[source]

Bases: Encoder

Use to exlude an observation by returning None type.

Examples

>>> encoder = RemoveFeature()
>>> observation = 2
>>> encoder*observation
None