예제 #1
0
def run_one(params, res_dict=None):
    """
    Once you have the parameters, this function completes one loop to get
    a dictionary of results.

    For the first loop leave res_dict as None.
    """
    pi = params['pi'][0]
    # lambda_ = params['lambda_'][0]

    np.random.seed(42)
    w_grid = params['w_grid'][0]
    z_grid = params['z_grid'][0]

    if res_dict:
        print("Reusing res_dict.")
        v = res_dict['Tv']
        out = res_dict['rigid_out']
    else:
        v = Interp(w_grid, -w_grid + 27.3, kind='linear')
        out = ss_output_flexible(params)  # ss output w/ flexible wages
    # Get close with linear first.  Then do a few cubic to finish up
    Tv, ws, rest = iter_bellman(v,
                                tol=0.005,
                                strict=False,
                                log=False,
                                params=params,
                                pi=pi,
                                aggL=out,
                                kind='linear')
    Tvc = Interp(Tv.X, Tv.Y, kind='cubic')
    Tv, ws, rest = iter_bellman(Tvc,
                                tol=0.005,
                                strict=False,
                                log=False,
                                params=params,
                                pi=pi,
                                aggL=out)
    res_dict = {'Tv': Tv, 'ws': ws, 'rest': rest}
    flex_ws = Interp(z_grid, ss_wage_flexible(params, shock=z_grid))
    #-------------------------------------------------------------------------
    pths, shks = sample_path(ws, params, nseries=1000, nperiods=30)
    pth, shocks = pths[28], shks[28]  # a period in steady state
    g = ecdf(np.sort(pth))
    shocks = np.sort(shocks)
    #-------------------------------------------------------------------------
    rigid_out = get_rigid_output(ws, params, flex_ws, g)
    res_dict['gp'] = g
    res_dict['rigid_out'] = rigid_out
    return res_dict
예제 #2
0
def wage_dist_ecdf_refactor():
    """
    This implements the refactor of gp's to ecdfs.

    Also takes care of the output.
    """
    with open('results/fixup_notice.txt', 'a') as f:
        t = str(datetime.datetime.now())
        f.write("FIXED gps AT {}\n".format(t))

    params = load_params()
    params['results_path/'] = 'results/', 'a'
    all_files = ar.get_all_files(params)
    gps = ar.read_output(all_files, kind='gp')
    wses = ar.read_output(all_files, kind='ws')
    z_grid = params['z_grid'][0]
    flex_ws = Interp(z_grid, ss_wage_flexible(params, shock=z_grid))

    for key in gps.iterkeys():
        piname, lambda_ = [str(x).replace('.', '') for x in key]
        out_name = 'results/gp_' + piname + '_' + lambda_ + '.pkl'
        shutil.copy2(out_name, 'results/replaced_results/')
        ws = wses[key]
        params['pi'] = key[0], 'you'
        params['lambda_'] = key[1], 'idiot'
        new_g, shocks = get_new_g(ws, params)

        with open(out_name, 'w') as f:
            cPickle.dump(new_g, f)

        print("Fixed wage distribution for {}.".format(key))

        new_rigid_out = get_rigid_output(ws, params, flex_ws, new_g, shocks)

        out_name = 'results/rigid_output_' + piname + '_' + lambda_ + '_.txt'
        with open(out_name, 'w') as f:
            f.write(str(new_rigid_out))

        with open('results/fixup_notice.txt', 'a') as f:
            f.write("Fixed {}\n".format(key))
예제 #3
0
def run_one(params, res_dict=None):
    """
    Once you have the parameters, this function completes one loop to get
    a dictionary of results.

    For the first loop leave res_dict as None.
    """
    pi = params['pi'][0]
    # lambda_ = params['lambda_'][0]

    np.random.seed(42)
    w_grid = params['w_grid'][0]
    z_grid = params['z_grid'][0]

    if res_dict:
        print("Reusing res_dict.")
        v = res_dict['Tv']
        out = res_dict['rigid_out']
    else:
        v = Interp(w_grid, -w_grid + 27.3, kind='linear')
        out = ss_output_flexible(params)  # ss output w/ flexible wages
    # Get close with linear first.  Then do a few cubic to finish up
    Tv, ws, rest = iter_bellman(v, tol=0.005, strict=False, log=False,
                                params=params, pi=pi, aggL=out, kind='linear')
    Tvc = Interp(Tv.X, Tv.Y, kind='cubic')
    Tv, ws, rest = iter_bellman(Tvc, tol=0.005, strict=False, log=False,
                                params=params, pi=pi, aggL=out)
    res_dict = {'Tv': Tv, 'ws': ws, 'rest': rest}
    flex_ws = Interp(z_grid, ss_wage_flexible(params, shock=z_grid))
    #-------------------------------------------------------------------------
    pths, shks = sample_path(ws, params, nseries=1000, nperiods=30)
    pth, shocks = pths[28], shks[28]  # a period in steady state
    g = ecdf(np.sort(pth))
    shocks = np.sort(shocks)
    #-------------------------------------------------------------------------
    rigid_out = get_rigid_output(ws, params, flex_ws, g)
    res_dict['gp'] = g
    res_dict['rigid_out'] = rigid_out
    return res_dict