当前位置: 首页>>代码示例>>Python>>正文


Python quantecon.compute_fixed_point函数代码示例

本文整理汇总了Python中quantecon.compute_fixed_point函数的典型用法代码示例。如果您正苦于以下问题:Python compute_fixed_point函数的具体用法?Python compute_fixed_point怎么用?Python compute_fixed_point使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了compute_fixed_point函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _new_solution

def _new_solution(sp, f, grp):
    "gets a new set of solution objects and updates the data file"

    # compute value function and policy rule using vfi
    v_init = np.zeros(len(sp.grid_points)) + sp.c / (1 - sp.beta)
    v = compute_fixed_point(sp.bellman_operator, v_init, error_tol=_tol,
                            max_iter=5000)
    phi_vfi = sp.get_greedy(v)

    # also run v through bellman so I can test if it is a fixed point
    # bellman_operator takes a long time, so store result instead of compute
    new_v = sp.bellman_operator(v)

    # compute policy rule using pfi

    phi_init = np.ones(len(sp.pi_grid))
    phi_pfi = compute_fixed_point(sp.res_wage_operator, phi_init,
                                  error_tol=_tol, max_iter=5000)

    # write all arrays to file
    write_array(f, grp, v, "v")
    write_array(f, grp, phi_vfi, "phi_vfi")
    write_array(f, grp, phi_pfi, "phi_pfi")
    write_array(f, grp, new_v, "new_v")

    # return data
    return v, phi_vfi, phi_pfi, new_v
开发者ID:AgZoey,项目名称:QuantEcon.applications,代码行数:27,代码来源:test_odu.py

示例2: _solve_via_pfi

def _solve_via_pfi(cp, c_init):
    "compute policy rule using policy function iteration"
    p = compute_fixed_point(cp.coleman_operator, c_init, verbose=False,
                            error_tol=1e-5,
                            max_iter=1000)

    return p
开发者ID:AgZoey,项目名称:QuantEcon.applications,代码行数:7,代码来源:test_ifp.py

示例3: test_contraction_1

 def test_contraction_1(self):
     "compute_fp: convergence inside interval of convergence"
     f = lambda x: self.T(x, self.mu_1)
     for i in self.unit_inverval:
         # should have fixed point of 0.0
         self.assertTrue(abs(compute_fixed_point(f, i, **self.kwargs))
                         < 1e-4)
开发者ID:fo-github,项目名称:quant-econ,代码行数:7,代码来源:test_compute_fp.py

示例4: test_not_contraction_2

 def test_not_contraction_2(self):
     "compute_fp: no convergence outside interval of convergence"
     f = lambda x: self.T(x, self.mu_2)
     for i in self.unit_inverval:
         # This shouldn't converge to 0.0
         self.assertFalse(abs(compute_fixed_point(f, i, **self.kwargs))
                          < 1e-4)
开发者ID:fo-github,项目名称:quant-econ,代码行数:7,代码来源:test_compute_fp.py

示例5: compute_lt_price

    def compute_lt_price(self, error_tol=1e-3, max_iter=50, verbose=0):
        """
        Compute the equilibrium price function associated with Lucas
        tree lt

        Parameters
        ----------
        error_tol, max_iter, verbose
            Arguments to be passed directly to
            `quantecon.compute_fixed_point`. See that docstring for more
            information

        Returns
        -------
        price : array_like(float)
            The prices at the grid points in the attribute `grid` of the
            object

        """
        # == simplify notation == #
        grid, grid_size = self.grid, self.grid_size
        lucas_operator, gamma = self.lucas_operator, self.gamma

        # == Create storage array for compute_fixed_point. Reduces  memory
        # allocation and speeds code up == #
        Tf = np.empty(grid_size)

        # == Initial guess, just a vector of zeros == #
        f_init = np.zeros(grid_size)
        f = compute_fixed_point(lucas_operator, f_init, error_tol,
                                max_iter, verbose, Tf=Tf)

        price = f * grid**gamma

        return price
开发者ID:361793842,项目名称:QuantEcon.applications,代码行数:35,代码来源:lucastree.py

示例6: _solve_via_vfi

def _solve_via_vfi(jv):
    "compute policy rules via value function iteration"
    v_init = jv.x_grid * 0.6
    V = compute_fixed_point(jv.bellman_operator, v_init,
                            max_iter=3000,
                            error_tol=1e-5)
    return V
开发者ID:361793842,项目名称:QuantEcon.applications,代码行数:7,代码来源:test_jv.py

示例7: test_not_contraction_1

 def test_not_contraction_1(self):
     "compute_fp: no convergence outside interval of convergence"
     f = lambda x: self.T(x, self.mu_1)
     fp = (4 * self.mu_1 - 1) / (4 * self.mu_1)
     for i in self.unit_inverval:
         # This should not converge  (b/c unique fp is 0.0)
         self.assertFalse(abs(compute_fixed_point(f, i, **self.kwargs)-fp)
                          < 1e-4)
开发者ID:fo-github,项目名称:quant-econ,代码行数:8,代码来源:test_compute_fp.py

示例8: test_contraction_2

 def test_contraction_2(self):
     "compute_fp: convergence inside interval of convergence"
     f = lambda x: self.T(x, self.mu_2)
     fp = (4 * self.mu_2 - 1) / (4 * self.mu_2)
     for i in self.unit_inverval:
         # This should converge to fp
         self.assertTrue(abs(compute_fixed_point(f, i, **self.kwargs)-fp)
                         < 1e-4)
开发者ID:fo-github,项目名称:quant-econ,代码行数:8,代码来源:test_compute_fp.py

示例9: setUpClass

    def setUpClass(cls):
        jv = JvWorker(A=A, alpha=alpha, beta=beta, grid_size=grid_size)
        cls.jv = jv

        # compute solution
        v_init = _get_vf_guess(jv)
        cls.V = compute_fixed_point(jv.bellman_operator, v_init)
        cls.s_pol, cls.phi_pol = jv.bellman_operator(cls.V * 0.999,
                                                     return_policies=True)
开发者ID:361793842,项目名称:QuantEcon.applications,代码行数:9,代码来源:test_jv.py

示例10: test_2d_input

    def test_2d_input(self):
        error_tol = self.coeff**4

        for method in self.methods:
            init = np.array([[-1, 0.5], [-1/3, 0.1]])
            fp_computed = compute_fixed_point(self.f, init,
                                              error_tol=error_tol,
                                              method=method)
            ok_((fp_computed <= error_tol * 2).all())
开发者ID:fo-github,项目名称:quant-econ,代码行数:9,代码来源:test_compute_fp.py

示例11: test_num_iter_one

    def test_num_iter_one(self):
        init = 1.
        error_tol = self.coeff

        for method in self.methods:
            fp_computed = compute_fixed_point(self.f, init,
                                              error_tol=error_tol,
                                              method=method)
            ok_(fp_computed <= error_tol * 2)
开发者ID:fo-github,项目名称:quant-econ,代码行数:9,代码来源:test_compute_fp.py

示例12: test_imitation_game_method

    def test_imitation_game_method(self):
        "compute_fp: Test imitation game method"
        method = 'imitation_game'
        error_tol = self.kwargs['error_tol']

        for mu in [self.mu_1, self.mu_2]:
            for i in self.unit_inverval:
                fp_computed = compute_fixed_point(self.T, i, method=method,
                                                  mu=mu, **self.kwargs)
                self.assertTrue(
                    abs(self.T(fp_computed, mu=mu) - fp_computed) <= error_tol
                )

            # numpy array input
            i = np.asarray(self.unit_inverval)
            fp_computed = compute_fixed_point(self.T, i, method=method, mu=mu,
                                              **self.kwargs)
            self.assertTrue(
                abs(self.T(fp_computed, mu=mu) - fp_computed).max() <=
                error_tol
            )
开发者ID:fo-github,项目名称:quant-econ,代码行数:21,代码来源:test_compute_fp.py

示例13: test_num_iter_large

    def test_num_iter_large(self):
        init = 1.
        buff_size = 2**8  # buff_size in 'imitation_game'
        max_iter = buff_size + 2
        error_tol = self.coeff**max_iter

        for method in self.methods:
            fp_computed = compute_fixed_point(self.f, init,
                                              error_tol=error_tol,
                                              max_iter=max_iter, method=method,
                                              print_skip=max_iter)
            ok_(fp_computed <= error_tol * 2)
开发者ID:fo-github,项目名称:quant-econ,代码行数:12,代码来源:test_compute_fp.py

示例14: _solve_via_vfi

def _solve_via_vfi(cp, v_init, return_both=False):
    "compute policy rule using value function iteration"
    v = compute_fixed_point(cp.bellman_operator, v_init, verbose=False,
                            error_tol=1e-5,
                            max_iter=1000)

    # Run one more time to get the policy
    p = cp.bellman_operator(v, return_policy=True)

    if return_both:
        return v, p
    else:
        return p
开发者ID:AgZoey,项目名称:QuantEcon.applications,代码行数:13,代码来源:test_ifp.py

示例15: _new_solution

def _new_solution(gm, f, grp):
    "gets a new set of solution objects and updates the data file"

    # compute value function and policy rule using vfi
    v_init = 5 * gm.u(gm.grid) - 25
    v = compute_fixed_point(gm.bellman_operator, v_init, error_tol=_tol,
                            max_iter=5000)
    # sigma = gm.get_greedy(v)

    # write all arrays to file
    write_array(f, grp, v, "v")

    # return data
    return v
开发者ID:AlIrvine,项目名称:QuantEcon.py,代码行数:14,代码来源:test_optgrowth.py


注:本文中的quantecon.compute_fixed_point函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。