2 #ifndef GEESE_MEAT_LIKELIHOOD_EXHAUST_HPP
3 #define GEESE_MEAT_LIKELIHOOD_EXHAUST_HPP 1
8 const std::vector< double > & par
15 std::vector< double > par0(par.begin(), par.end() -
nfunctions);
16 std::vector< double > par_root(par.end() -
nfunctions, par.end());
19 for (
auto& p : par_root)
20 p = std::exp(p)/(std::exp(p) + 1);
24 throw std::overflow_error(
"Too many nodes! Exhaust calculation of likelihood cannot be done for such cases.");
26 if (this->
nfuns() > 3)
27 throw std::overflow_error(
"Too many functions! Exhaust calculation of likelihood cannot be done for such cases.");
34 for (
size_t i = 0u;
i <
nfuns(); ++
i)
35 base(
i, n.second.ord) = n.second.annotations[
i];
41 rule_empty_free<PhyloArray,PhyloRuleData>,
47 std::vector< size_t > preorder(this->
sequence);
48 std::reverse(preorder.begin(), preorder.end());
54 for (
size_t p = 0u; p < pset.size(); ++p)
62 std::vector< size_t > tmpstates(this->
nfuns());
65 for (
auto&
i : preorder)
69 std::fill(tmpstates.begin(), tmpstates.end(), 0u);
70 s->get_col_vec(&tmpstates, node->
ord,
false);
73 if (node->
parent ==
nullptr)
77 for (
auto k = 0u; k < this->
nfuns(); ++k)
78 prob *= tmpstates[k] == 1u ? par_root[k] : (1.0 - par_root[k]);
87 std::vector< double > bl(node->
offspring.size(), 1.0);
89 std::vector< bool > sl = vector_caster<bool,size_t>(tmpstates);
97 for (
size_t a = 0u; a <
nfuns(); ++a)
100 for (
size_t o = 0u; o < node->
offspring.size(); ++o)
103 if (s->get_cell(a, node->
offspring[o]->id) == 1u)
104 transition(a, o) = 1u;
110 prob *= this->model->likelihood(
113 node->
narray[
this->map_to_state_id[tmpstates]],
std::vector< size_t > sequence
size_t nnodes() const noexcept
Number of nodes (interior + leaf)
std::map< size_t, Node > nodes
size_t nfuns() const noexcept
Number of functions analyzed.
double likelihood_exhaust(const std::vector< double > &par)
Data definition for the PhyloArray class.
A single node for the model.
std::vector< Node * > offspring
Offspring nodes.
std::vector< size_t > narray
ID of the array in the model.
Node * parent
Parent node.
size_t ord
Order in which the node was created.
bool is_leaf() const noexcept
std::vector< std::pair< size_t, size_t > > PhyloRuleData
barry::BArrayDense< size_t, NodeData > PhyloArray
barry::PowerSet< PhyloArray, PhyloRuleData > PhyloPowerSet