// construct PMF with the given background and delta, from a PMF representing the observed profile. // if pmf unknown (empty) return the background // NB The input PMF need NOT be normalized. The returned PMF is normalized. // static PMF<Allele> makePMF(const PMF<Allele> &pmf, const PMF<Allele> &background, float delta, bool sparse) { // How much background to add in? // If the input PMF is not normalized then we make up the difference // with background. Otherwise we add in delta. double bglevel = std::max((double)delta, 1 - pmf.sum()); PMF<Allele> ret; if (!sparse) { // This implementation ensures there is an element of the // returned PMF for each element of the background ret = background; if (! pmf.empty()) { ret *= bglevel; ret += pmf; ret.normalize(); } Assert2(ret.size() == background.size(), "PMF contains unknown alleles"); } else { // This implementation allows the PMF (and therefore the HMatrix) to remain sparse if (pmf.empty()) { ret = background; } else if (bglevel == 0) { ret = pmf; ret.normalize(); } else { ret = background; ret *= bglevel; ret += pmf; ret.normalize(); } } // cout << "pmf = " << pmf << endl; // cout << "background = " << background << endl; // cout << "bglevel = " << bglevel << endl; // cout << "ret = " << ret << endl << endl; return ret; }