Random Object Arrays

NSNFactory

class pynsn.NSNFactory(target_area_radius, min_dist_between=None, min_dist_area_boarder=None)

Bases: ArrayParameter

create_incremental_random_array(n_objects, allow_overlapping=False)
Parameters
  • n_objects

  • allow_overlapping

Returns

rtn

Return type

iterator of object _arrays

create_random_array(n_objects, allow_overlapping=False, occupied_space=None)

occupied_space is a dot array (used for multicolour dot array (join after)

attribute is an array, _arrays are assigned randomly.

Parameters
Returns

rtn

Return type

object array

sample(n, round_to_decimals=None)

return list objects (Dot or Rect) with random size all positions = (0,0)

Random distributions

Each distribution class below is a child of PyNSNDistribution and has the following class members:

class pynsn.distributions.PyNSNDistribution(min_max)
as_dict()

Dict representation of the distribution

pyplot_samples(n=100000)

Creating a visualization of the distribution with matplotlib.pyplot

Parameters

n – number of sample (optional)

Returns

pyplot.figure()

Raises

ImportError – if matplotlib is not installed

sample(n, round_to_decimals=False)

Random sample from the distribution

Parameters
  • n – number of samples

  • round_to_decimals – Set to round samples. If 0 a array of integer will be return

Returns

Numpy array of the sample

Categorical variables

class pynsn.distributions.Levels(levels, weights=None, exact_weighting=False)

Continuous variables

class pynsn.distributions.Uniform(min_max)
class pynsn.distributions.Normal(mu, sigma, min_max=None)
class pynsn.distributions.Triangle(mode, min_max)
class pynsn.distributions.Beta(mu=None, sigma=None, alpha=None, beta=None, min_max=None)
sample(n, round_to_decimals=None)

Random sample from the distribution

Parameters
  • n – number of samples

  • round_to_decimals – Set to round samples. If 0 a array of integer will be return

Returns

Numpy array of the sample

property shape_parameter

Alpha (p) & beta (q) parameter for the beta distribution http://www.itl.nist.gov/div898/handbook/eda/section3/eda366h.htm

Returns

parameter – shape parameter (alpha, beta) of the distribution

Return type

tuple

Multivariate distribution

class pynsn.distributions.Normal2D(mu, sigma, correlation, max_radius=None)
as_dict()

Dict representation of the distribution

sample(n, round_to_decimals=None)

Random sample from the distribution

Parameters
  • n – number of samples

  • round_to_decimals – Set to round samples. If 0 a array of integer will be return

Returns

Numpy array of the sample

varcov()

Variance covariance matrix

Init Random Generator

pynsn.init_random_generator(seed=None)

Init random generator and set random seed (optional)

Parameters

seed (seed value) – must be none, int or array_like[ints]

Notes

see documentation of numpy.random.default_rng() of Python standard library