Esempio n. 1
0
def obs_pp(cdat, alp, lw, gn):
    """replace obs type params"""

    # Get parameter sums
    r = make_psums(cdat, alp, lw, gn)
    phat = 100

    # Get wealth ratios
    exptot = cdat['exptot']
    w = lw / exptot

    # Fit spline
    gp = run_est.make_grid(cdat) #should move this to save on calculation
    #spline = fit_spline.fit(gp, alp)
    w_pts, r_pts, op_pts = fit_spline.fit(gp, alp)

    # Get gammas
    #gam = spline.ev(w,r) 
    gam = np.nan_to_num(griddata((w_pts, r_pts), op_pts, (w,r)))
    op = gam * phat
    op[op <= 1e-10] = 1e3 #eliminate negative and exactly zero values (approximation error)

    # Read into consumption data
    cdat['op'] = op
    for i in range(gn):
        pname = 'p' + str(i + 1)
        addme = (cdat['ot'] == i + 1) * op 
        cdat[pname] = addme.add((cdat['ot'] != i + 1) * cdat[pname])

    return cdat
Esempio n. 2
0
    # Remove weird values
    x = [k[0] for k in gp]
    y = [k[1] for k in gp]
    df = pd.DataFrame(np.array([x, y, sols]).T)
    clean = df.groupby(0).apply(lambda row: elim_weirds(row))

    return clean[0], clean[1], clean[2]


def elim_weirds(group):
    """even a zero param will have some consumption of the obs good
    which means that some consumptions are impossible, and confuse my
    solver.  This script eliminates those weird values"""

    minind = group[2].idxmin()
    group[group.index < minind] = 1e-12

    return group


if __name__ == "__main__":

    cdat = pd.read_pickle("cdat.pickle")

    # get grid points in form of (w, r)
    gp = run_est.make_grid(cdat)

    alp = 0.3
    spline = fit(gp, alp)