Skip to content

noise_producer

frog.hardware.noise_producer ¤

Provides a class for producing random noise.

Classes¤

NoiseParameters(mean=0.0, standard_deviation=1.0, seed=42) dataclass ¤

A compact way of expressing arguments to NoiseProducer.

NoiseProducer(mean=0.0, standard_deviation=1.0, type=float, seed=42) ¤

A callable object which produces normally distributed noise.

Create a new NoiseProducer.

Parameters:

Name Type Description Default
mean float

The distribution's mean

0.0
standard_deviation float

The distribution's standard deviation

1.0
type type

The type of the returned value

float
seed int | None

Initial random seed (None for random)

42
Source code in frog/hardware/noise_producer.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def __init__(
    self,
    mean: float = 0.0,
    standard_deviation: float = 1.0,
    type: type = float,
    seed: int | None = 42,
) -> None:
    """Create a new NoiseProducer.

    Args:
        mean: The distribution's mean
        standard_deviation: The distribution's standard deviation
        type: The type of the returned value
        seed: Initial random seed (None for random)
    """
    self.rng = np.random.default_rng(seed)
    self.mean = mean
    self.standard_deviation = standard_deviation
    self.type = type
Functions¤
__call__(*args, **kwargs) ¤

Return some noise.

Returns:

Type Description
Any

A random number of the specified type.

Source code in frog/hardware/noise_producer.py
34
35
36
37
38
39
40
def __call__(self, *args: Any, **kwargs: Any) -> Any:
    """Return some noise.

    Returns:
        A random number of the specified type.
    """
    return self.type(self.rng.normal(self.mean, self.standard_deviation))
from_parameters(parameters, type=float) classmethod ¤

Create a NoiseProducer from a NoiseParameters object.

Source code in frog/hardware/noise_producer.py
42
43
44
45
46
47
@classmethod
def from_parameters(
    cls, parameters: NoiseParameters, type: type = float
) -> NoiseProducer:
    """Create a NoiseProducer from a NoiseParameters object."""
    return cls(**asdict(parameters), type=type)