Local Group Halo Properties: Demo Inference

We approximate the local group distance, radial velocity and proper motion likelihood function by sampling from the posterior distributions for these variables reported in the literature and transforming to kinematic variables in the M31-centric coordinate system.


In [1]:
%matplotlib inline
import localgroup
import triangle
import sklearn
from sklearn import mixture
import numpy as np
import pickle
import matplotlib.patches as mpatches

Inside the Likelihood object is a "triplet" object called T, which contains an array of sample local groups, each with kinematic parameters consistent with the observational data. Let's plot these kinematic parameters in a "triangle" figure, to show all their 1 and 2-D marginal distributions.


In [2]:
L = localgroup.Likelihood(isPair=True)
L.generate(Nsamples=200000)


Inside method: heliocentric_equatorial_spherical_to_galactocentric_cartesian
l =  [ 121.17440269  121.17440269  121.17440269 ...,  121.17440269  121.17440269
  121.17440269]
b =  [-21.57299867 -21.57299867 -21.57299867 ..., -21.57299867 -21.57299867
 -21.57299867]
mu_l = -125.303442 +/- 30.799672
mu_b = -73.808082 +/- 28.400333
v_west:  125.303442 +/- 30.799672
v_north: -73.808082 +/- 28.400333
xh, yh, zh, vxh, vyh, vzh =  [-0.35393277 -0.36673656 -0.37782385 ..., -0.38354089 -0.3652727
 -0.36930436] [ 0.58500213  0.60616504  0.6244908  ...,  0.63394029  0.60374548
  0.61040926] [-0.27033785 -0.28011754 -0.28858614 ..., -0.29295288 -0.27899943
 -0.28207885] [ 53.56447789  22.66583603  29.85425525 ...,  60.89206229  13.61353981
  71.14749652] [-316.76174823 -359.90100093 -347.6593149  ..., -332.36252023 -339.74521062
 -309.23784958] [ 65.67697021  13.36618103  27.23500655 ...,  22.10672528  64.18066513
  58.24773679]
localgroup/halo.py:135: RuntimeWarning: invalid value encountered in divide
  self.v_r = (self.x*self.vx + self.y*self.vy + self.z*self.vz)/self.D

In [3]:
L.set_PDF(mixture.GMM(n_components=10, covariance_type='full'))
L.approximate()

In [4]:
figure_obs = L.plot_samples(10, color='b', overlay=False)


Quantiles:
[(0.16, 0.73399316952250726), (0.5, 0.77379653961789541), (0.84, 0.81360300530492524)]
Quantiles:
[(0.16, -113.46249351324595), (0.5, -109.08030766031318), (0.84, -104.69673842774021)]
Quantiles:
[(0.16, 18.834241705275883), (0.5, 37.602907796582727), (0.84, 61.091133905879708)]

The above plot shows a Gaussian Mixture model fitted Gaussians. The shaded regions show two standard deviations. The samples data has been preprocessed to zero the mean and scale by standard deviation. Since we are using the Gaussian Mixture Model to model the underlying PDF of the data, more components is always better.

How to evaluate goodness of fit:

Due to lack of a standard goodness of fit test for GMM's, the best we can do is graphically show that the model reproduces the data well. We proceed by drawing a set of points from the fitted model, where each point is a local group with (MW_D, MW_vr, MW_vt, M33_D, M33_vr, M33_vt). We then plot the 1D and 2D marginalizations of the drawn point set and show that the marginalizations match the marginalizations of the true data.


In [5]:
figure_model = L.model_gof(L.T.Nsamples, color="r", fig=None)



In [6]:
L.model_gof(L.T.Nsamples, color="r", fig=figure_obs)
red_patch = mpatches.Patch(color='red')
blue_patch = mpatches.Patch(color='blue')
figure_obs.legend(handles=[red_patch, blue_patch], labels=["Model Generated", "Observation Generated"])


Out[6]:
<matplotlib.legend.Legend at 0x9bf6410>

In [7]:
figure_obs


Out[7]:

The above plot shows that the points drawn from the model create a population that is very similar to the true data.


In [8]:
#name = "likelihood_fit.png"
#figure_obs.savefig("/afs/slac.stanford.edu/u/ki/mwillia1/Thesis/LocalGroupHaloProps/doc/thesis/plots/final_plots/Pair_LGMM_GOF.pdf", dpi=1200)

Reading Simulation Points:

Below we read the preconfigured files containing the Consuelo (soon to be Dark Sky) Local Group analogs into a Triplet object. We plot the marginalizations of the simulation data, which allows us to compare with the LG prior.


In [49]:
path = '/lustre/ki/pfs/mwillia1/LG_project/Consuelo_Boxes/4001/quad_dat_M31_larger_bgc2.npy'
#path = '/afs/slac.stanford.edu/u/ki/mwillia1/Thesis/data_files/MW_M31_pairs.txt'
npoints = 5000
halo_props = ['MW_Mvir', 'M31_Mvir', 'M33_Mvir']

In [50]:
Tr = localgroup.Triplet(isPair=True)
Tr.read_sim_points(path, npoints, halo_props, h=0.7, a=1.0, npy=True)

In [51]:
Tr.transform_to_M31(sim=True)

In [52]:
#Tr.mass_filter('sim')

In [53]:
Tr.dist_filter((Tr.sim_samples[:,0] < 1))


sim_sample length before:  (5000, 3)
sim_sample length after:  (4983, 3)
Out[53]:
<matplotlib.axes._subplots.AxesSubplot at 0xaeb4a50>

In [54]:
Tr.preprocess(L.samples_means, L.samples_stds, mode='sim')

In [55]:
sim_plot = Tr.plot_kinematics('sim', L.samples_means, L.samples_stds, color='c', fig=None)


Quantiles:
[(0.16, 0.32696442760905176), (0.5, 0.60001403716592006), (0.84, 0.87381245452677714)]
Quantiles:
[(0.16, -268.72688720296503), (0.5, -132.89318707662417), (0.84, -43.689350685683912)]
Quantiles:
[(0.16, 41.944698510790005), (0.5, 99.086208272361546), (0.84, 211.20350145378532)]

In [56]:
Tr.plot_kinematics('sim', L.samples_means, L.samples_stds, color='g', fig=figure_model)


Quantiles:
[(0.16, 0.32696442760905176), (0.5, 0.60001403716592006), (0.84, 0.87381245452677714)]
Quantiles:
[(0.16, -268.72688720296503), (0.5, -132.89318707662417), (0.84, -43.689350685683912)]
Quantiles:
[(0.16, 41.944698510790005), (0.5, 99.086208272361546), (0.84, 211.20350145378532)]
Out[56]:

In [57]:
red_patch = mpatches.Patch(color='red')
green_patch = mpatches.Patch(color='green')
figure_model.legend(handles=[red_patch, green_patch], labels=["Model Generated", "Consuelo Triplets"])
figure_model


Out[57]:

In [58]:
#name = 'trips_000_054_like_prior.png'
#sim_plot.savefig('/afs/slac.stanford.edu/u/ki/mwillia1/Thesis/LocalGroupHaloProps/doc/thesis/plots/asurps/'+name)

In [59]:
Tr.compute_model_weights(L, "sim")

In [60]:
N95 = Tr.calculate_N95()
N95


Out[60]:
(44, 0.0023723283984876434)

In [14]:
MW_C200 = Tr.calculate_cvir_to_c200(Tr.MW.Cvir)
M31_C200 = Tr.calculate_cvir_to_c200(Tr.M31.Cvir)
#M33_C200 = Tr.calculate_cvir_to_c200(Tr.M33.Cvir)

MW_M200 = Tr.calculate_Mvir_to_M200(Tr.MW.Mvir, Tr.MW.Cvir, MW_C200)
M31_M200 = Tr.calculate_Mvir_to_M200(Tr.M31.Mvir, Tr.M31.Cvir, M31_C200)
#M33_M200 = Tr.calculate_Mvir_to_M200(Tr.M33.Mvir, Tr.M33.Cvir, M33_C200)

total_200 = M31_M200+MW_M200

In [61]:
total = Tr.MW.Mvir + Tr.M31.Mvir
all_mvir = np.log10(np.transpose(np.vstack((Tr.MW.Mvir, Tr.M31.Mvir, total))))
labs = ["$M_{MW}$", "$M_{M31}$", "$M_{LG}$"]
#total = MW_M200 + M31_M200
#all_mvir = np.log10(np.transpose(np.vstack((MW_M200, M31_M200, total))))
#labs = ["MW Mvir", "M31 Mvir", "MW+M31"]

In [26]:
all_mvir = np.transpose(np.vstack((Tr.MW.Cvir, Tr.M31.Cvir)))
labs = ["$Cvir_{MW}$", "$Cvir_{M31}$"]

In [13]:
all_mvir.shape


Out[13]:
(797329, 3)

In [48]:
figure = triangle.corner(all_mvir, labels=labs, quantiles=[0.16,0.5,0.84], fig=None, weights=np.transpose(Tr.weights),\
                         plot_contours=True, show_titles=True, title_args={"fontsize": 16}, label_args={"fontsize": 16},\
                         plot_datapoints=False, bins=20, color='k')


Quantiles:
[(0.16, 11.591965667864686), (0.5, 11.791697665029389), (0.84, 12.14407071737269)]
Quantiles:
[(0.16, 11.930407115450917), (0.5, 12.446070935701005), (0.84, 12.592123077724755)]
Quantiles:
[(0.16, 12.163910863191841), (0.5, 12.544548665675919), (0.84, 12.661950766732591)]

In [17]:
h = np.load('/lustre/ki/pfs/mwillia1/LG_project/Consuelo_Boxes/4002/4002hlist.npy')

In [21]:
mw_h = h[np.abs(np.log10(h['mvir'])-11.7) < .1]
m31_h = h[np.abs(np.log10(h['mvir'])-12) < .1]
m33_h = h[np.abs(np.log10(h['mvir'])-10.8) < .1]

In [22]:
mwc = mw_h['rvir']/mw_h['rs']
m31c = m31_h['rvir']/m31_h['rs']
m33c = m33_h['rvir']/m33_h['rs']

mwc.shape, m31c.shape, m33c.shape


Out[22]:
((217665,), (117899,), (1122183,))

In [23]:
mwc = mwc[0:100000]
m31c = m31c[0:100000]
m33c = m33c[0:100000]

In [28]:
all_mvir = np.transpose(np.vstack((mwc, m31c)))
labs = ["$Cvir_{MW}$", "$Cvir_{M31}$", "$Cvir_{M33}$"]

In [30]:
figure_c = triangle.corner(all_mvir, labels=labs, quantiles=[0.,0.5,0.84], fig=figure, weights=None,\
                         plot_contours=True, show_titles=True, title_args={"fontsize": 16}, label_args={"fontsize": 16},\
                         plot_datapoints=False, bins=20, color='k')


Quantiles:
[(0.0, 2.1626035287540142), (0.5, 9.7768424877369338), (0.84, 13.064559736233724)]
Quantiles:
[(0.0, 2.1626225121906293), (0.5, 9.3402476001345551), (0.84, 12.231018804621753)]

In [62]:
figure2 = triangle.corner(all_mvir, labels=labs, quantiles=[0.16,0.5,0.84], fig=figure, weights=Tr.weights,\
                         plot_contours=True, show_titles=False, title_args={"fontsize": 12}, \
                         plot_datapoints=False, bins=20, color='r')


Quantiles:
[(0.16, 11.766102632238333), (0.5, 12.106313312282849), (0.84, 12.271869474806953)]
Quantiles:
[(0.16, 11.983218949786723), (0.5, 12.357761368222771), (0.84, 12.54441534103564)]
Quantiles:
[(0.16, 12.269246565679271), (0.5, 12.569056245757798), (0.84, 12.730423569681577)]

In [63]:
figure


Out[63]:

In [64]:
red_patch = mpatches.Patch(color='red')
green_patch = mpatches.Patch(color='k')
figure.legend(handles=[red_patch, green_patch], labels=["Box 4001 bgc2", "Box 4001 hlist"])
figure


Out[64]:

In [ ]:

1D posterior work


In [110]:
Tr.weights.shape


Out[110]:
(120645,)

In [66]:
xdata = total
plot(xdata, Tr.weights)
xscale('log')



In [67]:
bins = 20
xbins = np.logspace(np.log10(xdata.min()), np.log10(xdata.max()), bins)
ybins = [np.sum(Tr.weights[(xdata[:]>xbins[i]) & (xdata[:]<xbins[i+1])]) for i in range(bins-1)]
print len(xbins)
print len(ybins)
print len(xbins[:bins-1])


20
19
19

In [68]:
plot(xbins[:bins-1], ybins)
xscale('log')



In [40]:
xtrip = np.copy(xbins[:bins-1])
ytrip = np.copy(ybins)

In [45]:
xtripmw = np.copy(xbins[:bins-1])
ytripmw = np.copy(ybins)

In [65]:
xpairmw = np.copy(xbins[:bins-1])
ypairmw = np.copy(ybins)

In [69]:
xpair = np.copy(xbins[:bins-1])
ypair = np.copy(ybins)

In [80]:
plot(xtripmw, ytripmw, color='r')
plot(xpairmw, ypairmw, color='b')
ylabel('P(MMW)')
xlabel('MMW')

red_patch = mpatches.Patch(color='red')
blue_patch = mpatches.Patch(color='blue')
legend(["Trips, M33 dynamics", "Pairs, M33 existence"])
xscale('log')
#savefig("/afs/slac.stanford.edu/u/ki/mwillia1/Thesis/LocalGroupHaloProps/doc/thesis/plots/pdf_mw_plot.png")



In [ ]:


In [ ]: