import numpy as np
import pandas as pd
%matplotlib inline
import matplotlib.pyplot as plt
from lenstools.statistics.ensemble import Ensemble,Series
from lenstools.statistics.constraints import Emulator
from lenstools.statistics.contours import ContourPlot
/usr/local/lib/python2.7/site-packages/IPython/kernel/__init__.py:13: ShimWarning: The `IPython.kernel` package has been deprecated. You should import from ipykernel or jupyter_client instead. "You should import from ipykernel or jupyter_client instead.", ShimWarning)
p = np.outer(np.arange(10.0),np.ones(2))
f = np.outer(np.arange(10.0)+0.1*2,np.ones(5))
emulator = Emulator.from_features(f,p,parameter_index=[r"$\alpha$",r"$\beta$"],feature_index=[r"$f_{0}$".format(n) for n in range(5)])
emulator
parameters | features | ||||||
---|---|---|---|---|---|---|---|
$\alpha$ | $\beta$ | $f_0$ | $f_1$ | $f_2$ | $f_3$ | $f_4$ | |
0 | 0 | 0 | 0.2 | 0.2 | 0.2 | 0.2 | 0.2 |
1 | 1 | 1 | 1.2 | 1.2 | 1.2 | 1.2 | 1.2 |
2 | 2 | 2 | 2.2 | 2.2 | 2.2 | 2.2 | 2.2 |
3 | 3 | 3 | 3.2 | 3.2 | 3.2 | 3.2 | 3.2 |
4 | 4 | 4 | 4.2 | 4.2 | 4.2 | 4.2 | 4.2 |
5 | 5 | 5 | 5.2 | 5.2 | 5.2 | 5.2 | 5.2 |
6 | 6 | 6 | 6.2 | 6.2 | 6.2 | 6.2 | 6.2 |
7 | 7 | 7 | 7.2 | 7.2 | 7.2 | 7.2 | 7.2 |
8 | 8 | 8 | 8.2 | 8.2 | 8.2 | 8.2 | 8.2 |
9 | 9 | 9 | 9.2 | 9.2 | 9.2 | 9.2 | 9.2 |
test_feature = Series(np.ones(5)*4.0 + 0.05*np.random.randn(5),index=emulator[["features"]].columns)
Ensemble(test_feature).T
features | |||||
---|---|---|---|---|---|
$f_0$ | $f_1$ | $f_2$ | $f_3$ | $f_4$ | |
0 | 4.032221 | 3.951471 | 3.999335 | 3.952642 | 4.03128 |
features_covariance = Ensemble(np.eye(5)*0.5,index=test_feature.index,columns=test_feature.index)
features_covariance
features | ||||||
---|---|---|---|---|---|---|
$f_0$ | $f_1$ | $f_2$ | $f_3$ | $f_4$ | ||
features | $f_0$ | 0.5 | 0.0 | 0.0 | 0.0 | 0.0 |
$f_1$ | 0.0 | 0.5 | 0.0 | 0.0 | 0.0 | |
$f_2$ | 0.0 | 0.0 | 0.5 | 0.0 | 0.0 | |
$f_3$ | 0.0 | 0.0 | 0.0 | 0.5 | 0.0 | |
$f_4$ | 0.0 | 0.0 | 0.0 | 0.0 | 0.5 |
emulator.train()
g = np.arange(0.0,10.0,0.5)
p = np.array(np.meshgrid(g,g,indexing="ij")).reshape(2,400).T
test_parameters = Ensemble(p,columns=emulator.parameter_names)
test_parameters
$\alpha$ | $\beta$ | |
---|---|---|
0 | 0.0 | 0.0 |
1 | 0.0 | 0.5 |
2 | 0.0 | 1.0 |
3 | 0.0 | 1.5 |
4 | 0.0 | 2.0 |
5 | 0.0 | 2.5 |
6 | 0.0 | 3.0 |
7 | 0.0 | 3.5 |
8 | 0.0 | 4.0 |
9 | 0.0 | 4.5 |
10 | 0.0 | 5.0 |
11 | 0.0 | 5.5 |
12 | 0.0 | 6.0 |
13 | 0.0 | 6.5 |
14 | 0.0 | 7.0 |
15 | 0.0 | 7.5 |
16 | 0.0 | 8.0 |
17 | 0.0 | 8.5 |
18 | 0.0 | 9.0 |
19 | 0.0 | 9.5 |
20 | 0.5 | 0.0 |
21 | 0.5 | 0.5 |
22 | 0.5 | 1.0 |
23 | 0.5 | 1.5 |
24 | 0.5 | 2.0 |
25 | 0.5 | 2.5 |
26 | 0.5 | 3.0 |
27 | 0.5 | 3.5 |
28 | 0.5 | 4.0 |
29 | 0.5 | 4.5 |
... | ... | ... |
370 | 9.0 | 5.0 |
371 | 9.0 | 5.5 |
372 | 9.0 | 6.0 |
373 | 9.0 | 6.5 |
374 | 9.0 | 7.0 |
375 | 9.0 | 7.5 |
376 | 9.0 | 8.0 |
377 | 9.0 | 8.5 |
378 | 9.0 | 9.0 |
379 | 9.0 | 9.5 |
380 | 9.5 | 0.0 |
381 | 9.5 | 0.5 |
382 | 9.5 | 1.0 |
383 | 9.5 | 1.5 |
384 | 9.5 | 2.0 |
385 | 9.5 | 2.5 |
386 | 9.5 | 3.0 |
387 | 9.5 | 3.5 |
388 | 9.5 | 4.0 |
389 | 9.5 | 4.5 |
390 | 9.5 | 5.0 |
391 | 9.5 | 5.5 |
392 | 9.5 | 6.0 |
393 | 9.5 | 6.5 |
394 | 9.5 | 7.0 |
395 | 9.5 | 7.5 |
396 | 9.5 | 8.0 |
397 | 9.5 | 8.5 |
398 | 9.5 | 9.0 |
399 | 9.5 | 9.5 |
400 rows × 2 columns
scores = emulator.score(parameters=test_parameters,observed_feature=test_feature,features_covariance=features_covariance)
scores['features'] = np.exp(-0.5*scores['features'])
scores
$\alpha$ | $\beta$ | features | |
---|---|---|---|
0 | 0.0 | 0.0 | 5.625426e-32 |
1 | 0.0 | 0.5 | 3.521637e-28 |
2 | 0.0 | 1.0 | 4.897591e-24 |
3 | 0.0 | 1.5 | 5.708903e-20 |
4 | 0.0 | 2.0 | 3.206524e-16 |
5 | 0.0 | 2.5 | 7.267817e-13 |
6 | 0.0 | 3.0 | 6.592555e-10 |
7 | 0.0 | 3.5 | 2.413168e-07 |
8 | 0.0 | 4.0 | 3.500603e-05 |
9 | 0.0 | 4.5 | 1.950301e-03 |
10 | 0.0 | 5.0 | 4.061495e-02 |
11 | 0.0 | 5.5 | 3.108992e-01 |
12 | 0.0 | 6.0 | 8.681904e-01 |
13 | 0.0 | 6.5 | 8.835149e-01 |
14 | 0.0 | 7.0 | 3.288347e-01 |
15 | 0.0 | 7.5 | 4.508659e-02 |
16 | 0.0 | 8.0 | 2.300813e-03 |
17 | 0.0 | 8.5 | 4.426370e-05 |
18 | 0.0 | 9.0 | 3.258601e-07 |
19 | 0.0 | 9.5 | 9.333513e-10 |
20 | 0.5 | 0.0 | 3.521637e-28 |
21 | 0.5 | 0.5 | 1.209583e-24 |
22 | 0.5 | 1.0 | 6.669063e-21 |
23 | 0.5 | 1.5 | 2.628684e-17 |
24 | 0.5 | 2.0 | 5.055777e-14 |
25 | 0.5 | 2.5 | 4.427197e-11 |
26 | 0.5 | 3.0 | 1.797327e-08 |
27 | 0.5 | 3.5 | 3.326160e-06 |
28 | 0.5 | 4.0 | 2.657245e-04 |
29 | 0.5 | 4.5 | 8.654495e-03 |
... | ... | ... | ... |
370 | 9.0 | 5.0 | 7.636822e-25 |
371 | 9.0 | 5.5 | 4.866940e-28 |
372 | 9.0 | 6.0 | 1.501671e-31 |
373 | 9.0 | 6.5 | 2.181730e-35 |
374 | 9.0 | 7.0 | 1.445907e-39 |
375 | 9.0 | 7.5 | 4.257047e-44 |
376 | 9.0 | 8.0 | 5.623061e-49 |
377 | 9.0 | 8.5 | 3.629200e-54 |
378 | 9.0 | 9.0 | 1.352796e-59 |
379 | 9.0 | 9.5 | 3.544478e-65 |
380 | 9.5 | 0.0 | 9.333513e-10 |
381 | 9.5 | 0.5 | 1.050117e-10 |
382 | 9.5 | 1.0 | 7.895252e-12 |
383 | 9.5 | 1.5 | 3.832280e-13 |
384 | 9.5 | 2.0 | 1.158858e-14 |
385 | 9.5 | 2.5 | 2.105540e-16 |
386 | 9.5 | 3.0 | 2.216933e-18 |
387 | 9.5 | 3.5 | 1.305401e-20 |
388 | 9.5 | 4.0 | 4.152889e-23 |
389 | 9.5 | 4.5 | 6.906267e-26 |
390 | 9.5 | 5.0 | 5.819521e-29 |
391 | 9.5 | 5.5 | 2.412454e-32 |
392 | 9.5 | 6.0 | 4.779298e-36 |
393 | 9.5 | 6.5 | 4.392211e-40 |
394 | 9.5 | 7.0 | 1.821566e-44 |
395 | 9.5 | 7.5 | 3.373918e-49 |
396 | 9.5 | 8.0 | 2.894912e-54 |
397 | 9.5 | 8.5 | 1.286516e-59 |
398 | 9.5 | 9.0 | 3.544478e-65 |
399 | 9.5 | 9.5 | 7.336884e-71 |
400 rows × 3 columns
contour = ContourPlot.from_scores(scores,parameters=emulator.parameter_names)
contour.show()
contour.getLikelihoodValues([0.684],precision=0.1)
contour.plotContours(colors=["red"])
contour.labels()
/usr/local/lib/python2.7/site-packages/matplotlib/text.py:52: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal if rotation in ('horizontal', None): /usr/local/lib/python2.7/site-packages/matplotlib/text.py:54: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal elif rotation == 'vertical':