diff --git a/Documentation/CHANGELOG.md b/Documentation/CHANGELOG.md index c5573cea3..f16f1ad23 100644 --- a/Documentation/CHANGELOG.md +++ b/Documentation/CHANGELOG.md @@ -8,6 +8,14 @@ For more information on HARK, see [our Github organization](https://github.com/e ## Changes +### 0.10.9 + +Release Data: TBD + +#### Major Changes + +* calcExpectations method for taking the expectation of a distribution over a function (#884)[https://github.com/econ-ark/HARK/pull/884/] + ### 0.10.8 Release Data: Nov. 05 2020 diff --git a/HARK/ConsumptionSaving/ConsAggShockModel.py b/HARK/ConsumptionSaving/ConsAggShockModel.py index f55a56ca9..4c446b53d 100644 --- a/HARK/ConsumptionSaving/ConsAggShockModel.py +++ b/HARK/ConsumptionSaving/ConsAggShockModel.py @@ -29,7 +29,12 @@ CRRAutility_inv, makeGridExpMult, ) -from HARK.distribution import Uniform, calcExpectation +from HARK.distribution import ( + MeanOneLogNormal, + Uniform, + combineIndepDstns, + calcExpectation +) from HARK.ConsumptionSaving.ConsIndShockModel import ( ConsumerSolution, IndShockConsumerType, @@ -1109,6 +1114,8 @@ def solveConsAggShock( The net interest factor on assets as a function of capital ratio k. wFunc : function The wage rate for labor as a function of capital-to-labor ratio k. + DeprFac : float + Capital Depreciation Rate Returns ------- @@ -1449,6 +1456,8 @@ def solveConsAggMarkov( The net interest factor on assets as a function of capital ratio k. wFunc : function The wage rate for labor as a function of capital-to-labor ratio k. + DeprFac : float + Capital Depreciation Rate Returns ------- diff --git a/HARK/distribution.py b/HARK/distribution.py index a2099e33c..604fecc8c 100644 --- a/HARK/distribution.py +++ b/HARK/distribution.py @@ -84,6 +84,8 @@ def draw(self, N): ---------- N : int Number of draws in each row. + seed : int + Seed for random number generator. Returns: ------------ @@ -217,7 +219,6 @@ def __init__(self, sigma=1.0, seed=0): mu = -0.5 * sigma ** 2 super().__init__(mu=mu, sigma=sigma, seed=seed) - class Normal(Distribution): """ A Normal distribution. @@ -584,6 +585,7 @@ def drawDiscrete(self, N, X=None, exact_match=False): int ) # cutoff points between discrete outcomes top = 0 + # Make a list of event indices that closely matches the discrete distribution event_list = [] for j in range(events.size): @@ -964,8 +966,8 @@ def combineIndepDstns(*distributions, seed=0): # probability array. So get the probability array, P_out, here. P_out = np.prod(np.array(P_temp), axis=0) - assert np.isclose(np.sum(P_out),1),'Probabilities do not sum to 1!' - return DiscreteDistribution(P_out, X_out) + assert np.isclose(np.sum(P_out), 1), "Probabilities do not sum to 1!" + return DiscreteDistribution(P_out, X_out, seed=seed) def calcExpectation(dstn,func=None,values=None): diff --git a/HARK/tests/test_distribution.py b/HARK/tests/test_distribution.py index 952f47311..64efb9466 100644 --- a/HARK/tests/test_distribution.py +++ b/HARK/tests/test_distribution.py @@ -53,7 +53,14 @@ def test_Weibull(self): self.assertEqual(distribution.Weibull().draw(1)[0], 0.79587450816311) def test_Uniform(self): + uni = distribution.Uniform() + self.assertEqual(distribution.Uniform().draw(1)[0], 0.5488135039273248) + self.assertEqual( + distribution.calcExpectation(uni.approx(10))[0], + 0.5 + ) + def test_Bernoulli(self): self.assertEqual(distribution.Bernoulli().draw(1)[0], False)