Randomness

pyroomacoustics.random.get_rng()

Access to the package global RNG.

pyroomacoustics.random.power_spherical(loc=None, scale=None, size=None, rng=None)

Generates power spherical samples on the (n-1)-sphere according to

Nicola De Cao, Wilker Aziz, “The Power Spherical distribution”, arXiv, 2020. http://arxiv.org/abs/2006.04437v1

Parameters:
  • loc (float or array_like of floats, optional) – The location (i.e., direction) unit vector. If None, then loc = np.array([1.0, 0.0, 0.0]) is used.

  • scale (float or array_like of floats) – The scale parameter descibing the spread of the distribution

  • size (int or tuple of ints, optional) – The number of samples to generate

  • rng (numpy.random.Generator or None) – A numpy.random.Generator object or None. If None, numpy.random.default_rng is used to obtain a Generator object.

Returns:

out – The samples draw from the uniform distribution on the n-sphere

Return type:

ndarray, shape (*size, dim)

pyroomacoustics.random.seed(numpy=None, libroom=None)

Sets the seeds of the numpy random generator and optionally of the libroom sub-package.

Parameters:
  • numpy ({None, int, array_like[ints], SeedSequence, BitGenerator, Generator}, optional) – Seed for the Numpy generator. Seed Numpy doc for details.

  • libroom (Unsigned 64 bit int.) – Seed for the libroom sub-package (integer between 0 and 2 ** 64 - 1). If it not provided, it is derived from the Numpy RNG.

pyroomacoustics.random.uniform_spherical(dim=3, size=None, rng=None)

Generates uniform samples on the n-sphere

Parameters:
  • size (int or tuple of ints, optional) – The number of samples to generate

  • dim (int, optional) – The number of dimensions of the sphere, the default is dim=3

  • rng (numpy.random.Generator or None) – A numpy.random.Generator object or None. If None, numpy.random.default_rng is used to obtain a Generator object.

Returns:

out – The samples draw from the uniform distribution on the n-sphere

Return type:

ndarray, shape (*size, dim)

Random Number Generator

Access to a package-wide random number generator (RNG).

The simulation can be made deterministic by fixing a seed.

# Globally seed pyroomacoustics.
pra.random.seed(42)

# Seed the numpy and libroom RNGs separately
pra.random.seed(numpy=42, libroom=43)
pyroomacoustics.random.generator.get_rng()

Access to the package global RNG.

pyroomacoustics.random.generator.seed(numpy=None, libroom=None)

Sets the seeds of the numpy random generator and optionally of the libroom sub-package.

Parameters:
  • numpy ({None, int, array_like[ints], SeedSequence, BitGenerator, Generator}, optional) –

    Seed for the Numpy generator. Seed Numpy doc for details.

  • libroom (Unsigned 64 bit int.) – Seed for the libroom sub-package (integer between 0 and 2 ** 64 - 1). If it not provided, it is derived from the Numpy RNG.