double cDirichletNode::entropy(){ double temp = 0; double ent = -lngamma(a.sum(), temp); for (int i=0; i < a.rows(); i++) {ent += lngamma(a(i), temp);} ent += (a.sum() - a.rows())*psi(a.sum()); // ent -= (a - PVector::Ones(a.rows()))*psi(); for (int i=0; i < a.rows(); i++){ent -= (a(i) - 1)*psi(a(i));} return ent; }
double cGammaNode::calcBound(cBayesNet* net){ double bound = 0; double temp = 0; for (int i=0; i < lnE.rows(); i++) { bound += pa*log(pb); bound += (pa - 1.)*lnE(i); bound -= pb*E1(i); bound -= lngamma(pa, temp); } return bound + entropy(); }
double cGammaNode::entropy(){ double temp = 0; double ent = 0; for (int i=0; i < a.rows(); i++) { ent += a(i); ent -= log(b(i)); ent += lngamma(a(i), temp); ent += (1. - a(i))*psi(a(i)); } return ent; }
double cDirichletNode::calcBound(cBayesNet* net){ double temp = 0; double bound = ((a0 - PVector::Ones(a0.rows()))*lnE).sum() - lngamma(a0.sum(), temp); for (int i=0; i < a0.rows(); i++) { bound += lngamma(a0(i), temp); } return bound + entropy(); }