colosseum.noises.base

 1import abc
 2from typing import List, Callable, Tuple
 3
 4import numpy as np
 5
 6from colosseum import config
 7
 8
 9class Noise(abc.ABC):
10    """
11    The base class for the noise to be applied to the emission maps.
12    """
13
14    @abc.abstractmethod
15    def _sample_noise(self, n: int) -> np.ndarray:
16        """
17        Returns
18        -------
19        np.ndarray
20            The n samples of the noise_class.
21        """
22
23    @property
24    def shape(self) -> Tuple[int, ...]:
25        """
26        Returns
27        -------
28        Tuple[int, ...]
29            The shape of the emission map to which the noise is applied.
30        """
31        if self._shape is None:
32            self._shape = self._shape_f()
33        return self._shape
34
35    def __init__(self, seed: int, shape_f: Callable[[], List[int]]):
36        """
37        Parameters
38        ----------
39        seed : int
40            The random seed.
41        shape_f : Callable[[], List[int]]
42            The function that returns the shape of the emission map.
43        """
44
45        self._rng = np.random.RandomState(seed)
46        self._shape_f = shape_f
47
48        self._shape = None
49        self._cached_samples = []
50
51    def __next__(self):
52        if len(self._cached_samples) == 0:
53            self._cached_samples = list(
54                self._sample_noise(config.get_size_cache_noise()).astype(np.float32)
55            )
56        return self._cached_samples.pop(0)
class Noise(abc.ABC):
10class Noise(abc.ABC):
11    """
12    The base class for the noise to be applied to the emission maps.
13    """
14
15    @abc.abstractmethod
16    def _sample_noise(self, n: int) -> np.ndarray:
17        """
18        Returns
19        -------
20        np.ndarray
21            The n samples of the noise_class.
22        """
23
24    @property
25    def shape(self) -> Tuple[int, ...]:
26        """
27        Returns
28        -------
29        Tuple[int, ...]
30            The shape of the emission map to which the noise is applied.
31        """
32        if self._shape is None:
33            self._shape = self._shape_f()
34        return self._shape
35
36    def __init__(self, seed: int, shape_f: Callable[[], List[int]]):
37        """
38        Parameters
39        ----------
40        seed : int
41            The random seed.
42        shape_f : Callable[[], List[int]]
43            The function that returns the shape of the emission map.
44        """
45
46        self._rng = np.random.RandomState(seed)
47        self._shape_f = shape_f
48
49        self._shape = None
50        self._cached_samples = []
51
52    def __next__(self):
53        if len(self._cached_samples) == 0:
54            self._cached_samples = list(
55                self._sample_noise(config.get_size_cache_noise()).astype(np.float32)
56            )
57        return self._cached_samples.pop(0)

The base class for the noise to be applied to the emission maps.

Noise(seed: int, shape_f: Callable[[], List[int]])
36    def __init__(self, seed: int, shape_f: Callable[[], List[int]]):
37        """
38        Parameters
39        ----------
40        seed : int
41            The random seed.
42        shape_f : Callable[[], List[int]]
43            The function that returns the shape of the emission map.
44        """
45
46        self._rng = np.random.RandomState(seed)
47        self._shape_f = shape_f
48
49        self._shape = None
50        self._cached_samples = []
Parameters
  • seed (int): The random seed.
  • shape_f (Callable[[], List[int]]): The function that returns the shape of the emission map.
shape: Tuple[int, ...]
Returns
  • Tuple[int, ...]: The shape of the emission map to which the noise is applied.