Skip to content

Commit

Permalink
distribution to distributions
Browse files Browse the repository at this point in the history
  • Loading branch information
alanlujan91 committed Nov 7, 2024
1 parent 470a9bc commit 235d3ce
Show file tree
Hide file tree
Showing 47 changed files with 7,266 additions and 7,266 deletions.
8 changes: 3 additions & 5 deletions Documentation/overview/ARKitecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ from HARK.rewards import CRRAutility
CRRAutility(1, 2)
```

Python modules in HARK can generally be categorized into two types: tools and models. **Tool modules** contain functions and classes with general purpose tools that have no inherent ''economic content'', but that can be used in many economic models as building blocks or utilities; they could plausibly be useful in non-economic settings. Tools might include functions for data analysis (e.g. calculating Lorenz shares from data, or constructing a non-parametric kernel regression), functions to create and manipulate discrete approximations to continuous distributions, or classes for constructing interpolated approximations to non-parametric functions. The most commonly used tool modules reside in HARK's root directory and have names like **_HARK.distribution_** and **_HARK.interpolation_**.
Python modules in HARK can generally be categorized into two types: tools and models. **Tool modules** contain functions and classes with general purpose tools that have no inherent ''economic content'', but that can be used in many economic models as building blocks or utilities; they could plausibly be useful in non-economic settings. Tools might include functions for data analysis (e.g. calculating Lorenz shares from data, or constructing a non-parametric kernel regression), functions to create and manipulate discrete approximations to continuous distributions, or classes for constructing interpolated approximations to non-parametric functions. The most commonly used tool modules reside in HARK's root directory and have names like **_HARK.distributions_** and **_HARK.interpolation_**.

**Model modules** specify particular economic models, including classes to represent agents in the model (and the ''market structure'' in which they interact) and functions for solving the ''one period problem'' of those models. For example, **ConsIndShockModel.py** concerns consumption-saving models in which agents have CRRA utility over consumption and face idiosyncratic shocks to permanent and transitory income. The module includes classes for representing ''types'' of consumers, along with functions for solving (several flavors of) the one period consumption-saving problem. Model modules generally have **_Model_** in their name, and the classes for representing agents all have **_Type_** at the end of their name (as instances represent a collection of ex ante homogeneous agents who share common model and parameters-- a "type"). For example, **_HARK.ConsumptionSaving.ConsIndShockModel_** includes the class **_IndShockConsumerType_**.


## HARK

After you [installed](https://docs.econ-ark.org/Documentation/guides/installation.html) or [cloned the repository of](https://github.com/econ-ark/HARK) HARK, you can explore the content of it. In the subfolder HARK, you can find a range of [general purpose tools](#general-purpose-tools), as well as the next subfolder ConsumptionSaving which has [AgentType subclasses](#agenttype-class) and [Market subclasses](#market-class).
Expand All @@ -59,9 +58,9 @@ Macroeconomic models in HARK use the **_Market_** class to represent a market (o

The **_HARK.utilities_** module contains a variety of general purpose tools, including some data manipulation tools (e.g. for calculating an average of data conditional on being within a percentile range of different data), basic kernel regression tools, convenience functions for retrieving information about functions, and basic plotting tools using **_matplotlib.pyplot_**. See [here](https://docs.econ-ark.org/Documentation/reference/tools/utilities.html) for further documentation.

#### HARK.distribution
#### HARK.distributions

The **_HARK.distribution_** module includes classes for representing continuous distributions in a relatively consistent framework. Critically for numeric purposes, it also has methods and functions for constructing discrete approximations to those distributions (e.g. **_approx\_lognormal()_** to approximate a log-normal distribution) as well as manipulating these representations (e.g. appending one outcome to an existing distribution, or combining independent univariate distributions into one multivariate distribution). As a convention in HARK, continuous distributions are approximated as finite discrete distributions when solving models. This both simplifies solution methods (reducing numeric integrals to simple dot products) and allows users to easily test whether their chosen degree of discretization yields a sufficient approximation to the full distribution. See [here](https://docs.econ-ark.org/Documentation/reference/tools/distribution.html) for further documentation.
The **_HARK.distributions_** module includes classes for representing continuous distributions in a relatively consistent framework. Critically for numeric purposes, it also has methods and functions for constructing discrete approximations to those distributions (e.g. **_approx\_lognormal()_** to approximate a log-normal distribution) as well as manipulating these representations (e.g. appending one outcome to an existing distribution, or combining independent univariate distributions into one multivariate distribution). As a convention in HARK, continuous distributions are approximated as finite discrete distributions when solving models. This both simplifies solution methods (reducing numeric integrals to simple dot products) and allows users to easily test whether their chosen degree of discretization yields a sufficient approximation to the full distribution. See [here](https://docs.econ-ark.org/Documentation/reference/tools/distribution.html) for further documentation.

#### HARK.interpolation

Expand Down Expand Up @@ -107,7 +106,6 @@ A discrete time model in our framework is characterized by a sequence of ''perio

An instance of **_AgentType_** also has the attributes named in **_time_vary_** and **_time_inv_**, and may have other attributes that are not included in either (e.g. values not used in the model solution, but instead to construct objects used in the solution). Note that **_time_vary_** may include attributes that are never used by a function in **_solveOnePeriod_**. Most saliently, the attribute **_solution_** is time-varying but is not used to solve individual periods.


#### A Universal Solver

When an instance of **_AgentType_** invokes its **_solve_** method, the solution to the agent's problem is stored in the attribute **_solution_**. The solution is computed by recursively solving the sequence of periods defined by the variables listed in **_time_vary_** and **_time_inv_** using the functions in **_solve\_one_period_**. The time-varying inputs are updated each period, including the successive period's solution as **_solution_next_**; the same values of time invariant inputs in **_time_inv_** are passed to the solver in every period. The first call to **_solve\_one\_period_** uses **_solution_terminal_** as **_solution_next_**. In an infinite horizon problem (**_cycles_=0**), the sequence of periods is solved until the solutions of successive cycles have a ''distance'' of less than **_tolerance_**. Usually, the "sequence" of periods in such models is just *one* period long.
Expand Down
2 changes: 1 addition & 1 deletion Documentation/reference/tools/distribution.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Distribution
-------------

.. automodule:: HARK.distribution
.. automodule:: HARK.distributions
:members:
:undoc-members:
:show-inheritance:
2 changes: 1 addition & 1 deletion HARK/Calibration/Assets/AssetProcesses.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import numpy as np
from scipy.optimize import minimize_scalar
from HARK.distribution import (
from HARK.distributions import (
combine_indep_dstns,
DiscreteDistributionLabeled,
IndexDistribution,
Expand Down
2 changes: 1 addition & 1 deletion HARK/Calibration/Income/IncomeProcesses.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import numpy as np
from HARK.metric import MetricObject
from HARK.distribution import (
from HARK.distributions import (
add_discrete_outcome_constant_mean,
combine_indep_dstns,
DiscreteDistribution,
Expand Down
2 changes: 1 addition & 1 deletion HARK/ConsumptionSaving/ConsAggShockModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
init_idiosyncratic_shocks,
)
from HARK.ConsumptionSaving.ConsMarkovModel import MarkovConsumerType
from HARK.distribution import (
from HARK.distributions import (
MarkovProcess,
MeanOneLogNormal,
Uniform,
Expand Down
2 changes: 1 addition & 1 deletion HARK/ConsumptionSaving/ConsBequestModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
make_portfolio_solution_terminal,
)
from HARK.ConsumptionSaving.ConsRiskyAssetModel import make_simple_ShareGrid
from HARK.distribution import expected
from HARK.distributions import expected
from HARK.interpolation import (
BilinearInterp,
ConstantFunction,
Expand Down
2 changes: 1 addition & 1 deletion HARK/ConsumptionSaving/ConsGenIncProcessModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
ConsumerSolution,
IndShockConsumerType,
)
from HARK.distribution import Lognormal, expected
from HARK.distributions import Lognormal, expected
from HARK.interpolation import (
BilinearInterp,
ConstantFunction,
Expand Down
2 changes: 1 addition & 1 deletion HARK/ConsumptionSaving/ConsIndShockModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from HARK.Calibration.SCF.WealthIncomeDist.SCFDistTools import (
income_wealth_dists_from_scf,
)
from HARK.distribution import (
from HARK.distributions import (
Lognormal,
MeanOneLogNormal,
Uniform,
Expand Down
2 changes: 1 addition & 1 deletion HARK/ConsumptionSaving/ConsLabeledModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
)
from HARK.ConsumptionSaving.LegacyOOsolvers import ConsIndShockSetup
from HARK.core import make_one_period_oo_solver
from HARK.distribution import DiscreteDistributionLabeled
from HARK.distributions import DiscreteDistributionLabeled
from HARK.metric import MetricObject
from HARK.rewards import UtilityFuncCRRA

Expand Down
2 changes: 1 addition & 1 deletion HARK/ConsumptionSaving/ConsMarkovModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
PerfForesightConsumerType,
make_basic_CRRA_solution_terminal,
)
from HARK.distribution import MarkovProcess, Uniform, expected
from HARK.distributions import MarkovProcess, Uniform, expected
from HARK.interpolation import (
CubicInterp,
LinearInterp,
Expand Down
2 changes: 1 addition & 1 deletion HARK/ConsumptionSaving/ConsMedModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
VariableLowerBoundFunc2D,
)
from HARK.ConsumptionSaving.ConsIndShockModel import ConsumerSolution
from HARK.distribution import Lognormal, add_discrete_outcome_constant_mean, expected
from HARK.distributions import Lognormal, add_discrete_outcome_constant_mean, expected
from HARK.interpolation import (
BilinearInterp,
BilinearInterpOnInterp1D,
Expand Down
2 changes: 1 addition & 1 deletion HARK/ConsumptionSaving/ConsPortfolioFrameModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
PortfolioConsumerType,
init_portfolio,
)
from HARK.distribution import (
from HARK.distributions import (
Bernoulli,
IndexDistribution,
Lognormal,
Expand Down
2 changes: 1 addition & 1 deletion HARK/ConsumptionSaving/ConsPortfolioModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
RiskyAssetConsumerType,
make_simple_ShareGrid,
)
from HARK.distribution import expected
from HARK.distributions import expected
from HARK.interpolation import (
BilinearInterp,
ConstantFunction,
Expand Down
2 changes: 1 addition & 1 deletion HARK/ConsumptionSaving/ConsPrefShockModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
get_PermShkDstn_from_IncShkDstn,
get_TranShkDstn_from_IncShkDstn,
)
from HARK.distribution import MeanOneLogNormal, expected
from HARK.distributions import MeanOneLogNormal, expected
from HARK.interpolation import (
CubicInterp,
LinearInterp,
Expand Down
2 changes: 1 addition & 1 deletion HARK/ConsumptionSaving/ConsRepAgentModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
make_basic_CRRA_solution_terminal,
)
from HARK.ConsumptionSaving.ConsMarkovModel import MarkovConsumerType
from HARK.distribution import MarkovProcess
from HARK.distributions import MarkovProcess
from HARK.interpolation import LinearInterp, MargValueFuncCRRA
from HARK.utilities import make_assets_grid

Expand Down
2 changes: 1 addition & 1 deletion HARK/ConsumptionSaving/ConsRiskyAssetModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
get_PermShkDstn_from_IncShkDstn,
get_TranShkDstn_from_IncShkDstn,
)
from HARK.distribution import (
from HARK.distributions import (
Bernoulli,
expected,
IndexDistribution,
Expand Down
2 changes: 1 addition & 1 deletion HARK/ConsumptionSaving/ConsRiskyContribModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
init_risky_asset,
IndShockRiskyAssetConsumerType_constructor_default,
)
from HARK.distribution import calc_expectation
from HARK.distributions import calc_expectation
from HARK.interpolation import BilinearInterp # 2D interpolator
from HARK.interpolation import (
ConstantFunction, # Interpolator-like class that returns constant value
Expand Down
2 changes: 1 addition & 1 deletion HARK/ConsumptionSaving/ConsWealthPortfolioModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
PortfolioSolution,
make_portfolio_solution_terminal,
)
from HARK.distribution import expected
from HARK.distributions import expected
from HARK.interpolation import (
BilinearInterp,
CubicInterp,
Expand Down
2 changes: 1 addition & 1 deletion HARK/ConsumptionSaving/LegacyOOsolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from dataclasses import dataclass
import numpy as np
from HARK import NullFunc
from HARK.distribution import expected, calc_expectation, DiscreteDistribution
from HARK.distributions import expected, calc_expectation, DiscreteDistribution
from HARK.interpolation import (
BilinearInterp,
BilinearInterpOnInterp1D,
Expand Down
2 changes: 1 addition & 1 deletion HARK/ConsumptionSaving/TractableBufferStockModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from scipy.optimize import brentq, newton

from HARK import AgentType, NullFunc
from HARK.distribution import Bernoulli, Lognormal
from HARK.distributions import Bernoulli, Lognormal
from HARK.interpolation import CubicInterp

# Import the HARK library.
Expand Down
2 changes: 1 addition & 1 deletion HARK/ConsumptionSaving/tests/test_ConsAggShockModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
KrusellSmithEconomy,
KrusellSmithType,
)
from HARK.distribution import Uniform
from HARK.distributions import Uniform
from HARK.tests import HARK_PRECISION


Expand Down
2 changes: 1 addition & 1 deletion HARK/ConsumptionSaving/tests/test_ConsMarkovModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
MarkovConsumerType,
init_indshk_markov,
)
from HARK.distribution import (
from HARK.distributions import (
DiscreteDistribution,
DiscreteDistributionLabeled,
MeanOneLogNormal,
Expand Down
2 changes: 1 addition & 1 deletion HARK/ConsumptionSaving/tests/test_SmallOpenEconomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
SmallOpenEconomy,
init_cobb_douglas,
)
from HARK.distribution import Uniform
from HARK.distributions import Uniform


class testSmallOpenEconomy(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion HARK/ConsumptionSaving/tests/test_modelcomparisons.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
)
from HARK.ConsumptionSaving.ConsMarkovModel import MarkovConsumerType
from HARK.ConsumptionSaving.TractableBufferStockModel import TractableConsumerType
from HARK.distribution import DiscreteDistributionLabeled
from HARK.distributions import DiscreteDistributionLabeled


class Compare_PerfectForesight_and_Infinite(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion HARK/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import numpy as np
import pandas as pd
from HARK.distribution import (
from HARK.distributions import (
Distribution,
IndexDistribution,
TimeVaryingDiscreteDistribution,
Expand Down
8 changes: 5 additions & 3 deletions HARK/distributions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
]

from HARK.distributions.base import (
DiscreteDistribution,
DiscreteDistributionLabeled,
Distribution,
IndexDistribution,
MarkovProcess,
Expand All @@ -39,7 +37,11 @@
Uniform,
Weibull,
)
from HARK.distributions.discrete import Bernoulli
from HARK.distributions.discrete import (
Bernoulli,
DiscreteDistribution,
DiscreteDistributionLabeled,
)
from HARK.distributions.multivariate import MVLogNormal, MVNormal
from HARK.distributions.utils import (
add_discrete_outcome_constant_mean,
Expand Down
2 changes: 1 addition & 1 deletion HARK/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np

from HARK import AgentType, Model
from HARK.distribution import Distribution
from HARK.distributions import Distribution


class Frame:
Expand Down
2 changes: 1 addition & 1 deletion HARK/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from dataclasses import dataclass, field, replace
from copy import copy, deepcopy
from HARK.distribution import (
from HARK.distributions import (
Distribution,
DiscreteDistributionLabeled,
combine_indep_dstns,
Expand Down
2 changes: 1 addition & 1 deletion HARK/models/consumer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from HARK.distribution import Bernoulli, Lognormal, MeanOneLogNormal
from HARK.distributions import Bernoulli, Lognormal, MeanOneLogNormal
from HARK.model import Control, DBlock, RBlock

"""
Expand Down
2 changes: 1 addition & 1 deletion HARK/models/perfect_foresight.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from HARK.distribution import Bernoulli
from HARK.distributions import Bernoulli
from HARK.model import Control, DBlock

# This way of distributing parameters across the scope is clunky
Expand Down
2 changes: 1 addition & 1 deletion HARK/models/perfect_foresight_normalized.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from HARK.distribution import Bernoulli
from HARK.distributions import Bernoulli
from HARK.model import Control, DBlock

# This way of distributing parameters across the scope is clunky
Expand Down
2 changes: 1 addition & 1 deletion HARK/models/test_models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from HARK.distribution import Lognormal
from HARK.distributions import Lognormal
import HARK.models.consumer as cons
import HARK.models.perfect_foresight as pfm
import HARK.models.perfect_foresight_normalized as pfnm
Expand Down
2 changes: 1 addition & 1 deletion HARK/parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from HARK.distribution import Bernoulli, Lognormal, MeanOneLogNormal
from HARK.distributions import Bernoulli, Lognormal, MeanOneLogNormal
from sympy.utilities.lambdify import lambdify
from sympy.parsing.sympy_parser import parse_expr
import yaml
Expand Down
2 changes: 1 addition & 1 deletion HARK/simulation/monte_carlo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import numpy as np

from HARK.distribution import (
from HARK.distributions import (
Distribution,
IndexDistribution,
TimeVaryingDiscreteDistribution,
Expand Down
2 changes: 1 addition & 1 deletion HARK/simulation/test_monte_carlo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import unittest

from HARK.distribution import Bernoulli, IndexDistribution, MeanOneLogNormal
from HARK.distributions import Bernoulli, IndexDistribution, MeanOneLogNormal
from HARK.model import Aggregate, Control, DBlock
from HARK.simulation.monte_carlo import *

Expand Down
2 changes: 1 addition & 1 deletion HARK/tests/test_approxDstns.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np

# Bring in modules we need
import HARK.distribution as distribution
import HARK.distributions as distribution


class testsForDCEGM(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion HARK/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
init_idiosyncratic_shocks,
)
from HARK.core import AgentPopulation, AgentType, Parameters, distribute_params
from HARK.distribution import Uniform
from HARK.distributions import Uniform
from HARK.metric import MetricObject, distance_metric


Expand Down
2 changes: 1 addition & 1 deletion HARK/tests/test_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
import xarray as xr

from HARK.distribution import (
from HARK.distributions import (
Bernoulli,
DiscreteDistribution,
DiscreteDistributionLabeled,
Expand Down
2 changes: 1 addition & 1 deletion HARK/tests/test_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from HARK.distribution import Bernoulli, DiscreteDistribution
from HARK.distributions import Bernoulli, DiscreteDistribution
import HARK.model as model
from HARK.model import Control
import HARK.models.consumer as cons
Expand Down
Loading

0 comments on commit 235d3ce

Please sign in to comment.