<jupyter_start><jupyter_text>See differences in Pushforwards when you fix noise values Exploring the "corners" of the M-dimensional Guassian hyper-sphere to get a sense of bounds on the noise sample space.<jupyter_code>def see_difference(eps,idx):
    i0, i1 = idx
    input_samples_fix_noise = input_samples.copy()
    input_samples_fix_noise[:,i0:(i1+0)] = eps
    output_samps_fix_noise = model(input_samples_fix_noise)
    output_samples_fix_noise = loss_fun(output_samps_fix_noise)
    
    w = 3 # window size (to the left and right of zero)
    plt.figure(figsize=(20,10))
    plt.hist(output_samples, bins=40, density=True, color='b', alpha = 0.5, label='histogram of loss function for variable noise')
    plt.hist(output_samples_fix_noise, bins=40, density=True, alpha = 0.5, color='r', label='histogram of loss function for fixed noise')
    xmesh = np.linspace(-w, w, 1000)
    full_eval = sstats.gaussian_kde(output_samples).evaluate(xmesh)
    part_eval = sstats.gaussian_kde(output_samples_fix_noise).evaluate(xmesh)
    plt.plot(xmesh, full_eval, c='b', label='estimate of density for full problem', lw=3)
#     plt.vlines(0,0, 0.3)
    plt.plot(xmesh, part_eval, c='r', label='estimate of density for approx problem', lw=3)
#     plt.plot(xmesh, obs_dist.pdf(xmesh), 'k:', label='observed')
    plt.title('Data Space')
    plt.xlim([-w, w])
#     plt.ylim([0, 0.1])
    plt.legend()
    plt.show()
    ratio_diff = np.abs( (full_eval - part_eval)/full_eval )
    print(ratio_diff.min(), ratio_diff.max())
    print(100*ratio_diff.mean(), ratio_diff.std())
    print(output_samples_fix_noise.min(), output_samples_fix_noise.max())
    print(output_samples.min(), output_samples.max())
    
eps_choice = list(np.linspace(-0.025, 0.025, 5))
wid.interact(see_difference, eps=wid.SelectionSlider(value=0, options=eps_choice, continuous_update=False),
             idx=wid.IntRangeSlider(value=(3,M+1), min=3, max=M+1, continuous_update=False),
            regularize=wid.Checkbox(value=True))<jupyter_output><empty_output><jupyter_text>Draw random samples from $\Xi$ and approximate push-forward<jupyter_code>def see_variation(k,idx):
    i0, i1 = idx
    input_samples_fix_noise = input_samples.copy()
    input_samples_fix_noise[:,i0:i1] = input_samples_fix_noise[k,i0:i1]
    
    output_samps_fix_noise = model(input_samples_fix_noise)
    output_samples_fix_noise = loss_fun(output_samps_fix_noise)
    
    w = 5 # window size (to the left and right of zero)
    plt.figure(figsize=(20,10))
    plt.hist(output_samples, bins=40, density=True, color='b', alpha = 0.5, label='histogram of loss function for variable noise')
    plt.hist(output_samples_fix_noise, bins=40, density=True, alpha = 0.5, color='r', label='histogram of loss function for fixed noise')
    xmesh = np.linspace(-w, w, 1000)
    full_eval = sstats.gaussian_kde(output_samples).evaluate(xmesh)
    part_eval = sstats.gaussian_kde(output_samples_fix_noise).evaluate(xmesh)
    plt.plot(xmesh, full_eval, c='b', label='estimate of density for full problem', lw=3)
#     plt.vlines(0,0, 0.3)
    plt.plot(xmesh, part_eval, c='r', label='estimate of density for approx problem', lw=3)
#     plt.plot(xmesh, obs_dist.pdf(xmesh), 'k:', label='observed')
    plt.title('Data Space')
    plt.xlim([-w, w])
#     plt.ylim([0, 0.1])
    plt.legend()
    plt.show()
    ratio_diff = np.abs( (full_eval - part_eval)/full_eval )
    print(ratio_diff.min(), ratio_diff.max())
    print(100*ratio_diff.mean(), ratio_diff.std())
    print(output_samples_fix_noise.min(), output_samples_fix_noise.max())
    print(output_samples.min(), output_samples.max())
    
wid.interact(see_variation, k=wid.IntSlider(value=0, min=0, max=N-1, continuous_update=False),
             idx=wid.IntRangeSlider(value=(3,M+1), min=3, max=M+1, continuous_update=False),
            regularize=wid.Checkbox(value=True))<jupyter_output><empty_output><jupyter_text>draw MC samples from $\Xi$ and plot their pushforwardsWe get a sense of the variation in the pushforward approximation in the region of interest. _This represents experiments that COULD have happened_.Notice that no individual draw from $\Xi$ can faithfully reproduce the full density.<jupyter_code>w = 3 # window size (to the left and right of zero)
xmesh = np.linspace(-w, w, 500)
plt.figure(figsize=(20,10))
# plt.hist(output_samples, bins=40, density=True, color='b', alpha = 0.5, label='histogram of loss function for variable noise')
full_eval = sstats.gaussian_kde(output_samples).evaluate(xmesh)
plt.plot(xmesh, full_eval, c='b', label='estimate of density for full problem', lw=5)

for k in range(50):
    input_samples_fix_noise = input_samples.copy()
    input_samples_fix_noise[:,3::] = input_samples_fix_noise[k,3::]
    output_samps_fix_noise = model(input_samples_fix_noise)
    output_samples_fix_noise = loss_fun(output_samps_fix_noise)
#     plt.hist(output_samples_fix_noise, bins=40, density=True, alpha = 0.5, color='r', label='histogram of loss function for fixed noise')
    part_eval = sstats.gaussian_kde(output_samples_fix_noise).evaluate(xmesh)
    plt.plot(xmesh, part_eval, c='k', lw=1, alpha=0.5)
#     plt.vlines(0,0, 1)

input_samples_fix_noise = input_samples.copy()
input_samples_fix_noise[:,3::] = 0
output_samps_fix_noise = model(input_samples_fix_noise)
output_samples_fix_noise = loss_fun(output_samps_fix_noise)
#     plt.hist(output_samples_fix_noise, bins=40, density=True, alpha = 0.5, color='r', label='histogram of loss function for fixed noise')
part_eval = sstats.gaussian_kde(output_samples_fix_noise).evaluate(xmesh)
plt.plot(xmesh, part_eval, c='red', lw=5, alpha=1, label='Zero Noise')

# plt.plot(xmesh, obs_dist.pdf(xmesh), 'r', label='observed')
plt.title('Data Space')
plt.xlim([-w, w])
# plt.ylim([0, 0.05])
plt.legend()
# plt.savefig('no_one_line.png')
plt.show()<jupyter_output><empty_output><jupyter_text>Observed Noise<jupyter_code>def noise_vary(eps, regularize=False):
    test_mesh = np.linspace(0,0.5,500)
    I = quad(conditionalY, -1, 1, args=eps)[0]
    test_eval = np.array([conditionalY(xi, fixy=eps) for xi in test_mesh])
    test_eval = test_eval/(1+regularize*(I-1))
    plt.figure(figsize=(20,10))
    # plt.plot(test_mesh, sstats.norm(scale=data_std).pdf(test_mesh))
#     plt.vlines(obs_data + noise, 0, 2, label='$d$')
#     plt.vlines(lam, 0, test_eval.max(), color='blue', label='$\lambda_0$')
    plt.plot(test_mesh, sstats.norm(loc=lam, scale=data_std).pdf(test_mesh), label='N(0,$\sigma_d$)')
    plt.plot(test_mesh, test_eval, c='r', label='conditional')
    plt.xlabel('$\lambda$')
#     if regularize:
#         plt.ylim([0,75])
#     else:
#         plt.ylim([0,1000])
    plt.legend()
    plt.show()
    return I 
    
def lam_vary(lam0, regularize=False):
    ww = 0.05
    test_mesh = np.linspace(-ww, ww, 500)
    I = quad(conditionalX, -ww, ww, args=lam0)[0]
    test_eval = np.array([conditionalX(xi, fixx=lam0) for xi in test_mesh])
    test_eval = test_eval/(1+regularize*(I-1))
    plt.figure(figsize=(20,10))
    plt.plot(test_mesh, sstats.norm(scale=data_std).pdf(test_mesh), label='N(0,$\sigma_d$)')
#     plt.vlines(noise, 0, test_eval.max(), label='noise')
#     plt.vlines(0, 0, test_eval.max(), color='blue', label='0')
    plt.plot(test_mesh, test_eval, c='r', label='conditional')
    plt.xlabel('$\epsilon$')
#     if regularize:
#         plt.ylim([0,75])
#     else:
#         plt.ylim([0,1000])
    plt.legend()
    plt.show()
    return I<jupyter_output><empty_output><jupyter_text>Slice through a particular noise value.<jupyter_code>eps_choice = list(np.linspace(-0.025, 0.025, 21)) 
wid.interact(noise_vary, eps=wid.SelectionSlider(value=0, options=eps_choice, continuous_update=False),
            regularize=wid.Checkbox(value=True))<jupyter_output><empty_output><jupyter_text>Slice through a particular input parameter value. (noise = 0)<jupyter_code>lam_choice = list(np.linspace(0.2, 0.3, 21))
wid.interact(lam_vary, lam0=wid.SelectionSlider(value=lam, options=lam_choice, continuous_update=False),
            regularize=wid.Checkbox(value=True))

plt.figure(figsize=(20,10))
marg_L = np.sum(post_eval,axis=0)
marg_L = marg_L/np.sum(marg_L)
plt.plot(eval_L.ravel(), marg_L, label='marginal_posterior')
plt.xlabel('$\lambda$')
plt.title('Marginal of Noise Space')
# plt.vlines(obs_data,0,100,'r', label='obs data')
# plt.vlines(lam,0,100,'k', label='lam true')
# plt.ylim([0,1])
plt.legend()
plt.show()
plt.figure(figsize=(20,10))
marg_E = np.sum(post_eval,axis=1)
marg_E = marg_E/np.sum(marg_E)
plt.plot(eval_E.ravel(), marg_E, label='marginal_posterior')
# plt.plot(eval_E, sstats.distributions.norm.pdf(eval_E, loc=0,scale=data_std))
plt.xlabel('$\epsilon$')
plt.title('Marginal of Data Space')
# plt.vlines(noise, 0, 200, 'r', label='noise')
# plt.vlines(0, 0, 200, label='mean zero')
plt.legend()
plt.show()<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup