def updateEvolution(self): ''' Updates the "population punk proportion" evolution array. Fasion victims believe that the proportion of punks in the subsequent period is a linear function of the proportion of punks this period, subject to a uniform shock. Given attributes of self pNextIntercept, pNextSlope, pNextCount, pNextWidth, and pGrid, this method generates a new array for the attri- bute pEvolution, representing a discrete approximation of next period states for each current period state in pGrid. Parameters ---------- None Returns ------- None ''' self.pEvolution = np.zeros((self.pCount, self.pNextCount)) for j in range(self.pCount): pNow = self.pGrid[j] pNextMean = self.pNextIntercept + self.pNextSlope * pNow dist = Uniform(bot=pNextMean - self.pNextWidth, top=pNextMean + self.pNextWidth) self.pEvolution[j, :] = dist.approx(self.pNextCount).X
def test_distribute_params(self): dist = Uniform(bot=0.9, top=0.94) self.agents = distribute_params(self.agent, 'DiscFac', 3, dist) self.assertTrue(all(['DiscFac' in agent.parameters for agent in self.agents])) self.assertTrue(all([self.agents[i].parameters['DiscFac'] == dist.approx(3).X[i] for i in range(3)]))
def test_Uniform(self): uni = Uniform() self.assertEqual(Uniform().draw(1)[0], 0.5488135039273248) self.assertEqual(calc_expectation(uni.approx(10)), 0.5)