power1d.random

Functions and classes for generating 1D random fields. The randn1d function is similar to the numpy.random.randn function but the former generates smooth (correlated) 1D Gaussian fields and the latter generates rough (uncorrelated) fields.

If a large number of random fields are required (e.g. for validation simulations) it may be more efficient to use the Generator1D class.

THIS FILE IS COPIED DIRECLY FROM THE rft1d SOFTWARE PACKAGE. SEE THE ORIGINAL DOCUMENTATION FOR MORE DETAILS:

http://www.spm1d.org/rft1d

Reference:

Pataky TC (2016) RFT1D: Smooth One-Dimensional Random Field Upcrossing Probabilities in Python. Journal of Statistical Software 71(7), 1-22. http://doi.org/10.18637/jss.v071.i07

randn1d

power1d.random.randn1d(nResponses, nodes, FWHM=10.0, pad=False)

Generate smooth Gaussian random fields.

Parameters:

nResponses – number of fields (int)

nodes – number of field nodes (int) OR a binary field (boolean array)

FWHM – field smoothness (float)

pad – pad prior to smoothing (bool)

Returns:

A 2D numpy array with shape: (nResponses, nodes)

Examples:
>>> y = power1d.random.randn1d(8, 101, 15.0)
>>> y = power1d.random.randn1d(1000, 101, 75.0, pad=True)

Warning

Padding is slow but necessary when (2 x FWHM) is greater than the number of nodes

Generator1D

class power1d.random.Generator1D(nResponses=1, nodes=101, FWHM=10, pad=False)

Generator of smooth Gaussian random fields.

Parameters:

nResponses – number of fields (int)

nodes – number of field nodes (int) OR a binary field (boolean array)

FWHM – field smoothness (float)

pad – pad prior to smoothing (bool)

Returns:

A Generator1D object

Notes:
  1. Generator1D is faster than randn1d for iteratively generating many random samples.

Examples:
>>> g = power1d.random.Generator1D(8, 101, 15.0)
>>> y = g.generate_sample()