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]
v_west:  125.144111 +/- 30.723486
v_north: -73.712271 +/- 28.466936
xh, yh, zh, vxh, vyh, vzh =  [-0.37081737 -0.37392858 -0.38337424 ..., -0.39236694 -0.35824388
 -0.38359084] [ 0.61291005  0.61805246  0.63366483 ...,  0.64852852  0.59212781
  0.63402283] [-0.28323451 -0.28561089 -0.29282559 ..., -0.29969431 -0.27363074
 -0.29299102] [ 83.88287902  20.89262847  64.79230876 ...,  86.12160741  85.13309577
  80.60291601] [-323.10033149 -360.14176574 -330.70607548 ..., -300.48820472 -303.23165254
 -321.97162555] [  8.44469992  12.54748118  18.89039299 ...,  49.25300642  49.23564902
  18.90210142]
localgroup/halo.py:134: 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.73418056814863952), (0.5, 0.77413717529872095), (0.84, 0.81391569351083914)]
Quantiles:
[(0.16, -113.46262460764024), (0.5, -109.08364419534806), (0.84, -104.68683876375775)]
Quantiles:
[(0.16, 18.94983332215601), (0.5, 37.644555172652304), (0.84, 61.309015613022495)]

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 0x9ccab90>

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]:
#figure_obs.savefig("/afs/slac.stanford.edu/u/ki/mwillia1/Thesis/LocalGroupHaloProps/doc/thesis/plots/model_gof.png")

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 [17]:
path = '/afs/slac.stanford.edu/u/ki/mwillia1/Thesis/data_files/complete_triplets.txt'
#path = '/afs/slac.stanford.edu/u/ki/mwillia1/Thesis/data_files/MW_M31_pairs.txt'
npoints = 122000
halo_props = ['MW_Mvir', 'M31_Mvir', 'M33_Mvir']

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

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

In [20]:
Tr.mass_filter('sim')


sim_samples new shape:  (62816, 3)

In [21]:
Tr.dist_filter((Tr.sim_samples[:,0] < 10))


sim_sample length before:  (62816, 3)
sim_sample length after:  (62096, 3)
Out[21]:
<matplotlib.axes._subplots.AxesSubplot at 0xfb4c610>

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

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


Quantiles:
[(0.16, 0.56299670336384688), (0.5, 0.84804127255100914), (0.84, 1.0782950431118372)]
Quantiles:
[(0.16, -153.64577285607692), (0.5, -82.864210577066544), (0.84, -28.670941080127328)]
Quantiles:
[(0.16, 26.019828330387853), (0.5, 59.20887603018825), (0.84, 118.35968485671467)]

In [24]:
#sim_plot = Tr.plot_kinematics('sim', L.samples_means, L.samples_stds, color='c', fig=None)
Tr.unprocess(L.samples_means, L.samples_stds, mode='sim')
data = np.transpose(np.vstack((np.transpose(Tr.sim_samples), np.log10(Tr.MW.Mvir), np.log10(Tr.M31.Mvir))))
labs=["mwd", "mwvr", "mwvt", "MWMvir", "M31Mvir"]
sim_plot = triangle.corner(data, labels=labs, quantiles=[0.16,0.5,0.84], fig=None, weights=None,\
                         plot_contours=True, show_titles=True, title_args={"fontsize": 12}, \
                         plot_datapoints=False, bins=20, color='r', label_kwargs={"fontsize": 16})
red_patch = mpatches.Patch(color='r')
cyan_patch = mpatches.Patch(color='c')
sim_plot.legend(handles=[red_patch, cyan_patch], labels=["CONSUELO Prior", "GMM-fit CONSUELO Prior"])
Tr.preprocess(L.samples_means, L.samples_stds, mode='sim')


Quantiles:
[(0.16, 0.56299670336384688), (0.5, 0.84804127255100914), (0.84, 1.0782950431118372)]
Quantiles:
[(0.16, -153.64577285607692), (0.5, -82.864210577066544), (0.84, -28.670941080127328)]
Quantiles:
[(0.16, 26.019828330387853), (0.5, 59.20887603018825), (0.84, 118.35968485671467)]
Quantiles:
[(0.16, 11.456930552602447), (0.5, 11.773899756199135), (0.84, 12.151001907992832)]
Quantiles:
[(0.16, 11.722013293609216), (0.5, 12.149357695164209), (0.84, 12.572432440891294)]

In [25]:
sim_plot


Out[25]:

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

In [27]:
dat = np.transpose(np.vstack((np.transpose(Tr.sim_samples), np.log10(Tr.M31.Mvir), np.log10(Tr.MW.Mvir))))
Tr.GMM(40, dat)

In [33]:
Tr.GMM_sample(12200000)


gmm_MW = np.copy(Tr.gmm_samples[:,4])
gmm_M31 = np.copy(Tr.gmm_samples[:,3])
gmm_LG = np.log10(np.power(10,gmm_MW) + np.power(10,gmm_M31))

cond = gmm_MW < gmm_M31
Tr.gmm_samples = Tr.gmm_samples[cond]
gmm_MW = gmm_MW[cond]
gmm_M31 = gmm_M31[cond]
gmm_LG = gmm_LG[cond]

Tr.gmm_samples = Tr.gmm_samples[:,0:3]

In [34]:
Tr.compute_model_weights(L, 'gmm')

In [35]:
Tr.calculate_N95()


Out[35]:
211089

In [ ]:


In [36]:
Tr.unprocess(L.samples_means, L.samples_stds, 'gmm')
data2 = np.transpose(np.vstack((np.transpose(Tr.gmm_samples), gmm_MW, gmm_M31)))
labs=["mwd", "mwvr", "mwvt", "MWMvir", "M31Mvir"]
pl = triangle.corner(data2, labels=labs, quantiles=[0.16,0.5,0.84], fig=None, weights=None,\
                         plot_contours=True, show_titles=True, title_args={"fontsize": 12}, \
                         plot_datapoints=False, bins=20, color='c')
Tr.preprocess(L.samples_means, L.samples_stds, mode='gmm')


Quantiles:
[(0.16, 0.56789529654061577), (0.5, 0.84803175489644489), (0.84, 1.076429464286087)]
Quantiles:
[(0.16, -154.54184403908209), (0.5, -83.940679508066751), (0.84, -29.876560471516548)]
Quantiles:
[(0.16, 26.623281781927496), (0.5, 59.637351713270469), (0.84, 118.45867536745037)]
Quantiles:
[(0.16, 11.459682766765436), (0.5, 11.768713756916725), (0.84, 12.136383674619864)]
Quantiles:
[(0.16, 11.748874160647848), (0.5, 12.163511074080986), (0.84, 12.584225135070195)]

In [ ]:


In [37]:
labs = ["MWMvir", "M31Mvir", "MW+M31"]
all_mvir = np.transpose(np.vstack((gmm_MW, gmm_M31, gmm_LG)))
figure = triangle.corner(all_mvir, labels=labs, quantiles=[0.16,0.5,0.84], fig=None, weights=Tr.weights,\
                         plot_contours=True, show_titles=True, title_kwargs={"fontsize": 12}, \
                         plot_datapoints=False, bins=20, color='red')
#figure = triangle.corner(all_mvir, labels=labs, quantiles=[0.16,0.5,0.84], fig=None, show_titles=True, title_args={"fontsize": 12}, color='g')


Quantiles:
[(0.16, 11.536223972309328), (0.5, 11.786434863303205), (0.84, 12.036125163592976)]
Quantiles:
[(0.16, 11.922495103693963), (0.5, 12.198049209447086), (0.84, 12.382765398531946)]
Quantiles:
[(0.16, 12.121245475548005), (0.5, 12.360606321017599), (0.84, 12.520566983556996)]

In [ ]: