Skip to content
Normalization.AbstractModifier Type
julia
AbstractModifier{N<:AbstractNormalization} <: AbstractNormalization{eltype(N)}

Abstract type for modifiers that wrap an existing normalization, altering its behavior (for example, by making it robust to outliers or NaN-safe).

Interface

Any concrete modifier type Modifier <: AbstractModifier (such as Robust, Mixed, or NaNSafe) can be applied to a concrete normalization type Normalization <: AbstractNormalization:

julia
N = Modifier{Normalization} # A combined type with a free `eltype` of `Any`
N = Modifier{Normalization{Float64}} # A concrete `eltype` of `Float64`

All AbstractNormalization constructors and traits are then defined for AbstractModifier types.

source
Normalization.AbstractNormalization Type
julia
AbstractNormalization

Abstract type for normalizations.

Constructors

You can work with AbstractNormalizations as either types or instances. The type approach is useful for concise code, whereas the instance approach is useful for performant mutations. In the examples below we use the ZScore normalization, but the same syntax applies to all Normalizations.

Fit to a type

julia
X = randn(100, 10)
N = fit(ZScore, X; dims=nothing) # eltype inferred from X
N = fit(ZScore{Float32}, X; dims=nothing) # eltype set to Float32
N isa AbstractNormalization && N isa ZScore # Returns a concrete AbstractNormalization

Fit to an instance

julia
X = randn(100, 10)
N = ZScore{Float64}(; dims=2) # Initializes with empty parameters
N isa AbstractNormalization && N isa ZScore # Returns a concrete AbstractNormalization
!isfit(N)

fit!(N, X; dims=1) # Fit normalization in-place, and update the `dims`
Normalization.dims(N) == 1

Normalization and denormalization

With a fit normalization, there are two approaches to normalizing data: in-place and out-of-place.

julia
_X = copy(X)
normalize!(_X, N) # Normalizes in-place, updating _X
Y = normalize(X, N) # Normalizes out-of-place, returning a new array
normalize(X, ZScore; dims=1) # For convenience, fits and then normalizes

For most normalizations, there is a corresponding denormalization that transforms data to the original space.

julia
Z = denormalize(Y, N) # Denormalizes out-of-place, returning a new array
Z  X
denormalize!(Y, N) # Denormalizes in-place, updating Y

Properties and traits

Type traits

  • Normalization.estimators(N::Union{<:AbstractNormalization,Type{<:AbstractNormalization}) returns the estimators N as a tuple of functions

  • forward(N::Union{<:AbstractNormalization,Type{<:AbstractNormalization}) returns the forward normalization function (e.g. x-> x - 𝜇 / 𝜎 for the ZScore)

  • inverse(N::Union{<:AbstractNormalization,Type{<:AbstractNormalization}})returns the inverse normalization function e.g.forward(N)(ps...) |> InverseFunctions.inverse`

  • eltype(N::Union{<:AbstractNormalization,Type{<:AbstractNormalization}) returns the eltype of the normalization parameters

Concrete properties

  • Normalization.dims(N::<:AbstractNormalization) returns the dimensions of the normalization. The dimensions are determined by dims and correspond to the mapped slices of the input array.

  • params(N::<:AbstractNormalization) returns the parameters of N as a tuple of arrays. The dimensions of arrays are the complement of dims.

  • isfit(N::<:AbstractNormalization) checks if all parameters are non-empty

source
Normalization.Mixed Type
julia
Mixed{N<:AbstractNormalization} <: AbstractModifier{N}

A modifier type that wraps an existing normalization and replaces its estimators with a mixture of robust and classical statistics.

Mixed uses the median instead of the mean if the interquartile range (IQR) is nonzero, otherwise it falls back to the mean. For the standard deviation, it uses the IQR (divided by 1.35) if nonzero, otherwise it falls back to the standard deviation. This makes the normalization robust to outliers while still using classical estimators when the data is degenerate.

source
Normalization.NaNSafe Type
julia
NaNSafe{N<:AbstractNormalization} <: AbstractModifier{N}

A modifier type that wraps an existing normalization and replaces its estimators with NaN-safe versions.

NaNSafe modifies the estimators of the underlying normalization so that they ignore any NaN values in the input data.

source
Normalization.Robust Type
julia
Robust{N<:AbstractNormalization} <: AbstractModifier{N}

A modifier type that wraps an existing normalization and replaces its estimators with robust statistics.

Robust replaces the mean with the median and the standard deviation with the interquartile range (IQR, divided by 1.35 so that it matches the standard deviation for normally distributed data). This makes the normalization more robust to outliers.

source