Neighbourhood strategy submodule#

Code author: Wilfried Mercier - IRAP <wilfried.mercier@irap.omp.eu>

Classes defining the behaviour of the BMU neighbourhood.

How to implement a custom neighbourhood class ?#

To implement a custom neighbourhood strategy, please inherit from NeighbourhoodStrategy and implement your own NeighbourhoodStrategy.__init__ and NeighbourhoodStrategy.__call__ methods as follows

class NewNeighbourhoodStrategy(NeighbourhoodStrategy):

    def __init__(self, sigma: Union[int, float] = 1, **kwargs) -> None:

        super().__init__(sigma=sigma)

        ...

    def __call__(step, *args, **kwargs) -> float:

        ...

        return sigma

The NeighbourhoodStrategy.__call__ method must always have step as its first argument.

Note

Additional arguments with *args and **kwargs in NeighbourhoodStrategy.__call__ method can be present but should not be used.

API#

class SOMptimised.neighbourhood.ConstantRadiusStrategy(sigma: Union[int, float] = 1, **kwargs)[source]#

Bases: SOMptimised.neighbourhood.NeighbourhoodStrategy

Code author: Wilfried Mercier - IRAP <wilfried.mercier@irap.omp.eu>

Class implementing a constant neighbourhood radius strategy.

Parameters

sigma (int or float) – (Optional) neighbourhood radius

__call__(step: int, *args, **kwargs) float[source]#

Code author: Wilfried Mercier - IRAP <wilfried.mercier@irap.omp.eu>

Provide the neighbourhood radius at the given time step.

Parameters

step (int) – time step during the learning process

Returns

neighbourhood radius

Return type

float

class SOMptimised.neighbourhood.ExponentialRadiusStrategy(sigma: Union[int, float] = 1, tau: Union[int, float] = 1, **kwargs)[source]#

Bases: SOMptimised.neighbourhood.NeighbourhoodStrategy

Code author: Wilfried Mercier - IRAP <wilfried.mercier@irap.omp.eu>

Class implementing an exponential neighbourhood radius strategy.

Parameters
  • sigma (int or float) – (Optional) neighbourhood radius

  • tau (int or float) – (Optional) decay time scale

__call__(step: int, *args, **kwargs)[source]#

Code author: Wilfried Mercier - IRAP <wilfried.mercier@irap.omp.eu>

Provide the neighbourhood radius at the given time step.

Parameters

step (int) – time step during the learning process

Returns

neighbourhood radius

Return type

float

property tau: float#

Code author: Wilfried Mercier - IRAP <wilfried.mercier@irap.omp.eu>

Provide the value of tau.

class SOMptimised.neighbourhood.NeighbourhoodStrategy(sigma: Union[int, float] = 1, **kwargs)[source]#

Bases: abc.ABC

Code author: Wilfried Mercier - IRAP <wilfried.mercier@irap.omp.eu>

Abstract class for strategies implementing neighbourhood radii strategies.

Parameters

sigma (int or float) – (Optional) neighbourhood radius

abstract __call__(step: int, *args, **kwargs) float[source]#

Code author: Wilfried Mercier - IRAP <wilfried.mercier@irap.omp.eu>

Provide the neighbourhood radius at the given step.

Parameters

step (int) – time step during the learning process

Returns

neighbourhood radius at the given time step

Return type

float

static _check_int_float(param: Any, name: str, *args, **kwargs) None[source]#

Code author: Wilfried Mercier - IRAP <wilfried.mercier@irap.omp.eu>

Check if a parameter is int or float.

Parameters
  • param – value to check

  • name – name of the parameter

Type

str

Raises

TypeError – if not isinstance(param, (int, float))

static _check_negative(param: Any, name: str, *args, **kwargs) None[source]#

Code author: Wilfried Mercier - IRAP <wilfried.mercier@irap.omp.eu>

Check if a parameter is negative.

Parameters
  • param – value to check

  • name – name of the parameter

Type

str

Raises

ValueError – if lr < 0

_check_sigma(value: Any, name: str = 'sigma', **kwargs) None[source]#

Code author: Wilfried Mercier - IRAP <wilfried.mercier@irap.omp.eu>

Check if a value is acceptable for the neighbourhood radius.

Parameters

value – value to check

Raises
  • TypeError – if not isinstance(value, (int, float))

  • ValueError – if value < 0

property sigma: float#

Code author: Wilfried Mercier - IRAP <wilfried.mercier@irap.omp.eu>

Provide the value of sigma.