Skip to content
An Econ-ARK project

Shock distributions

Summary

A line such as y ~ LogNormal(μ_y, σ_y) declares the probability distribution of a shock, of a tuple of shocks jointly, or of each component of a collection of shocks, by one of eleven families. This page lists the families, with the arguments each takes and what they mean, links each to the object of the Bellman calculus a declaration denotes, and names the table of the package the row is read from. A declared distribution is what an expectation integrates against and what a forward builder extends a measure by.

Relationship with other documents

Formal account — Appendix E.3 Operators §4: the conditional distribution of a shock, a probability kernel, and the two operators that read it. Builds on — Stage tutorial §2: where a distribution is declared in a stage file. See also — Operations: the Expectation and DistributionExtension rows that read a declared distribution; Refusals: the smallest example of each rule a declaration can be refused under.

1 Reading a declaration

A declaration writes the shock on the left of ~ and a call of a family on the right. The shock's set is declared on its own line, y : ℝ₊₊, and the declaration gives the distribution of the shock over that set: the set says which values the shock can take, and the distribution how probability is spread over them.

A tuple subject declares one joint distribution of its shocks, (y, z) ~ N((μ_y, μ_z), ((σ_y^2, r), (r, σ_z^2))). An argument may name a parameter; a state or a control at the source perch of the shock's edge, where an edge is the step from one perch to the next that one forward builder makes; or another shock, called a parent of the declaration. The declaration is then the distribution of the shock conditional on those arguments, a probability kernel: a distribution for each value the arguments take. Ψ ~ LogNormal(ν, σ_Ψ) in sa_savings.bl is conditional on the shock ν, and y_n ~ MarkovChain(P_y, y_grid, y_wa) in worker_ageing.bl on last period's ability y_wa.

A shock is drawn on the edge of one forward builder: the builder whose block lists the shock among its inputs, or else the edge of a shock declared with it or of a shock whose declaration reads it. The declarations drawn on one edge form one joint distribution, the product of their conditional distributions, each given its parents and the states and controls it reads. Two declarations that do not name one another are therefore conditionally independent given those states and controls; stage.obligations() lists that product as the assumption joint-distribution-factorization. On the card a builder prints (Operations §1), the distribution of ψ prints as P_ψ: an expectation integrates against it, E_{ψ}[…], and a distribution extension extends a measure by it, μ≺⊗P_ψ.

A declaration of one real shock by N, LogNormal, Uniform, TruncatedNormal, TruncatedLogNormal or TypeIExtremeValue, the scalar families whose definition the package's table of definitions holds (the column definition of §2), denotes two objects: the law as written, the family applied to the written arguments, and the measure at those arguments, the family's definition with the written arguments in place of its variables. The card that stage.definitions.denote prints for the declaration gives the second on the row under the first, so that y ~ Uniform(a_y, b_y) has the row P_y = measure on ℝ given by B ↦ ∫_{x ∈ {x ∈ ℝ | x ∈ B ∧ a_y ≤ x ∧ x ≤ b_y}} [1/(b_y − a_y)] Lebesgue(dx): the probability of a set B is the length of the part of B in [a_y, b_y], divided by b_y − a_y. A Mixture, a declaration of a tuple subject and a declaration by any other family denote the law as written alone.

A shock may be declared on the functions from a finite index set to the reals, ε : I_J → ℝ with I_J := {0, …, J} (Symbols and conventions), so that ε has one real component ε[i] for each member i of I_J. A call of LogNormal, Uniform, TruncatedNormal, TruncatedLogNormal or TypeIExtremeValue with real arguments is then the law of each component, and the declaration denotes the finite product of that law over the index set, printed ⊗_{i ∈ I_J} TypeIExtremeValue(0, 1) for ε ~ TypeIExtremeValue(0, 1); its measure, the second object, is the product of the scalar measures. The product of probability measures P_i on ℝ, one for each i in I_J, is the probability measure on the functions e from I_J to ℝ that gives the set of the functions with e(i) in B_i for every i the probability P_0(B_0) · P_1(B_1) · … · P_J(B_J). The components are therefore independent draws of one law, not copies of one draw, conditionally on the arguments the law reads, such as a parent shock η in ε ~ TypeIExtremeValue(η, 1), and the sentence of joint-distribution-factorization states it: the components of ε are independent, each with the law TypeIExtremeValue(0, 1), or conditionally independent given η for the law with the parent. N on such a shock is the joint normal law of its components, written ε ~ N(μ_ε, Σ_ε) with a mean μ_ε : I_J → ℝ and a covariance matrix Σ_ε : I_J × I_J → ℝ; it is not a product, and it denotes the law as written alone, as a Mixture on such a shock does.

The second argument

N(μ, v) takes the variance, not the standard deviation: sa_savings.bl writes ν ~ N(κ_1, σ_ν^2). LogNormal(μ, σ) takes the mean and the standard deviation of the logarithm of the draw, so μ is not the mean of the draw: buffer_stock.bl writes ψ ~ LogNormal(-(σ_ψ^2)/2, σ_ψ), whose mean is one. TruncatedNormal(μ, σ, l, u) takes the mean and the standard deviation of the normal law before the truncation to [l, u], so that σ is a standard deviation, not a variance as in N, and neither μ nor σ is the mean or the standard deviation of the draw. TruncatedLogNormal(μ, σ, l, u) takes the mean and the standard deviation of the logarithm, as LogNormal does, and its two endpoints in the draw's own units, so that TruncatedLogNormal(μ, σ, 0, inf) is LogNormal(μ, σ) and a bound stated as k standard deviations of the logarithm is written exp(μ + k·σ). TypeIExtremeValue(μ, s) takes a location and a scale, and the mean of the draw is μ + γs, γ ≈ 0.5772 being Euler's constant. A numerical routine written in another convention needs its arguments converted.

1.1 Laws with local arguments

The declaration y(_age) ~ LogNormal(μ_tab[_age], σ_y) gives the shock a local argument. The right side may also call a declared function, as in LogNormal(μ_fn(_age), σ_y). Leading underscores are allowed in the law's argument names and their occurrences within the right side.

List y and the incoming constant in the forward header and write y(age) or y[age] on that edge. The constant's declared set types _age and must fit the table's index set. Before an edge supplies the field, the formal domain remains unresolved and a table entry still requires membership of the key in the table's index set. Each shock uses one ordered list of constant arguments on the edge. Repeating the same arguments reads the same draw. The forward measure and E_{y} use the same applied law.

The builder's numerical record substitutes supplied constants and bound parameters into the declared law. Its detached DistributionDeclaration can still use coordinates such as a parent shock. Pass those values to bellman.distributions.families.specialize_distribution(declaration, values) to specialize the law and check the family parameters those values determine.

2 The families

The table has one row for each family of the package's table of families, FAMILY_ARGUMENTS in distributions/families.py, in that table's order. The column law names the family, and written gives its calls as the module docstring of distributions/families.py spells them. arguments gives how many arguments the family takes and what they are, and meaning gives the distribution a declaration gives, in the words of the same docstring. definition gives, for the seven families the package's table of definitions defines, N for one shock, LogNormal, Uniform, TruncatedNormal, TruncatedLogNormal, TypeIExtremeValue and Mixture, the defining expression, the measure as a function of the arguments; the other rows hold a dash. denotes links to the section of Appendix E.3 that defines the conditional distribution of a shock and the expectation that integrates against it. read from names the module, the table and the key of the family's arguments and, for the six families the table of definitions defines, of its definition.

law written arguments meaning definition denotes read from
N N(μ, v)
N((μ₁, …), ((Σ₁₁, …), …))
2 arguments: a mean and a variance, or for a tuple subject a mean vector and a covariance matrix N(μ, v) has variance v; a tuple subject N((μ₁, …), ((Σ₁₁, …), …)) has covariance matrix Σ (m, v) ↦ measure on ℝ given by B ↦ ∫_{z ∈ {z ∈ ℝ | m + v^(1/2) · z ∈ B}} [exp(−z²/2)/(2 · pi)^(1/2)] Lebesgue(dz) E.3 §4 Constituent operations distributions/families.py, FAMILY_ARGUMENTS, "N"
typing/primitive_definitions.py, PRIMITIVE_DEFINITIONS["definitions"], "N"
LogNormal LogNormal(μ, σ) 2 arguments: a location and a scale, the mean and the standard deviation of the logarithm LogNormal(μ, σ) has σ the standard deviation of the logarithm (m, s) ↦ measure on (0, ∞) given by B ↦ ∫_{z ∈ {z ∈ ℝ | exp(m + s · z) ∈ B}} [exp(−z²/2)/(2 · pi)^(1/2)] Lebesgue(dz) E.3 §4 Constituent operations distributions/families.py, FAMILY_ARGUMENTS, "LogNormal"
typing/primitive_definitions.py, PRIMITIVE_DEFINITIONS["definitions"], "LogNormal"
Uniform Uniform(a, b) 2 arguments: the two endpoints of the interval, finite and in order, a < b Uniform(a, b) is the uniform law on the interval [a, b], with a < b finite (a, b) ↦ measure on ℝ given by B ↦ ∫_{x ∈ {x ∈ ℝ | x ∈ B ∧ a ≤ x ∧ x ≤ b}} [1/(b − a)] Lebesgue(dx) E.3 §4 Constituent operations distributions/families.py, FAMILY_ARGUMENTS, "Uniform"
typing/primitive_definitions.py, PRIMITIVE_DEFINITIONS["definitions"], "Uniform"
TruncatedNormal TruncatedNormal(μ, σ, l, u) 4 arguments: the mean and the standard deviation of the underlying normal and the two endpoints of the truncation interval, l < u, with -inf and inf admitted TruncatedNormal(μ, σ, l, u) is the normal law of mean μ and standard deviation σ > 0 conditional on the interval [l, u], with extended-real endpoints l < u, -inf and inf admitted (m, s, l, u) ↦ measure on ℝ given by B ↦ ∫_{z ∈ {z ∈ ℝ | m + s · z ∈ B ∧ l ≤ m + s · z ∧ m + s · z ≤ u}} [exp(−z²/2)/(2 · pi)^(1/2)] Lebesgue(dz)/∫_{z ∈ {z ∈ ℝ | l ≤ m + s · z ∧ m + s · z ≤ u}} [exp(−z²/2)/(2 · pi)^(1/2)] Lebesgue(dz) E.3 §4 Constituent operations distributions/families.py, FAMILY_ARGUMENTS, "TruncatedNormal"
typing/primitive_definitions.py, PRIMITIVE_DEFINITIONS["definitions"], "TruncatedNormal"
TruncatedLogNormal TruncatedLogNormal(μ, σ, l, u) 4 arguments: the mean and the standard deviation of the logarithm and the two endpoints of the truncation interval in the draw's own units, 0 ≤ l < u, with 0 and inf admitted TruncatedLogNormal(μ, σ, l, u) is the lognormal law whose logarithm has mean μ and standard deviation σ > 0, conditional on the interval [l, u] of the draw itself, with endpoints 0 ≤ l < u, 0 and inf admitted (m, s, l, u) ↦ measure on (0, ∞) given by B ↦ ∫_{z ∈ {z ∈ ℝ | exp(m + s · z) ∈ B ∧ l ≤ exp(m + s · z) ∧ exp(m + s · z) ≤ u}} [exp(−z²/2)/(2 · pi)^(1/2)] Lebesgue(dz)/∫_{z ∈ {z ∈ ℝ | l ≤ exp(m + s · z) ∧ exp(m + s · z) ≤ u}} [exp(−z²/2)/(2 · pi)^(1/2)] Lebesgue(dz) E.3 §4 Constituent operations distributions/families.py, FAMILY_ARGUMENTS, "TruncatedLogNormal"
typing/primitive_definitions.py, PRIMITIVE_DEFINITIONS["definitions"], "TruncatedLogNormal"
TypeIExtremeValue TypeIExtremeValue(μ, s) 2 arguments: a location and a scale, the scale positive TypeIExtremeValue(μ, s) is the maximum type-I extreme-value law with location μ and scale s > 0, whose cumulative distribution is exp(−exp(−(x − μ)/s)) (m, s) ↦ measure on ℝ given by B ↦ ∫_{z ∈ {z ∈ ℝ | m + s · z ∈ B}} [exp(−z − exp(−z))] Lebesgue(dz) E.3 §4 Constituent operations distributions/families.py, FAMILY_ARGUMENTS, "TypeIExtremeValue"
typing/primitive_definitions.py, PRIMITIVE_DEFINITIONS["definitions"], "TypeIExtremeValue"
DiscreteMarkov DiscreteMarkov(Π, points)
DiscreteMarkov(Π, points, z_pre)
2 or 3 arguments: the transition probabilities, written as a matrix, named or a tuple of rows, or as the one row the previous state selects; the chain's states, written as a tuple of points, a named vector, a set or a tuple of the subjects' sets; and, where a third is written, the previous state, a field of the stage on whose value the draw is conditioned DiscreteMarkov(Π, points) and MarkovChain(Π, points) draw the subject from the chain with transition probabilities Π over points, and with a third argument, DiscreteMarkov(Π, points, z_pre), from the row of Π that the previous state z_pre selects, so that the declaration denotes a stochastic kernel in that field — E.3 §4 Constituent operations distributions/families.py, FAMILY_ARGUMENTS, "DiscreteMarkov"
MarkovChain MarkovChain(Π, points) 2 or 3 arguments: the transition probabilities, written as a matrix, named or a tuple of rows, or as the one row the previous state selects; the chain's states, written as a tuple of points, a named vector, a set or a tuple of the subjects' sets; and, where a third is written, the previous state, a field of the stage on whose value the draw is conditioned DiscreteMarkov(Π, points) and MarkovChain(Π, points) draw the subject from the chain with transition probabilities Π over points, and with a third argument, DiscreteMarkov(Π, points, z_pre), from the row of Π that the previous state z_pre selects, so that the declaration denotes a stochastic kernel in that field — E.3 §4 Constituent operations distributions/families.py, FAMILY_ARGUMENTS, "MarkovChain"
Mixture Mixture((f₁, J₁), …) 2 or more arguments: one pair of a weight and a component for each component Mixture((f₁, J₁), …) draws the component Jᵢ with probability fᵢ (p, nu) ↦ measure on Z given by B ↦ ∫_{i ∈ {i ∈ [0, ∞) | i ∈ ℤ ∧ i < n}} [p(i) · nu(i)(B)] counting({i ∈ [0, ∞) | i ∈ ℤ ∧ i < n})(di) E.3 §4 Constituent operations distributions/families.py, FAMILY_ARGUMENTS, "Mixture"
typing/primitive_definitions.py, PRIMITIVE_DEFINITIONS["definitions"], "Mixture"
Categorical Categorical((f₁, …)) 1 argument: the weights, written as a tuple, as the rows of a matrix or as the one row a previous state selects Categorical((f₁, …)) draws the label in position i of its subject's declared finite set with probability fᵢ — E.3 §4 Constituent operations distributions/families.py, FAMILY_ARGUMENTS, "Categorical"
Bernoulli Bernoulli(p) 1 argument: one probability Bernoulli(p) draws the second of two points with probability p — E.3 §4 Constituent operations distributions/families.py, FAMILY_ARGUMENTS, "Bernoulli"

3 Conditions and refusals

A call of a family with a number of arguments the family does not take is refused under readable-form. An argument outside its family's domain is refused under distribution-domain: a negative variance, a negative standard deviation of the logarithm, weights outside the unit interval or not summing to one, a probability of Bernoulli outside [0, 1], and a mean or a covariance matrix that does not have the subject's dimension or a covariance matrix that is not symmetric positive semidefinite. A zero variance and a zero standard deviation of the logarithm lie in the domain: N(μ, 0) is a point mass at μ, and LogNormal(μ, 0) a point mass at exp(μ). A component of a Mixture written as a number is a point mass at that number, as the 0 of ξ ~ Mixture((p_zero, 0), (1 - p_zero, LogNormal(μ_ξ, σ_ξ))) in buffer_stock.bl.

The arguments of Uniform, TruncatedNormal, TruncatedLogNormal and TypeIExtremeValue are real numbers, and the same rule refuses each of the following:

  • endpoints that are not in order, Uniform(1, 0), Uniform(1, 1) or TruncatedNormal(0, 1, 2, 2);
  • a standard deviation or a scale that is not positive, TruncatedNormal(0, 0, -1, 1), TruncatedLogNormal(0, 0, 0, inf) or TypeIExtremeValue(0, 0);
  • a negative lower endpoint of a truncated lognormal, TruncatedLogNormal(0, 1, -1, 1), since the draw is positive: TruncatedLogNormal(0, 1, 0, inf) is LogNormal(0, 1) itself, and TruncatedLogNormal(0, 1, 0.5, 2) the lognormal law conditional on [0.5, 2];
  • an infinite argument other than an endpoint of a truncation: Uniform(0, inf) is refused, whereas TruncatedNormal(0, 1, 0, inf) is the normal law truncated to the nonnegative half-line and TruncatedNormal(0, 1, -inf, inf) the normal law itself;
  • an argument whose names all have values and whose arithmetic has no number, 0/0, or is not a number, inf - inf;
  • a tuple written as an argument, Uniform((0, 1), 2), and an argument that reads a parameter declared on a collection, μ : I_J → ℝ, or on a product set, b : ℝ × ℝ;
  • a tuple subject, (y, z) ~ Uniform(0, 1), since each of the three is the law of one real subject or of each component of a collection.

Every component of a Mixture that is a call of N, LogNormal or one of the four families is checked as a declaration of that family would be, and a refusal names the component: Mixture((0.5, 0), (0.5, N(0, -1))) is refused for the negative variance of its N component. A refusal under distribution-domain names the declaration's line of the file.

Where an argument names a parameter, the condition is decided when the calibration gives the number, and a calibration whose values break it is refused under distribution-domain. In the meantime three conditions stand among stage.obligations(): the condition on weights as distribution-weights-are-a-probability-vector, the condition on the covariance matrix of a tuple subject as covariance-positive-semidefinite, and the condition on the parameters of Uniform, TruncatedNormal, TruncatedLogNormal and TypeIExtremeValue, of a declaration or of a component of a mixture, as distribution-parameters-in-domain. The sentence of distribution-parameters-in-domain states the family's condition in the written terms, the parameters of the Uniform declaration two_nodes:distribution:y of y lie in the family's domain: a < b, with a = a_y and b = b_y, both finite. An argument that is a call, Uniform(exp(1), 3), or any other term outside the arithmetic of numbers and parameters the package evaluates, or that reads a state, a control or a parent shock, TypeIExtremeValue(0, z), keeps its condition as the obligation distribution-parameters-in-domain, which no calibration decides.

Every declaration also records the condition law-support: the distribution gives probability only to values in the shock's declared set. The package decides it at calibration where it knows the law's support and reads the bounds of the declared set: a truncated lognormal's support is [l, u], open at a lower endpoint 0 and at an upper endpoint inf, and calibrate establishes the condition when that interval lies within the declared set and refuses the calibration when it does not. For every other family the condition stays required and unchecked, so a normal distribution declared for a shock in ℝ₊₊ is not refused; a strictly positive shock takes a family whose draws are positive, such as LogNormal, or a mixture of such families with positive numbers. The numerical routine that provides a distribution to a solver is no condition of the stage: a solver reads one where a methods file names it and chooses its own otherwise.

The distribution of a shock whose labels select the branches of a block gives one probability to each label, written Categorical((p₁, …, pₙ)) in the order of the labels or Bernoulli(p) on two; any other is refused under branch-law. An expectation that needs a conditional distribution the declarations do not give, a posterior among them, is refused under conditional-not-declared.

A call of a family outside the table is not refused when the file is read: the declaration is kept as the file writes it, as the author's own distribution. The backward builders graph is constructed, but the forward builders graph is not: stage.builder.fwd holds a refusal under not-constructed, since a forward builder extends a measure only by the families of the table.