Getting Started
To demostrate basic usage of popclass we will mock some input microlensing event data and use a pre-loaded population model to classify the lens of the event. For a primer on microlensing see the microlensing source website.
The inputs to popclass are samples from a single event posterior distribution and their associated prior density. Let’s assume the posterior distribution is 10,000 samples from an uncorrelated gaussian in \(\log t_{E}- \log\pi_{E}\) centered on 2, and -1, with standard deviations of 0.1 and 0.5, respectively.
For simplicity, let’s also assume that an independent uniform prior with range [-3,3] in each parameter was used in the modeling so the prior density of each posterior sample is identical and equal to \(1/6 \times 1/6 \approx 0.028\).
[1]:
import numpy as np
from popclass.posterior import Posterior
from popclass.model import PopulationModel
from popclass.classify import classify
[2]:
NUM_POSTERIOR_SAMPLES = 10000
logtE_posterior_samples = np.random.normal(loc=2,scale=0.1, size=NUM_POSTERIOR_SAMPLES)
logpiE_posterior_samples = np.random.normal(loc=-1,scale=0.5, size=NUM_POSTERIOR_SAMPLES)
posterior_samples = np.vstack((logtE_posterior_samples,logpiE_posterior_samples)).swapaxes(0,1)
prior_density = 0.028 * np.ones(NUM_POSTERIOR_SAMPLES)
Now let’s load this data into a format popclass understands.
[3]:
posterior = Posterior(samples=posterior_samples, parameter_labels=['log10tE', 'log10piE'])
inference_data = posterior.to_inference_data(prior_density)
Now we will load in a readily-available (or named) population model. We will choose the PopSyCLE (Lam, 2020) population model with the sukhbold (Sukhbold, 2016) initial final mass relation.
[4]:
popsycle = PopulationModel.from_library('popsycle_singles_sukhboldn20')
We will now combine all of this information to classify the lens, given the popsycle model and the event \(\log t_{E}-\log\pi_{E}\) posterior.
[5]:
classification = classify(population_model=popsycle, inference_data=inference_data,
parameters =['log10tE', 'log10piE'])
print(classification)
{'black_hole': 0.0905788576625947, 'neutron_star': 0.0014221246262042565, 'star': 0.7070427946164506, 'white_dwarf': 0.20095622309475034}
classification is a dictionary of len class probabilities.
{"star": 0.4, "white dwarf": 0.3, "neutron star": 0.1, "black hole": 0.2}
For more advanced usage and a deeper dive into the details, please see the documentation tutorials.