Simulations

Independence Simulations

mgc.sims.linear(n, p, noise=False, low=-1, high=1)[source]

Simulates univariate or multivariate linear data.

Parameters:

n : int

The number of samples desired by the simulation.

p : int

The number of dimensions desired by the simulation.

noise : float, (default: 1)

The noise amplitude of the simulation.

low : float, (default: -1)

The lower limit of the uniform distribution simulated from.

high : float, (default: -1)

The upper limit of the uniform distribution simulated from.

Returns:

x, y : ndarray

Simulated data matrices. x and y have shapes (n, p) and (n, 1) where n is the number of samples and p is the number of dimensions.

Notes

Linear \((X, Y) \in \mathbb{R}^p \times \mathbb{R}\):

\[\begin{split}X &\sim \mathcal{U}(-1, 1)^p \\ Y &= w^T X + \kappa \epsilon\end{split}\]

Examples

>>> from mgc.sims import linear
>>> x, y = linear(100, 2)
>>> print(x.shape, y.shape)
(100, 2) (100, 1)
mgc.sims.exponential(n, p, noise=False, low=0, high=3)[source]

Simulates univariate or multivariate exponential data.

Parameters:

n : int

The number of samples desired by the simulation.

p : int

The number of dimensions desired by the simulation.

noise : float, (default: 10)

The noise amplitude of the simulation.

low : float, (default: 0)

The lower limit of the uniform distribution simulated from.

high : float, (default: 3)

The upper limit of the uniform distribution simulated from.

Returns:

x, y : ndarray

Simulated data matrices. x and y have shapes (n, p) and (n, 1) where n is the number of samples and p is the number of dimensions.

Notes

Exponential \((X, Y) \in \mathbb{R}^p \times \mathbb{R}\):

\[\begin{split}X &\sim \mathcal{U}(0, 3)^p \\ Y &= \exp (w^T X) + 10 \kappa \epsilon\end{split}\]

Examples

>>> from mgc.sims import exponential
>>> x, y = exponential(100, 2)
>>> print(x.shape, y.shape)
(100, 2) (100, 1)
mgc.sims.cubic(n, p, noise=False, low=-1, high=1, cubs=[-12, 48, 128], scale=0.3333333333333333)[source]

Simulates univariate or multivariate cubic data.

Parameters:

n : int

The number of samples desired by the simulation.

p : int

The number of dimensions desired by the simulation.

noise : float, (default: 80)

The noise amplitude of the simulation.

low : float, (default: -1)

The lower limit of the uniform distribution simulated from.

high : float, (default: -1)

The upper limit of the uniform distribution simulated from.

cubs : list of ints (default: [-12, 48, 128])

Coefficients of the cubic function where each value corresponds to the order of the cubic polynomial.

scale : float (default: 1/3)

Scaling center of the cubic.

Returns:

x, y : ndarray

Simulated data matrices. x and y have shapes (n, p) and (n, 1) where n is the number of samples and p is the number of dimensions.

Notes

Cubic \((X, Y) \in \mathbb{R}^p \times \mathbb{R}\):

\[\begin{split}X &\sim \mathcal{U}(-1, 1)^p \\ Y &= 128 \left( w^T X - \frac{1}{3} \right)^3 + 48 \left( w^T X - \frac{1}{3} \right)^2 - 12 \left( w^T X - \frac{1}{3} \right) + 80 \kappa \epsilon\end{split}\]

Examples

>>> from mgc.sims import cubic
>>> x, y = cubic(100, 2)
>>> print(x.shape, y.shape)
(100, 2) (100, 1)
mgc.sims.spiral(n, p, noise=False, low=0, high=5)[source]

Simulates univariate or multivariate spiral data.

Parameters:

n : int

The number of samples desired by the simulation.

p : int

The number of dimensions desired by the simulation.

noise : int, (default: 0.4)

The noise amplitude of the simulation.

low : float, (default: 0)

The lower limit of the uniform distribution simulated from.

high : float, (default: 5)

The upper limit of the uniform distribution simulated from.

Returns:

x, y : ndarray

Simulated data matrices. x and y have shapes (n, p) and (n, 1) where n is the number of samples and p is the number of dimensions.

Notes

Spiral \((X, Y) \in \mathbb{R}^p \times \mathbb{R}\): For \(U \sim \mathcal{U}(0, 5)\), \(\epsilon \sim \mathcal{N}(0, 1)\)

\[\begin{split}X_{|d|} &= U \sin(\pi U) \cos^d(\pi U)\ \mathrm{for}\ d = 1,...,p-1 \\ X_{|p|} &= U \cos^p(\pi U) \\ Y &= U \sin(\pi U) + 0.4 p \epsilon\end{split}\]

Examples

>>> from mgc.sims import spiral
>>> x, y = spiral(100, 2)
>>> print(x.shape, y.shape)
(100, 2) (100, 1)