Shortcuts

rising.random

Random Parameter Injection Base Classes

class rising.random.abstract.AbstractParameter(*args, **kwargs)[source][source]

Bases: torch.nn.Module

Abstract Parameter class to inject randomness to transforms

static _get_n_samples(size=(1, ))[source][source]

Calculates the number of elements in the given size

Parameters

size (Union[Sequence, Size]) – Sequence or torch.Size

Returns

the number of elements

Return type

int

forward(size=None, device=None, dtype=None, tensor_like=None)[source][source]

Forward function (will also be called if the module is called). Calculates the number of samples from the given shape, performs the sampling and converts it back to the correct shape.

Parameters
  • size (Union[Sequence, Size, None]) – the size of the sampled values. If None, it samples one value without reshaping

  • device (Union[device, str, None]) – the device the result value should be set to, if it is a tensor

  • dtype (Union[dtype, str, None]) – the dtype, the result value should be casted to, if it is a tensor

  • tensor_like (Optional[Tensor]) – the tensor, having the correct dtype and device. The result will be pushed onto this device and casted to this dtype if this is specified.

Returns

the sampled values

Return type

list or torch.Tensor

Notes

if the parameter tensor_like is given, it overwrites the parameters dtype and device

abstract sample(n_samples)[source][source]

Abstract sampling function

Parameters

n_samples (int) – the number of samples to return

Returns

the sampled values

Return type

torch.Tensor or list

AbstractParameter

class rising.random.abstract.AbstractParameter(*args, **kwargs)[source][source]

Bases: torch.nn.Module

Abstract Parameter class to inject randomness to transforms

static _get_n_samples(size=(1, ))[source][source]

Calculates the number of elements in the given size

Parameters

size (Union[Sequence, Size]) – Sequence or torch.Size

Returns

the number of elements

Return type

int

forward(size=None, device=None, dtype=None, tensor_like=None)[source][source]

Forward function (will also be called if the module is called). Calculates the number of samples from the given shape, performs the sampling and converts it back to the correct shape.

Parameters
  • size (Union[Sequence, Size, None]) – the size of the sampled values. If None, it samples one value without reshaping

  • device (Union[device, str, None]) – the device the result value should be set to, if it is a tensor

  • dtype (Union[dtype, str, None]) – the dtype, the result value should be casted to, if it is a tensor

  • tensor_like (Optional[Tensor]) – the tensor, having the correct dtype and device. The result will be pushed onto this device and casted to this dtype if this is specified.

Returns

the sampled values

Return type

list or torch.Tensor

Notes

if the parameter tensor_like is given, it overwrites the parameters dtype and device

abstract sample(n_samples)[source][source]

Abstract sampling function

Parameters

n_samples (int) – the number of samples to return

Returns

the sampled values

Return type

torch.Tensor or list

Continuous Random Parameters

class rising.random.continuous.ContinuousParameter(distribution)[source][source]

Bases: rising.random.abstract.AbstractParameter

Class to perform parameter sampling from torch distributions

Parameters

distribution (Distribution) – the distribution to sample from

sample(n_samples)[source][source]

Samples from the internal distribution

Parameters

n_samples (int) – the number of elements to sample

Returns

torch.Tensor: samples

Return type

Tensor

class rising.random.continuous.NormalParameter(mu, sigma)[source][source]

Bases: rising.random.continuous.ContinuousParameter

Samples Parameters from a normal distribution. For details have a look at torch.distributions.Normal

Parameters
class rising.random.continuous.UniformParameter(low, high)[source][source]

Bases: rising.random.continuous.ContinuousParameter

Samples Parameters from a uniform distribution. For details have a look at torch.distributions.Uniform

Parameters

ContinuousParameter

class rising.random.continuous.ContinuousParameter(distribution)[source][source]

Bases: rising.random.abstract.AbstractParameter

Class to perform parameter sampling from torch distributions

Parameters

distribution (Distribution) – the distribution to sample from

sample(n_samples)[source][source]

Samples from the internal distribution

Parameters

n_samples (int) – the number of elements to sample

Returns

torch.Tensor: samples

Return type

Tensor

NormalParameter

class rising.random.continuous.NormalParameter(mu, sigma)[source][source]

Bases: rising.random.continuous.ContinuousParameter

Samples Parameters from a normal distribution. For details have a look at torch.distributions.Normal

Parameters

UniformParameter

class rising.random.continuous.UniformParameter(low, high)[source][source]

Bases: rising.random.continuous.ContinuousParameter

Samples Parameters from a uniform distribution. For details have a look at torch.distributions.Uniform

Parameters

Discrete Random Parameters

class rising.random.discrete.DiscreteParameter(population, replacement=False, weights=None, cum_weights=None)[source][source]

Bases: rising.random.abstract.AbstractParameter

Samples parameters from a discrete population with or without replacement

Parameters
  • population (Sequence) – the parameter population to sample from

  • replacement (bool) – whether or not to sample with replacement

  • weights (Optional[Sequence]) – relative sampling weights

  • cum_weights (Optional[Sequence]) – cumulative sampling weights

sample(n_samples)[source][source]

Samples from the discrete internal population

Parameters

n_samples (int) – the number of elements to sample

Returns

the sampled values

Return type

list

class rising.random.discrete.DiscreteCombinationsParameter(population, replacement=False)[source][source]

Bases: rising.random.discrete.DiscreteParameter

Sample parameters from an extended population which consists of all possible combinations of the given population

Parameters
  • population (Sequence) – population to build combination of

  • replacement (bool) – whether or not to sample with replacement

DiscreteParameter

class rising.random.discrete.DiscreteParameter(population, replacement=False, weights=None, cum_weights=None)[source][source]

Bases: rising.random.abstract.AbstractParameter

Samples parameters from a discrete population with or without replacement

Parameters
  • population (Sequence) – the parameter population to sample from

  • replacement (bool) – whether or not to sample with replacement

  • weights (Optional[Sequence]) – relative sampling weights

  • cum_weights (Optional[Sequence]) – cumulative sampling weights

sample(n_samples)[source][source]

Samples from the discrete internal population

Parameters

n_samples (int) – the number of elements to sample

Returns

the sampled values

Return type

list

DiscreteCombinationsParameter

class rising.random.discrete.DiscreteCombinationsParameter(population, replacement=False)[source][source]

Bases: rising.random.discrete.DiscreteParameter

Sample parameters from an extended population which consists of all possible combinations of the given population

Parameters
  • population (Sequence) – population to build combination of

  • replacement (bool) – whether or not to sample with replacement

combinations_all

rising.random.discrete.combinations_all(data)[source][source]

Return all combinations of all length for given sequence

Parameters

data (Sequence) – sequence to get combinations of

Returns

all combinations

Return type

List


© Copyright Copyright (c) 2019-2020, Justus Schock, Michael Baumgartner.. Revision 2a580e9c.

Read the Docs v: latest
Versions
latest
stable
v0.2.0post0
v0.2.0
Downloads
pdf
html
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.