Skip to content

Learning rate

Catalog of learning rate functions.

AbstractLr

Bases: Module

Ensures that all learning rate functions have the same signatures.

Source code in src/somap/learning_rate.py
class AbstractLr(eqx.Module):
    """Ensures that all learning rate functions have the same signatures."""

    @abstractmethod
    def __call__(
        self, t: Integer[Array, ""], distances: Float[Array, "x y"]
    ) -> Float[Array, ""] | Float[Array, "x y"]:
        """SOM learning rate function.

        Args:
            t: Current iteration.
            distances: Distances between the prototype weights and the input data.

        Returns:
            A scalar ar 2D array containing the learning rate.
        """
        pass

__call__(t, distances) abstractmethod

SOM learning rate function.

Parameters:

Name Type Description Default
t Integer[Array, '']

Current iteration.

required
distances Float[Array, 'x y']

Distances between the prototype weights and the input data.

required

Returns:

Type Description
Float[Array, ''] | Float[Array, 'x y']

A scalar ar 2D array containing the learning rate.

Source code in src/somap/learning_rate.py
@abstractmethod
def __call__(
    self, t: Integer[Array, ""], distances: Float[Array, "x y"]
) -> Float[Array, ""] | Float[Array, "x y"]:
    """SOM learning rate function.

    Args:
        t: Current iteration.
        distances: Distances between the prototype weights and the input data.

    Returns:
        A scalar ar 2D array containing the learning rate.
    """
    pass

ConstantLr

Bases: AbstractLr

Basic SOM learning rate function.

Source code in src/somap/learning_rate.py
class ConstantLr(AbstractLr):
    """Basic SOM learning rate function."""

    alpha: float | Float[Array, "..."] = 0.01

    def __call__(self, _, __) -> Float[Array, ""]:
        """Returns the static SOM learning rate."""
        return jnp.array(self.alpha)

__call__(_, __)

Returns the static SOM learning rate.

Source code in src/somap/learning_rate.py
def __call__(self, _, __) -> Float[Array, ""]:
    """Returns the static SOM learning rate."""
    return jnp.array(self.alpha)

DsomLr

Bases: AbstractLr

DSOM learning rate function.

Source code in src/somap/learning_rate.py
class DsomLr(AbstractLr):
    """DSOM learning rate function."""

    alpha: float | Float[Array, "..."] = 0.001

    def __call__(self, _, distances: Float[Array, "x y"]) -> Float[Array, "x y"]:
        """Returns the DSOM learning rate."""
        return self.alpha * distances

__call__(_, distances)

Returns the DSOM learning rate.

Source code in src/somap/learning_rate.py
def __call__(self, _, distances: Float[Array, "x y"]) -> Float[Array, "x y"]:
    """Returns the DSOM learning rate."""
    return self.alpha * distances

KsomLr

Bases: AbstractLr

Kohonen SOM learning rate function.

Source code in src/somap/learning_rate.py
class KsomLr(AbstractLr):
    """Kohonen SOM learning rate function."""

    t_f: int | Integer[Array, "..."] = 100000
    alpha_i: float | Float[Array, "..."] = 0.01
    alpha_f: float | Float[Array, "..."] = 0.001

    def __call__(self, t: Integer[Array, ""], _) -> Float[Array, ""]:
        """Returns the Kohonen SOM learning rate."""
        return self.alpha_i * (self.alpha_f / self.alpha_i) ** (t / self.t_f)

__call__(t, _)

Returns the Kohonen SOM learning rate.

Source code in src/somap/learning_rate.py
def __call__(self, t: Integer[Array, ""], _) -> Float[Array, ""]:
    """Returns the Kohonen SOM learning rate."""
    return self.alpha_i * (self.alpha_f / self.alpha_i) ** (t / self.t_f)