Exemplo n.º 1
0
def test_direct():

    from dolo import yaml_import
    from dolo.algos.dtcscc.perturbations import approximate_controls
    from dolo.algos.dtcscc.time_iteration import time_iteration_direct, time_iteration

    model = yaml_import("examples/models/rbc_full.yaml")

    # Check without complementarity conditions
    dr = time_iteration_direct(model, with_complementarities=False)
    ddr = time_iteration(model, with_complementarities=False)

    x0 = dr(dr.grid)
    x1 = ddr(dr.grid)

    print(abs(x1 - x0).max() < 1e-5)

    # Check with complementarity conditions
    dr = time_iteration_direct(model, with_complementarities=True)
    ddr = time_iteration(model, with_complementarities=True)

    x0 = dr(dr.grid)
    x1 = ddr(dr.grid)

    print(abs(x1 - x0).max() < 1e-5)
Exemplo n.º 2
0
def test_direct():

    from dolo import yaml_import
    from dolo.algos.dtcscc.perturbations import approximate_controls
    from dolo.algos.dtcscc.time_iteration import time_iteration_direct, time_iteration

    model = yaml_import("examples/models/compat/rbc_full.yaml")

    # Check without complementarity conditions
    dr = time_iteration_direct(model, with_complementarities=False)
    ddr = time_iteration(model, with_complementarities=False)

    x0 = dr(dr.grid)
    x1 = ddr(dr.grid)

    print(abs(x1 - x0).max()<1e-5)


    # Check with complementarity conditions
    dr = time_iteration_direct(model, with_complementarities=True)
    ddr = time_iteration(model, with_complementarities=True)

    x0 = dr(dr.grid)
    x1 = ddr(dr.grid)

    print(abs(x1 - x0).max()<1e-5)
Exemplo n.º 3
0
def test_omega_errors():

    from dolo import yaml_import
    from dolo.algos.dtcscc.time_iteration import time_iteration as time_iteration

    model = yaml_import('examples/models/rbc.yaml')

    from dolo.algos.dtcscc.perturbations import approximate_controls

    dr = approximate_controls(model)
    dr_global = time_iteration(model,
                               smolyak_order=3,
                               verbose=False,
                               pert_order=1)

    sigma = model.covariances

    model.sigma = sigma

    s_0 = dr.S_bar

    from dolo.algos.dtcscc.accuracy import omega

    res_1 = omega(model, dr, orders=[10, 10], time_discount=0.96)
    res_2 = omega(model, dr_global)

    print(res_1)
    print(res_2)
Exemplo n.º 4
0
def test_denhaan_errors():

        from dolo import yaml_import
        from dolo.algos.dtcscc.time_iteration import time_iteration as time_iteration

        model = yaml_import('examples/models/rbc.yaml')

        from dolo.algos.dtcscc.perturbations import approximate_controls

        dr = approximate_controls(model)

        dr_global = time_iteration(model, verbose=False)

        s0 = model.calibration['states']
        sigma = model.get_distribution().sigma

        from dolo.algos.dtcscc.accuracy import denhaanerrors

        denerr_1 = denhaanerrors(model, dr)
        denerr_2 = denhaanerrors(model, dr_global)

        print(denerr_1)
        print(denerr_2)
        print(denerr_2['max_errors'][0])


        assert( max(denerr_2['max_errors']) < 10-7) # errors with solyak colocations at order 4 are very small
Exemplo n.º 5
0
def test_denhaan_errors():

    from dolo import yaml_import
    from dolo.algos.dtcscc.time_iteration import time_iteration as time_iteration

    model = yaml_import('examples/models/rbc.yaml')

    from dolo.algos.dtcscc.perturbations import approximate_controls

    dr = approximate_controls(model)

    dr_global = time_iteration(model, verbose=False)

    s0 = model.calibration['states']
    sigma = model.get_distribution().sigma

    from dolo.algos.dtcscc.accuracy import denhaanerrors

    denerr_1 = denhaanerrors(model, dr)
    denerr_2 = denhaanerrors(model, dr_global)

    print(denerr_1)
    print(denerr_2)
    print(denerr_2['max_errors'][0])

    assert (max(denerr_2['max_errors']) < 10 - 7
            )  # errors with solyak colocations at order 4 are very small
Exemplo n.º 6
0
def test_omega_errors():

        from dolo import yaml_import
        from dolo.algos.dtcscc.time_iteration import time_iteration as time_iteration

        model = yaml_import('examples/models/rbc.yaml')

        from dolo.algos.dtcscc.perturbations import approximate_controls

        dr = approximate_controls(model)
        dr_global = time_iteration(model, smolyak_order=3, verbose=False, pert_order=1)

        sigma = model.covariances

        model.sigma = sigma

        s_0 = dr.S_bar

        from dolo.algos.dtcscc.accuracy import  omega

        res_1 = omega( model, dr, orders=[10,10], time_discount=0.96)
        res_2 = omega( model, dr_global)

        print(res_1)
        print(res_2)
Exemplo n.º 7
0
def time_iteration(model, *args, **kwargs):

    if model.model_type == 'dtcscc':
        from dolo.algos.dtcscc.time_iteration import time_iteration
    elif model.model_type == 'dtmscc':
        from dolo.algos.dtmscc.time_iteration import time_iteration
    else:
        raise Exception("Model type {} not supported.".format(model.model_type))

    return time_iteration(model, *args, **kwargs)
Exemplo n.º 8
0
def time_iteration(model, *args, **kwargs):

    if model.model_type == 'dtcscc':
        from dolo.algos.dtcscc.time_iteration import time_iteration
    elif model.model_type == 'dtmscc':
        from dolo.algos.dtmscc.time_iteration import time_iteration
    else:
        raise Exception("Model type {} not supported.".format(
            model.model_type))

    return time_iteration(model, *args, **kwargs)
Exemplo n.º 9
0
def test_direct():

    from dolo import yaml_import
    from dolo.algos.dtcscc.perturbations import approximate_controls
    from dolo.algos.dtcscc.time_iteration import time_iteration_direct, time_iteration

    model = yaml_import("examples/models/rbc_full.yaml")

    dr = time_iteration_direct(model)
    ddr = time_iteration(model)

    x0 = dr(dr.grid)
    x1 = ddr(dr.grid)

    print(abs(x1 - x0).max()<1e-5)
Exemplo n.º 10
0
def test_direct():

    from dolo import yaml_import
    from dolo.algos.dtcscc.perturbations import approximate_controls
    from dolo.algos.dtcscc.time_iteration import time_iteration_direct, time_iteration

    model = yaml_import("examples/models/rbc_full.yaml")

    dr = time_iteration_direct(model)
    ddr = time_iteration(model)

    x0 = dr(dr.grid)
    x1 = ddr(dr.grid)

    print(abs(x1 - x0).max() < 1e-5)
def test_parameterized_expectations():

    from dolo import yaml_import
    from dolo.algos.dtcscc.parameterized_expectations import parameterized_expectations
    from dolo.algos.dtcscc.time_iteration import time_iteration

    model = yaml_import("examples/models/compat/rbc_full.yaml")

    dr_ti = time_iteration(model)
    dr_pea = parameterized_expectations(model, direct=False)

    x_ti = dr_ti(dr_ti.grid)
    x_pea = dr_pea(dr_ti.grid)

    print(abs(x_ti - x_pea).max() < 1e-5)
Exemplo n.º 12
0
def test_parameterized_expectations():

    from dolo import yaml_import
    from dolo.algos.dtcscc.parameterized_expectations import parameterized_expectations
    from dolo.algos.dtcscc.time_iteration import time_iteration

    model = yaml_import("examples/models/compat/rbc_full.yaml")

    dr_ti = time_iteration(model)
    dr_pea = parameterized_expectations(model, direct=False)

    x_ti = dr_ti(dr_ti.grid)
    x_pea = dr_pea(dr_ti.grid)

    print(abs(x_ti - x_pea).max() < 1e-5)
Exemplo n.º 13
0
def test_big_system():
    from dolo import yaml_import
    from dolo.algos.dtcscc.nonlinearsystem import nonlinear_system

    from dolo.algos.dtcscc.time_iteration import time_iteration

    model = yaml_import("examples/models/rbc.yaml")

    dr = time_iteration(model, grid={"type": "smolyak", "mu": 3}, verbose=True)
    sol = nonlinear_system(model, grid={"type": "smolyak", "mu": 3})

    diff = (sol.__values__) - dr.__values__
    assert abs(diff).max() < 1e-6

    sol_high_precision = nonlinear_system(model, grid={"type": "smolyak", "mu": 5}, initial_dr=sol)

    assert sol_high_precision.grid.shape == (145, 2)
Exemplo n.º 14
0
def test_big_system():
    from dolo import yaml_import
    from dolo.algos.dtcscc.nonlinearsystem import nonlinear_system

    from dolo.algos.dtcscc.time_iteration import time_iteration

    model = yaml_import('examples/models/compat/rbc.yaml')

    dr = time_iteration(model, grid={'type': 'smolyak', 'mu': 3}, verbose=True)
    sol = nonlinear_system(model, grid={'type': 'smolyak', 'mu': 3})

    diff = (sol.__values__) - dr.__values__
    assert(abs(diff).max() < 1e-6)

    sol_high_precision = nonlinear_system(model, grid={'type': 'smolyak', 'mu': 5}, initial_dr=sol)

    assert(sol_high_precision.grid.shape == (145, 2))
Exemplo n.º 15
0
def test_big_system():
    from dolo import yaml_import
    from dolo.algos.dtcscc.nonlinearsystem import nonlinear_system

    from dolo.algos.dtcscc.time_iteration import time_iteration

    model = yaml_import('examples/models/compat/rbc.yaml')

    dr = time_iteration(model, grid={'type': 'smolyak', 'mu': 3}, verbose=True)
    sol = nonlinear_system(model, grid={'type': 'smolyak', 'mu': 3})

    diff = (sol.__values__) - dr.__values__
    assert (abs(diff).max() < 1e-6)

    sol_high_precision = nonlinear_system(model,
                                          grid={
                                              'type': 'smolyak',
                                              'mu': 5
                                          },
                                          initial_dr=sol)

    assert (sol_high_precision.grid.shape == (145, 2))
Exemplo n.º 16
0
def test_omega_errors():

    from dolo import yaml_import
    from dolo.algos.dtcscc.time_iteration import time_iteration as time_iteration

    model = yaml_import('examples/models/compat/rbc.yaml')

    from dolo.algos.dtcscc.perturbations import approximate_controls

    dr = approximate_controls(model)
    dr_global = time_iteration(model, verbose=False, pert_order=1)

    sigma = model.get_distribution().sigma

    s_0 = dr.S_bar

    from dolo.algos.dtcscc.accuracy import omega

    res_1 = omega(model, dr, grid=dict(orders=[10, 10]), time_discount=0.96)
    res_2 = omega(model, dr_global)

    print(res_1)
    print(res_2)
Exemplo n.º 17
0
def test_omega_errors():

        from dolo import yaml_import
        from dolo.algos.dtcscc.time_iteration import time_iteration as time_iteration

        model = yaml_import('examples/models/compat/rbc.yaml')

        from dolo.algos.dtcscc.perturbations import approximate_controls

        dr = approximate_controls(model)
        dr_global = time_iteration(model, verbose=False, pert_order=1)

        sigma = model.get_distribution().sigma

        s_0 = dr.S_bar

        from dolo.algos.dtcscc.accuracy import omega

        res_1 = omega(model, dr, grid=dict(orders=[10, 10]), time_discount=0.96)
        res_2 = omega(model, dr_global)

        print(res_1)
        print(res_2)
Exemplo n.º 18
0
def global_solve(*args, **kwargs):
    return time_iteration(*args, **kwargs)