Пример #1
0
def stub_opt(df):
    print(df.name)
    stub = df.name
    # pufstub = pufbase.loc[pufbase['IRS_STUB'] ==  stub]
    xmat = np.asarray(df[targcols], dtype=float)
    wh = np.asarray(df.s006)

    targets_all.loc[targets_all['IRS_STUB'] == stub]
    targets_stub = targets_all[targcols].loc[targets_all['IRS_STUB'] == stub]
    targets_stub = np.asarray(targets_stub, dtype=float).flatten()

    x0 = np.ones(wh.size)

    rwp = rw.Reweight(wh, xmat, targets_stub)
    x, info = rwp.reweight(xlb=0.1, xub=10,
                           crange=.0001,
                           ccgoal=10, objgoal=100,
                           max_iter=50)
    print(info['status_msg'])

    df['x'] = x
    return df
Пример #2
0
xmat = np.asarray(pufstub[xcols], dtype=float)
xmat.shape

wh = np.asarray(pufstub.s006)

targets_stub = targets_all[tcols].iloc[stub]
targets_stub = np.asarray(targets_stub, dtype=float)

x0 = np.ones(wh.size)

# comp
t0 = constraints(x0, wh, xmat)
pdiff0 = t0 / targets_stub * 100 - 100
pdiff0

rwp = rw.Reweight(wh, xmat, targets_stub)
x, info = rwp.reweight(xlb=0.1, xub=10,
                       crange=.0001,
                       ccgoal=10, objgoal=100,
                       max_iter=50)
info['status_msg']

np.quantile(x, [0, .1, .25, .5, .75, .9, 1])

t1 = constraints(x, wh, xmat)
pdiff1 = t1 / targets_stub * 100 - 100
pdiff1


# %% loop through puf
grouped = df2.groupby('IRS_STUB')
Пример #3
0
p = mtp.Problem(h=500000, s=1, k=50)
p = mtp.Problem(h=1000000, s=1, k=100)


seed(1)
r = np.random.randn(p.targets.size) / 100  # random normal
q = [0, .01, .05, .1, .25, .5, .75, .9, .95, .99, 1]
np.quantile(r, q)
targets = (p.targets * (1 + r)).flatten()

x0 = np.ones(p.wh.size)
t0 = constraints(x0)
pdiff0 = t0 / targets * 100 - 100
pdiff0

rwp = rw.Reweight(p.wh, p.xmat, targets)
x, info = rwp.reweight(xlb=0.1, xub=10,
                       crange=.015,
                       ccgoal=10, objgoal=100,
                       max_iter=50)
info['status_msg']

np.quantile(x, [0, .1, .25, .5, .75, .9, 1])

t1 = constraints(x)
pdiff1 = t1 / targets * 100 - 100
pdiff1

pdiff0
pdiff1 - pdiff0
n, bins, patches = plt.hist(x, 100, density=True, facecolor='g', alpha=0.75)