%matplotlib inline

import matplotlib.pyplot as plt
import numpy as np

test = np.loadtxt('justStest.txt')
seed_S = 0.1570168038792813

plt.hist(test[:,0], bins=20, alpha=0.6, normed=True);
plt.title('$S$ Samples')
plt.xlabel('$S$')
plt.ylabel('Density')
plt.gca().axvline(seed_S, color='k', label='seed S')
plt.legend(loc=2);

plt.hist(test[:,1], bins=20, alpha=0.6, normed=True);
plt.title('Log-Likelihood Weights')
plt.xlabel('Log-Likelihood')
plt.ylabel('Density')

plt.hist(test[:,0], bins=20, alpha=0.6, normed=True, label='prior');
plt.hist(test[:,0], bins=20, alpha=0.6, \
         weights=((test[:,1] - test[:,1].min()) / (test[:,1].max() - test[:,1].min())),\
         normed=True,\
         label='l-weighted'
        );
plt.title('Log-Likelihood Weighted Samples')
plt.xlabel('$S$')
plt.ylabel('Weight')
plt.gca().axvline(seed_S, color='k', label='seed S')
plt.gca().axvline(test[:,0][np.argmax(test[:,1])], color='r', label='highest weight')
plt.legend(loc=2);

w = np.exp((test[:,1] - test[:,1].max()))
plt.hist(test[:,0], bins=20, alpha=0.6, normed=True, label='prior');
plt.hist(test[:,0], bins=20, alpha=0.6, \
         weights=w,\
         normed=True,\
         label='L-weighted'
        );
plt.title('Likelihood Weighted Samples')
plt.xlabel('$S$')
plt.ylabel('Weight')
plt.gca().axvline(seed_S, color='k', label='seed S')
plt.gca().axvline(test[:,0][np.argmax(test[:,1])], color='r', label='highest weight')
plt.legend(loc=2);

print np.min(w), np.max(w), np.sort(w)[-10:]

"""
Explanation: Validating Simpler Model
In order to confirm our hypothesis that our process is not currently able generate meaningful posteriors, we further simplify the model and investigate its performance.
Contents:
- Model
- Results
- Discussion
Model
We fix the hyper-parameters $\alpha$ and infer the hyper-posterior of $S$. We make these changes and then run this new model over the cluster, generating 960 samples that we analyze below.
Results
End of explanation
"""


np.sort(test[:,1])[::-1][:10]

"""
Explanation: We see that a few samples dominate the weight contribution.
End of explanation
"""


