コード例 #1
0
qs = np.zeros(shape=(len(l.ns), l.n_experiments, l.p + 1))

Rs_ins = np.empty(shape=(l.n_experiments, len(l.ns)))
Rs_oos = np.empty(shape=(l.n_experiments, len(l.ns)))
# Rs_lb = np.empty(shape=(len(l.ns)))

CEs_ins = np.empty(shape=(l.n_experiments, len(l.ns)))
CEs_oos = np.empty(shape=(l.n_experiments, len(l.ns)))

for i, n in enumerate(l.ns):
    print('Computing using sample of size %d' % n)

    pr_th = pr.AbstractProblem(l.M_true, n, l.λ, l.u, l.Rf)

    prs = pr.ProblemsDistribution(l.M, n, l.λ, l.u, l.Rf)
    prs.sample(l.n_experiments, par=True)

    qs[i, :, :] = prs.qs

    Rs_ins[:, i] = prs.Rs
    Rs_oos[:, i] = [R_star(q=p.q, M_square=None)
                    for p in prs()]  # Fixme make iterable
    CEs_ins[:, i] = prs.CEs
    CEs_oos[:, i] = [CE_star(q=p.q, M_square=None)
                     for p in prs()]  # Fixme make iterable

    # Rs_lb[i] = pr_th.Ω(δ,n)

datas = [
    'q_star', 'R_star_q_star', 'CE_star_q_star', 'qs', 'Rs_ins', 'Rs_oos',
コード例 #2
0
        return u.inverse(-R_star(q, λ))

    R_star_q_star = R_star(q_star)

    oos = np.empty(shape=(n_experiments, len(λs)))
    sbpt = np.empty(shape=(n_experiments, len(λs)))

    CE_ins = np.empty(shape=(n_experiments, len(λs)))
    CE_star = np.empty(shape=(n_experiments, len(λs)))
    CE_lb = np.empty(shape=(n_experiments, len(λs)))

    for i, λ in enumerate(λs):
        print('Computing with λ=%d' % λ)
        pr_th = pr.AbstractProblem(M, n, λ, u, Rf=0)

        prs = pr.ProblemsDistribution(M, n, λ, u, Rf=0)
        prs.sample(n_experiments)

        Rs_oos = [R_star(q_hat) for q_hat in prs.qs]
        oos[:, i] = np.abs(Rs_oos - prs.Rs)
        sbpt[:, i] = np.abs(R_star_q_star - prs.Rs)

        CE_ins[:, i] = prs.CEs
        CE_star[:, i] = [CE(q_hat) for q_hat in prs.qs]
        CE_lb[:, i] = CE_star[:, i] - u.inverse(-pr_th.Ω(δ, n) - prs.Rs)

    datas = ['CE_ins', 'CE_star', 'CE_lb', 'oos', 'sbpt']
    datas = {data: eval(data) for data in datas}

    params = ['λs', 'n', 'δ', 'n_experiments', 'u']
    params = {param: eval(param) for param in params}
コード例 #3
0
# In[22]:

# Results placeholder
qs = np.zeros(shape=(len(ns), p_true + 1, n_experiments))
CEs_ins = np.empty(shape=(len(ns), n_experiments))
CEs_oos = np.empty(shape=(len(ns), n_experiments))

# In[23]:

# About 8minutes running time.
for i, (n, p) in enumerate(zip(ns, ps)):
    print('Sampling %d problems of size %d × %d' % (n_experiments, n, p + 1))
    prs = pr.ProblemsDistribution(M,
                                  n,
                                  λ,
                                  u,
                                  Rf,
                                  problem_t=pr.SaturatedFeaturesMaskedProblem)
    prs.sample(n_experiments, {'fs': range(p + 1)}, par=True)
    qs[i, :p + 1, :] = prs.qs.T
    CEs_ins[i, :] = prs.CEs_ins
    CEs_oos[i, :] = prs.CEs_oos

# In[29]:

plt.plot(*five_stats(CEs_ins, ps))
plt.xlabel('$p$')
plt.ylabel('Returns (\%)')
plt.axis(xmin=4)
plt.title('In-sample CE. $n = 2p$')
コード例 #4
0
ファイル: Experiment9.py プロジェクト: thierry-bm/MEMOIRE
# In[17]:

# Results placeholder
qs = np.zeros(shape=(len(ns), p + 1, n_experiments))
CEs_ins = np.empty(shape=(len(ns), n_experiments))
CEs_oos = np.empty(shape=(len(ns), n_experiments))
Rs_ins = np.empty(shape=(len(ns), n_experiments))
Rs_oos = np.empty(shape=(len(ns), n_experiments))

# In[30]:

# About 8minutes running time.
for i, n in enumerate(ns):
    print('Sampling %d problems of size %d × %d' % (n_experiments, n, p + 1))
    prs = pr.ProblemsDistribution(M, n, λ / n, u, Rf)
    prs.sample(n_experiments)
    qs[i, :p + 1, :] = prs.qs.T
    CEs_ins[i, :] = prs.CEs_ins
    CEs_oos[i, :] = prs.CEs_oos
    Rs_ins[i, :] = prs.Rs_ins
    Rs_oos[i, :] = prs.Rs_oos

# In[34]:

matplotlib.rcParams['figure.figsize'] = (10, 4)
f, (p1, p2) = plt.subplots(1, 2)
p1.plot(*five_stats(CEs_ins, ns))
p1.axis(xmin=50)
p1.set_xlabel('$n$')
p1.set_ylabel('Returns (\%)')
コード例 #5
0
# In[13]:

# Results placeholder
qs = np.zeros(shape=(len(ns), p + 1, n_experiments))
CEs_ins = np.empty(shape=(len(ns), n_experiments))
CEs_oos = np.empty(shape=(len(ns), n_experiments))
Rs_ins = np.empty(shape=(len(ns), n_experiments))
Rs_oos = np.empty(shape=(len(ns), n_experiments))

# In[14]:

# About 5minutes running time.
for i, n in enumerate(ns):
    print('Sampling %d problems of size %d × %d' % (n_experiments, n, p + 1))
    prs = pr.ProblemsDistribution(M, n, λ / (n**2), u, Rf)
    prs.sample(n_experiments)
    qs[i, :p + 1, :] = prs.qs.T
    CEs_ins[i, :] = prs.CEs_ins
    CEs_oos[i, :] = prs.CEs_oos
    Rs_ins[i, :] = prs.Rs_ins
    Rs_oos[i, :] = prs.Rs_oos

# In[34]:

matplotlib.rcParams['figure.figsize'] = (10, 4)
f, (p1, p2) = plt.subplots(1, 2)
p1.plot(*five_stats(CEs_ins, ns))
p1.axis(xmin=50)
p1.set_xlabel('$n$')
p1.set_ylabel('Returns (\%)')