<commit_before>from HARK.ConsumptionSaving.ConsIndShockModel import \
    IndShockConsumerType, ConsIndShockSolverBasic
import HARK.ConsumptionSaving.ConsumerParameters as Params
import numpy as np
import unittest

class testIndShockConsumerType(unittest.TestCase):

    def test_getShocks(self):
        agent = IndShockConsumerType(
            AgentCount = 2,
            T_sim = 10
        )

        agent.solve()

        agent.initializeSim()
        agent.simBirth(np.array([True,False]))
        agent.simOnePeriod()
        agent.simBirth(np.array([False,True]))

        agent.getShocks()

        self.assertEqual(agent.PermShkNow[0],
                         1.0050166461586711)
        self.assertEqual(agent.PermShkNow[1],
                         1.0050166461586711)
        self.assertEqual(agent.TranShkNow[0],
                         1.1176912196531754)

    def test_ConsIndShockSolverBasic(self):
        LifecycleExample = IndShockConsumerType(
            **Params.init_lifecycle)
        LifecycleExample.cycles = 1
        LifecycleExample.solve()

        solver = ConsIndShockSolverBasic(LifecycleExample.solution[1],
                                 LifecycleExample.IncomeDstn[0],
                                 LifecycleExample.LivPrb[0],
                                 LifecycleExample.DiscFac,
                                 LifecycleExample.CRRA,
                                 LifecycleExample.Rfree,
                                 LifecycleExample.PermGroFac[0],
                                 LifecycleExample.BoroCnstArt,
                                 LifecycleExample.aXtraGrid,
                                 LifecycleExample.vFuncBool,
                                 LifecycleExample.CubicBool)

        solver.prepareToSolve()

        self.assertAlmostEqual(solver.DiscFacEff,
                               0.9503999999999999)
        self.assertAlmostEqual(solver.PermShkMinNext,
                               0.850430160026919)
        self.assertAlmostEqual(solver.cFuncNowCnst(4).tolist(),
                               4.0)
        self.assertAlmostEqual(solver.prepareToCalcEndOfPrdvP()[0],
                               -0.2491750859108316)
        self.assertAlmostEqual(solver.prepareToCalcEndOfPrdvP()[-1],
                               19.74982491408914)

        EndOfPrdvP = solver.calcEndOfPrdvP()

        self.assertAlmostEqual(EndOfPrdvP[0],
                               6622.251864311334)
        self.assertAlmostEqual(EndOfPrdvP[-1],
                               0.026301061207747087)

        solution = solver.makeBasicSolution(EndOfPrdvP,
                                            solver.aNrmNow,
                                            solver.makeLinearcFunc)
        solver.addMPCandHumanWealth(solution)

        self.assertAlmostEqual(solution.cFunc(4).tolist(),
                               1.7391265696400773)


class testBufferStock(unittest.TestCase):
    """ Tests of the results of the BufferStock REMARK.
    """
    
    def setUp(self):
        # Make a dictionary containing all parameters needed to solve the model
        self.base_params = Params.init_idiosyncratic_shocks<commit_msg>adding test for MPC result of IndShockConsumerType result of simulations<commit_after>from HARK.ConsumptionSaving.ConsIndShockModel import \
    IndShockConsumerType, ConsIndShockSolverBasic
import HARK.ConsumptionSaving.ConsumerParameters as Params
import numpy as np
import unittest

class testIndShockConsumerType(unittest.TestCase):

    def setUp(self):
        self.agent = IndShockConsumerType(
            AgentCount = 2,
            T_sim = 10
        )

        self.agent.solve()

    def test_getShocks(self):
        self.agent.initializeSim()
        self.agent.simBirth(np.array([True,False]))
        self.agent.simOnePeriod()
        self.agent.simBirth(np.array([False,True]))

        self.agent.getShocks()

        self.assertEqual(self.agent.PermShkNow[0],
                         1.0050166461586711)
        self.assertEqual(self.agent.PermShkNow[1],
                         1.0050166461586711)
        self.assertEqual(self.agent.TranShkNow[0],
                         1.1176912196531754)

    def test_ConsIndShockSolverBasic(self):
        LifecycleExample = IndShockConsumerType(
            **Params.init_lifecycle)
        LifecycleExample.cycles = 1
        LifecycleExample.solve()

        solver = ConsIndShockSolverBasic(LifecycleExample.solution[1],
                                 LifecycleExample.IncomeDstn[0],
                                 LifecycleExample.LivPrb[0],
                                 LifecycleExample.DiscFac,
                                 LifecycleExample.CRRA,
                                 LifecycleExample.Rfree,
                                 LifecycleExample.PermGroFac[0],
                                 LifecycleExample.BoroCnstArt,
                                 LifecycleExample.aXtraGrid,
                                 LifecycleExample.vFuncBool,
                                 LifecycleExample.CubicBool)

        solver.prepareToSolve()

        self.assertAlmostEqual(solver.DiscFacEff,
                               0.9503999999999999)
        self.assertAlmostEqual(solver.PermShkMinNext,
                               0.850430160026919)
        self.assertAlmostEqual(solver.cFuncNowCnst(4).tolist(),
                               4.0)
        self.assertAlmostEqual(solver.prepareToCalcEndOfPrdvP()[0],
                               -0.2491750859108316)
        self.assertAlmostEqual(solver.prepareToCalcEndOfPrdvP()[-1],
                               19.74982491408914)

        EndOfPrdvP = solver.calcEndOfPrdvP()

        self.assertAlmostEqual(EndOfPrdvP[0],
                               6622.251864311334)
        self.assertAlmostEqual(EndOfPrdvP[-1],
                               0.026301061207747087)

        solution = solver.makeBasicSolution(EndOfPrdvP,
                                            solver.aNrmNow,
                                            solver.makeLinearcFunc)
        solver.addMPCandHumanWealth(solution)

        self.assertAlmostEqual(solution.cFunc(4).tolist(),
                               1.7391265696400773)

    def test_MPCnow(self):
        self.agent.initializeSim()
        self.agent.simulate()

        self.assertAlmostEqual(self.agent.MPCnow[1],
                               0.5535801655448935)


class testBufferStock(unittest.TestCase):
    """ Tests of the results of the BufferStock REMARK.
    """
    
    def setUp(self):
        # Make a dictionary containing all parameters needed to solve the model
        self.base_params = Params.init_idiosyncratic_shocks
{'fraction_non_alphanumeric': 0.07291357291357291, 'fraction_numerical': 0.058509058509058506, 'mean_word_length': 1.5953757225433527, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1368706', 'n_tokens_mistral': 2136, 'n_tokens_neox': 1810, 'n_words': 228}