This review wiki covers the changes to the code based in order to incorporate population priors (as opposed to the default LALInference prior) as well as associated updates to the error estimation.
## Motivation
The calculation is still structured in the same basic way as before (compare [LIGO-P2000216](https://dcc.ligo.org/LIGO-P2000216) / [arXiv:2007.01372](https://arxiv.org/abs/2007.01372) to [LIGO-T1900552](https://dcc.ligo.org/LIGO-T1900552) and [LIGO-T2000097](https://dcc.ligo.org/T2000097)).
In particular, we implement a Monte-Carlo integral via two nested loops to estimate an upper limit on the posterior probability that an object is a NS by asserting perfect knowledge of the overall mass distribution and assuming that everything below Mmax is a NS. A more thorough discussion of the assumptions and limitations are available in [LIGO-P2000216](https://dcc.ligo.org/LIGO-P2000216) / [arXiv:2007.01372](https://arxiv.org/abs/2007.01372).
The considerations within [LIGO-P2000216](https://dcc.ligo.org/LIGO-P2000216) / [arXiv:2007.01372](https://arxiv.org/abs/2007.01372) forced us to modify the code in several ways (see below) to estimate the impact of different overall mass distributions along with updated error estimates from the Monte-Carlo integrals.
## Changes to Implementation
Here, we briefly review the changes in the code relative to what was reviewed as part of the [GW190814 effort](GW190814-Review). The code changed in two main ways
* incorporation of population priors to reweight default posterior samples
* changes to error estimation associated with the fact that the samples now carry prior weights
In particular, we can see changes to the code relative to what was used for the GW190814 detection paper in [this comparison](https://git.ligo.org/reed.essick/mmax-model-selection/-/compare/1b0411beb7288d88b16bdd5c281caa09f5ceb755...master).
### Library Structure
The library consists of a single executable (`mmax-model-selection`) which relies on a single module (`utils.py`). The only external dependencies are `numpy` and standard Python modules. The library can be installed with the standard syntax
Beyond parsing the command-line options, `mmax-model-selection` is relatively straightforward. It proceeds as follows
* load the Mmax posterior samples along with any non-trivial weights associated therewith. These are specified through command-line options specifying the path to a CSV file and appropriate column names.
* loads the event's posterior samples and prunes them. Again, a path to a CSV, column names, and prior ranges are all specified as command-line options.
* Pruning is done to restrict the posterior to within certain prior ranges and is typically not necessary. However, occassionally bad PE samples will contain outliers (e.g., negative component masses) that we would like to discard.
* Compute population prior weights based on the assumed overall mass distribution. We implement a small set of possible population models, and user specify which they want along with the relevant parameters through the command-line options.
* this is accomplished through a delegation to [utils.population_weights](https://git.ligo.org/reed.essick/mmax-model-selection/-/blob/master/mmax_model_selection/utils.py#L107), which is little more than a set of nested conditionals that set up population parameters before evaluating the ratio of prior probabilities (between the target prior and the one used to generate the event's posterior samples) for the
* masses: [single-object mass distribution](https://git.ligo.org/reed.essick/mmax-model-selection/-/blob/master/mmax_model_selection/utils.py#L86) and [pairing probability](https://git.ligo.org/reed.essick/mmax-model-selection/-/blob/master/mmax_model_selection/utils.py#L97)
* distance: [uniform in euclidean volume](https://git.ligo.org/reed.essick/mmax-model-selection/-/blob/master/mmax_model_selection/utils.py#L100). *Note* we do not currently incorporate cosmological models to get the distribution in comoving volume.
* Compute the posterior odds and the posterior probability, along with error estimates through a delegation to [utils.prob_odds](https://git.ligo.org/reed.essick/mmax-model-selection/-/blob/master/mmax_model_selection/utils.py#L335). Because the Odds ratio and posterior odds are estimated using many of the same calculations (see Appendix of [LIGO-P2000216](https://dcc.ligo.org/LIGO-P2000216) / [arXiv:2007.01372](https://arxiv.org/abs/2007.01372), these are estimated within the same function call).
* this computes the expected value and standard deviation through nested Monte-Carlo integrals over weighed samples.