HARK.simulation¶
Functions for generating simulated data and shocks.
Functions
drawBernoulli (N[, p, seed]) |
Generates arrays of booleans drawn from a simple Bernoulli distribution. |
drawDiscrete (N[, P, X, exact_match, seed]) |
Simulates N draws from a discrete distribution with probabilities P and outcomes X. |
drawLognormal (N[, mu, sigma, seed]) |
Generate arrays of mean one lognormal draws. |
drawMeanOneLognormal (N[, sigma, seed]) |
Generate arrays of mean one lognormal draws. |
drawNormal (N[, mu, sigma, seed]) |
Generate arrays of normal draws. |
drawUniform (N[, bot, top, seed]) |
Generate arrays of uniform draws. |
drawWeibull (N[, scale, shape, seed]) |
Generate arrays of Weibull draws. |
main () |
-
HARK.simulation.
drawBernoulli
(N, p=0.5, seed=0)¶ Generates arrays of booleans drawn from a simple Bernoulli distribution. The input p can be a float or a list-like of floats; its length T determines the number of entries in the output. The t-th entry of the output is an array of N booleans which are True with probability p[t] and False otherwise.
Returns: - draws : np.array or [np.array]
T-length list of arrays of Bernoulli draws each of size N, or a single array of size N (if sigma is a scalar).
-
HARK.simulation.
drawDiscrete
(N, P=[1.0], X=[0.0], exact_match=False, seed=0)¶ Simulates N draws from a discrete distribution with probabilities P and outcomes X.
Parameters: - P : np.array
A list of probabilities of outcomes.
- X : np.array
A list of discrete outcomes.
- N : int
Number of draws to simulate.
- exact_match : boolean
Whether the draws should “exactly” match the discrete distribution (as closely as possible given finite draws). When True, returned draws are a random permutation of the N-length list that best fits the discrete distribution. When False (default), each draw is independent from the others and the result could deviate from the input.
- seed : int
Seed for random number generator.
Returns: - draws : np.array
An array draws from the discrete distribution; each element is a value in X.
-
HARK.simulation.
drawLognormal
(N, mu=0.0, sigma=1.0, seed=0)¶ Generate arrays of mean one lognormal draws. The sigma input can be a number or list-like. If a number, output is a length N array of draws from the lognormal distribution with standard deviation sigma. If a list, output is a length T list whose t-th entry is a length N array of draws from the lognormal with standard deviation sigma[t].
Parameters: - N : int
Number of draws in each row.
- mu : float or [float]
One or more means. Number of elements T in mu determines number of rows of output.
- sigma : float or [float]
One or more standard deviations. Number of elements T in sigma determines number of rows of output.
- seed : int
Seed for random number generator.
-
HARK.simulation.
drawMeanOneLognormal
(N, sigma=1.0, seed=0)¶ Generate arrays of mean one lognormal draws. The sigma input can be a number or list-like. If a number, output is a length N array of draws from the lognormal distribution with standard deviation sigma. If a list, output is a length T list whose t-th entry is a length N array of draws from the lognormal with standard deviation sigma[t].
Parameters: - N : int
Number of draws in each row.
- sigma : float or [float]
One or more standard deviations. Number of elements T in sigma determines number of rows of output.
- seed : int
Seed for random number generator.
-
HARK.simulation.
drawNormal
(N, mu=0.0, sigma=1.0, seed=0)¶ Generate arrays of normal draws. The mu and sigma inputs can be numbers or list-likes. If a number, output is a length N array of draws from the normal distribution with mean mu and standard deviation sigma. If a list, output is a length T list whose t-th entry is a length N array with draws from the normal distribution with mean mu[t] and standard deviation sigma[t].
Parameters: - N : int
Number of draws in each row.
- mu : float or [float]
One or more means. Number of elements T in mu determines number of rows of output.
- sigma : float or [float]
One or more standard deviations. Number of elements T in sigma determines number of rows of output.
- seed : int
Seed for random number generator.
Returns: - draws : np.array or [np.array]
T-length list of arrays of normal draws each of size N, or a single array of size N (if sigma is a scalar).
-
HARK.simulation.
drawUniform
(N, bot=0.0, top=1.0, seed=0)¶ Generate arrays of uniform draws. The bot and top inputs can be numbers or list-likes. If a number, output is a length N array of draws from the uniform distribution on [bot,top]. If a list, output is a length T list whose t-th entry is a length N array with draws from the uniform distribution on [bot[t],top[t]].
Parameters: - N : int
Number of draws in each row.
- bot : float or [float]
One or more bottom values. Number of elements T in mu determines number of rows of output.
- top : float or [float]
One or more top values. Number of elements T in top determines number of rows of output.
- seed : int
Seed for random number generator.
Returns: - draws : np.array or [np.array]
T-length list of arrays of uniform draws each of size N, or a single array of size N (if sigma is a scalar).
-
HARK.simulation.
drawWeibull
(N, scale=1.0, shape=1.0, seed=0)¶ Generate arrays of Weibull draws. The scale and shape inputs can be numbers or list-likes. If a number, output is a length N array of draws from the Weibull distribution with the given scale and shape. If a list, output is a length T list whose t-th entry is a length N array with draws from the Weibull distribution with scale scale[t] and shape shape[t].
Note: When shape=1, the Weibull distribution is simply the exponential dist.
Mean: scale*Gamma(1 + 1/shape)
Parameters: - N : int
Number of draws in each row.
- scale : float or [float]
One or more scales. Number of elements T in scale determines number of rows of output.
- shape : float or [float]
One or more shape parameters. Number of elements T in scale determines number of rows of output.
- seed : int
Seed for random number generator.