29#include "pod_vector.h"
67 const double* _masses,
91 inline const double* get_lProbs()
const {
return atom_lProbs; }
176 inline void ensureModeConf() {
if (
mode_conf ==
nullptr) setupMode(); }
188 std::priority_queue<ProbAndConfPtr, pod_vector<ProbAndConfPtr> > pq;
195 const double min_lprob;
196 size_t current_bucket;
197 size_t initialized_until;
200 bool add_next_conf();
202 size_t bucket_no(
double lprob) {
return static_cast<size_t>( (
mode_lprob - lprob) * 100.0 ); }
228 while(current_count <= idx)
243 inline const pod_vector<Conf>& confs()
const {
return _confs; }
264 unsigned int no_confs;
296 inline bool inRange(
unsigned int idx)
const {
return idx < no_confs; }
303 inline const double&
get_lProb(
int idx)
const {
return lProbs[idx]; }
310 inline const double&
get_prob(
int idx)
const {
return probs[idx]; }
317 inline const double&
get_mass(
int idx)
const {
return masses[idx]; }
337 inline const Conf&
get_conf(
int idx)
const {
return confs[idx]; }
361 double current_threshold;
371 double* guarded_lProbs;
389 bool extend(
double new_threshold,
bool do_sort =
true);
392 inline double get_lProb(
int idx)
const {
return guarded_lProbs[idx]; }
395 inline double get_prob(
int idx)
const {
return probs[idx]; }
398 inline double get_mass(
int idx)
const {
return masses[idx]; }
404 inline const Conf&
get_conf(
int idx)
const {
return configurations[idx]; }
407 inline unsigned int get_no_confs()
const {
return configurations.size(); }
432template <
bool add_guards>
436 double current_threshold;
441 double* guarded_lProbs;
458 bool extend(
double new_threshold, [[maybe_unused]]
bool do_sort =
true) {
459 static_assert(add_guards,
"SingleAtomMarginal::extend: add_guards must be true");
460 current_threshold = new_threshold;
461 bool extended =
false;
462 while(guarded_lProbs[extended_to_idx] >= current_threshold)
467 return extended || (guarded_lProbs[extended_to_idx] != -std::numeric_limits<double>::infinity());
471 inline double get_lProb(
int idx)
const {
return guarded_lProbs[idx]; }
474 inline double get_prob(
int idx)
const {
return probs[idx]; }
477 inline double get_mass(
int idx)
const {
return masses[idx]; }
483 inline const Conf&
get_conf([[maybe_unused]]
int idx)
const {
throw std::logic_error(
"SingleAtomMarginal.get_conf: not implemented"); }
487 if constexpr(add_guards)
488 return extended_to_idx;
490 return static_cast<unsigned int>(original_indexes.size());}
493 inline double get_min_mass()
const {
throw std::logic_error(
"SingleAtomMarginal.get_min_mass: not implemented"); };
496 double get_max_mass()
const {
throw std::logic_error(
"SingleAtomMarginal.get_max_mass: not implemented"); };
504 inline bool probeConfigurationIdx(
int idx)
506 return idx < static_cast<int>(original_indexes.size());
509 const pod_vector<double>& conf_masses()
const {
return masses; }
511 int get_original_position(
int idx)
const
514 if (idx < 0 ||
static_cast<size_t>(idx) >= original_indexes.size())
515 throw std::out_of_range(
"Index out of range in SingleAtomMarginal::et_original_position");
517 return original_indexes[idx];
528 std::unique_ptr<T> real_marginal;
532 LoggingMarginal(T&& m) :
Marginal(m), real_marginal(std::make_unique(std::move(m))) {}
533 LoggingMarginal(T&& m,
int tabSize,
int hashSize)
534 :
Marginal(m), real_marginal(std::make_unique<T>(std::move(m), tabSize, hashSize)) {}
536 LoggingMarginal(
const LoggingMarginal& other) =
delete;
537 LoggingMarginal& operator=(
const LoggingMarginal& other) =
delete;
539 inline double getModeLProb()
const {
auto ret = real_marginal->getModeLProb(); std::cout <<
"LoggingMarginal::getModeLProb: " << ret << std::endl;
return ret; }
540 inline double get_lProb(
int idx)
const {
auto ret = real_marginal->get_lProb(idx); std::cout <<
"LoggingMarginal::get_lProb: " << idx <<
" " << ret << std::endl;
return ret; }
541 inline double get_prob(
int idx)
const {
auto ret = real_marginal->get_prob(idx); std::cout <<
"LoggingMarginal::get_prob: " << idx <<
" " << ret << std::endl;
return ret; }
542 inline double get_mass(
int idx)
const {
auto ret = real_marginal->get_mass(idx); std::cout <<
"LoggingMarginal::get_mass: " << idx <<
" " << ret << std::endl;
return ret; }
543 inline const double* get_lProbs_ptr()
const {
auto ret = real_marginal->get_lProbs_ptr(); std::cout <<
"LoggingMarginal::get_lProbs_ptr: "; printArray<double>(ret, real_marginal->get_no_confs());
return ret; }
544 inline const Conf& get_conf(
int idx)
const {
auto ret = real_marginal->get_conf(idx); std::cout <<
"LoggingMarginal::get_conf: " << idx << std::endl;
return ret; }
545 inline unsigned int get_no_confs()
const {
auto ret = real_marginal->get_no_confs(); std::cout <<
"LoggingMarginal::get_no_confs: " << ret << std::endl;
return ret; }
546 inline bool probeConfigurationIdx(
int idx) {
auto ret = real_marginal->probeConfigurationIdx(idx); std::cout <<
"LoggingMarginal::probeConfigurationIdx: " << idx <<
" " << ret << std::endl;
return ret; }
547 inline double get_min_mass()
const {
auto ret = real_marginal->get_min_mass(); std::cout <<
"LoggingMarginal::get_min_mass: " << ret << std::endl;
return ret; }
548 inline double get_max_mass()
const {
auto ret = real_marginal->get_max_mass(); std::cout <<
"LoggingMarginal::get_max_mass: " << ret << std::endl;
return ret; }
549 inline double getModeMass()
const {
auto ret = real_marginal->getModeMass(); std::cout <<
"LoggingMarginal::getModeMass: " << ret << std::endl;
return ret; }
550 inline double getLightestConfMass()
const {
auto ret = real_marginal->getLightestConfMass(); std::cout <<
"LoggingMarginal::getLightestConfMass: " << ret << std::endl;
return ret; }
551 inline double getHeaviestConfMass()
const {
auto ret = real_marginal->getHeaviestConfMass(); std::cout <<
"LoggingMarginal::getHeaviestConfMass: " << ret << std::endl;
return ret; }
552 inline double getMonoisotopicConfMass()
const {
auto ret = real_marginal->getMonoisotopicConfMass(); std::cout <<
"LoggingMarginal::getMonoisotopicConfMass: " << ret << std::endl;
return ret; }
553 inline double getAtomAverageMass()
const {
auto ret = real_marginal->getAtomAverageMass(); std::cout <<
"LoggingMarginal::getAtomAverageMass: " << ret << std::endl;
return ret; }
554 inline double variance()
const {
auto ret = real_marginal->variance(); std::cout <<
"LoggingMarginal::variance: " << ret << std::endl;
return ret; }
555 inline double getTheoreticalAverageMass()
const {
auto ret = real_marginal->getTheoreticalAverageMass(); std::cout <<
"LoggingMarginal::getTheoreticalAverageMass: " << ret << std::endl;
return ret; }
556 inline double getLogSizeEstimate(
double logEllipsoidRadius)
const
558 auto ret = real_marginal->getLogSizeEstimate(logEllipsoidRadius);
559 std::cout <<
"LoggingMarginal::getLogSizeEstimate: " << logEllipsoidRadius <<
" " << ret << std::endl;
562 inline void ensureModeConf() { real_marginal->ensureModeConf(); std::cout <<
"LoggingMarginal::ensureModeConf" << std::endl; }
563 inline const pod_vector<double>& conf_lprobs()
const {
return real_marginal->conf_lprobs(); }
564 inline const pod_vector<double>& conf_masses()
const {
return real_marginal->conf_masses(); }
565 inline int get_original_position(
int idx)
const {
return real_marginal->get_original_position(idx); }
566 inline int get_isotopeNo()
const {
return real_marginal->get_isotopeNo(); }
567 inline const double* get_lProbs()
const {
return real_marginal->get_lProbs(); }
568 inline const double* get_masses()
const {
return real_marginal->get_masses(); }
569 inline const double* get_atom_lProbs()
const {
return real_marginal->get_lProbs(); }
570 inline const double* get_atom_masses()
const {
return real_marginal->get_masses(); }
571 inline bool extend(
double new_threshold,
bool do_sort =
true)
573 auto ret = real_marginal->extend(new_threshold, do_sort);
574 std::cout <<
"LoggingMarginal::extend: " << new_threshold <<
" " << ret << std::endl;
double get_mass(int idx) const
get the mass of the idx-th subisotopologue, see details in PrecalculatedMarginal::get_mass.
double get_prob(int idx) const
get the probability of the idx-th subisotopologue, see details in PrecalculatedMarginal::get_eProb.
bool extend(double new_threshold, bool do_sort=true)
Extend the set of computed subisotopologues to those above the new threshold.
unsigned int get_no_confs() const
Get the number of precomputed subisotopologues, see details in PrecalculatedMarginal::get_no_confs.
double get_max_mass() const
Get the maximal mass in current layer.
double get_min_mass() const
Get the minimal mass in current layer.
const double * get_lProbs_ptr() const
get the pointer to lProbs array. Accessing index -1 is legal and returns a guardian of -inf....
double getModeLProb() const
Get the log-probability of the mode subisotopologue.
double get_lProb(int idx) const
get the log-probability of the idx-th subisotopologue, see details in PrecalculatedMarginal::get_lPro...
LayeredMarginal(Marginal &&m, int tabSize=1000, int hashSize=1000)
Move constructor: specializes the Marginal class.
const Conf & get_conf(int idx) const
get the counts of isotopes that define the subisotopologue, see details in PrecalculatedMarginal::get...
int get_isotopeNo() const
Get the number of isotopes of the investigated element.
Conf computeModeConf() const
The the probability of the mode subisotopologue.
double getSmallestLProb() const
The the log-probability of the lightest subisotopologue.
Marginal(const double *_masses, const double *_probs, int _isotopeNo, int _atomCnt)
Class constructor.
const unsigned int atomCnt
double fastGetModeLProb()
Get the log-probability of the mode subisotopologue. Results undefined if ensureModeConf() wasn't cal...
double getModeLProb()
Get the log-probability of the mode subisotopologue.
double getModeMass()
The the mass of the mode subisotopologue.
double getLightestConfMass() const
Get the mass of the lightest subisotopologue.
const unsigned int isotopeNo
const double *const atom_masses
double variance() const
Calculate the variance of the theoretical distribution describing the subisotopologue.
ISOSPEC_FORCE_INLINE double unnormalized_logProb(Conf conf) const
Calculate the log-probability of a given subisotopologue.
const double loggamma_nominator
double getHeaviestConfMass() const
Get the mass of the heaviest subisotopologue.
double getAtomAverageMass() const
The average mass of a single atom.
double getMonoisotopicConfMass() const
Get the mass of the monoisotopic subisotopologue.
double getTheoreticalAverageMass() const
The theoretical average mass of the molecule.
virtual ~Marginal()
Destructor.
size_t getMonoisotopicAtomIndex() const
Get the index of the monoisotopic (most probable) atom.
double getLogSizeEstimate(double logEllipsoidRadius) const
Return estimated logarithm of size of the marginal at a given ellipsoid radius.
const double *const atom_lProbs
double getModeLProb() const
Get the log-probability of the mode subisotopologue.
bool probeConfigurationIdx(int idx)
Check if the table of computed subisotopologues does not have to be extended.
MarginalTrek(Marginal &&m, int tabSize=1000, int hashSize=1000)
Move constructor: specializes the Marginal class.
unsigned int get_no_confs() const
Get the number of precomputed subisotopologues.
const double * get_lProbs_ptr() const
Get the table of the log-probabilities of subisotopologues.
const double * get_masses_ptr() const
Get the table of the masses of subisotopologues.
const double & get_prob(int idx) const
Get the probability of the idx-th subisotopologue.
virtual ~PrecalculatedMarginal()
Destructor.
const double & get_lProb(int idx) const
Get the log-probability of the idx-th subisotopologue.
bool inRange(unsigned int idx) const
Is there a subisotopologue with a given number?
const Conf & get_conf(int idx) const
Get the counts of isotopes that define the subisotopologue.
PrecalculatedMarginal(Marginal &&m, double lCutOff, bool sort=true, int tabSize=1000, int hashSize=1000)
The move constructor (disowns the Marginal).
const double & get_mass(int idx) const
Get the mass of the idx-th subisotopologue.
double getModeLProb() const
Get the log-probability of the mode subisotopologue.
double get_mass(int idx) const
get the mass of the idx-th subisotopologue, see details in PrecalculatedMarginal::get_mass.
double get_min_mass() const
Get the minimal mass in current layer.
double get_prob(int idx) const
get the probability of the idx-th subisotopologue, see details in PrecalculatedMarginal::get_eProb.
const double * get_lProbs_ptr() const
get the pointer to lProbs array. Accessing index -1 is legal and returns a guardian of -inf....
SingleAtomMarginal(Marginal &&m, int tabSize=1000, int hashSize=1000)
Move constructor: specializes the Marginal class.
double get_max_mass() const
Get the maximal mass in current layer.
double get_lProb(int idx) const
get the log-probability of the idx-th subisotopologue, see details in PrecalculatedMarginal::get_lPro...
double getModeLProb() const
Get the log-probability of the mode subisotopologue.
const Conf & get_conf(int idx) const
get the counts of isotopes that define the subisotopologue, see details in PrecalculatedMarginal::get...
unsigned int get_no_confs() const
Get the number of precomputed subisotopologues, see details in PrecalculatedMarginal::get_no_confs.
bool extend(double new_threshold, bool do_sort=true)
Extend the set of computed subisotopologues to those above the new threshold.