View Source Scholar.Preprocessing.Normalizer (Scholar v0.3.0)

Implements functionality for rescaling tensor to unit norm. It enables to apply normalization along any combination of axes.

Summary

Functions

Normalize samples individually to unit norm.

Functions

Link to this function

fit_transform(tensor, opts \\ [])

View Source

Normalize samples individually to unit norm.

The zero-tensors cannot be normalized and they stay the same after normalization.

Options

  • :axes - Axes to calculate the distance over. By default the distance is calculated between the whole tensors.

  • :norm - The norm to use to normalize each non zero sample. Possible options are :euclidean, :manhattan, and :chebyshev The default value is :euclidean.

Examples

iex> t = Nx.tensor([[0, 0, 0], [3, 4, 5], [-2, 4, 3]])
iex> Scholar.Preprocessing.Normalizer.fit_transform(t, axes: [1])
#Nx.Tensor<
  f32[3][3]
  [
    [0.0, 0.0, 0.0],
    [0.4242640733718872, 0.5656854510307312, 0.7071067690849304],
    [-0.3713906705379486, 0.7427813410758972, 0.5570860505104065]
  ]
>

iex> t = Nx.tensor([[0, 0, 0], [3, 4, 5], [-2, 4, 3]])
iex> Scholar.Preprocessing.Normalizer.fit_transform(t)
#Nx.Tensor<
  f32[3][3]
  [
    [0.0, 0.0, 0.0],
    [0.3375263810157776, 0.4500351846218109, 0.5625439882278442],
    [-0.22501759231090546, 0.4500351846218109, 0.3375263810157776]
  ]
>