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; }
void cGammaNode::updateMoments(){ for (int i=0; i < lnE.rows(); i++){ E1(i) = a(i)/b(i); lnE(i) = psi(a(i)) - log(b(i)); } }
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; }
void playing() { // insert code here... PMatrix m(2,2); PVector v1,v2; v1 = PVector::Constant(3, 2.1); v2 = PVector::Constant(3, 1.3); v1 = v2; v2(1) = 3; std::cout << PMatrix::Ones(3,4)*1.2 << std::endl; std::cout << v1 << std::endl << v2 + PVector::Ones(3)*2.0 << std::endl; m(0,0) = 3; m(1,0) = 2.5; m(0,1) = -1; m(1,1) = m(1,0) + m(0,1); std::cout << m << std::endl << m.rowwise().sum() << std::endl << m.colwise().sum() << std::endl; std::cout << randomreal() << std::endl << psi(10) << std::endl << gammafunction(10) << std::endl; }