//@{ double negativeBinomialDist::aic (const ArrayXd& y, const ArrayXd& n, const ArrayXd& mu, const ArrayXd& wt, double dev) const { return 2. * (wt * (y + d_theta) * (mu + d_theta).log() - y * mu.log() + (y + 1).unaryExpr(Lgamma<double>()) - d_theta * std::log(d_theta) + lgamma(d_theta) - (d_theta + y).unaryExpr(Lgamma<double>())).sum(); }
VectorXd probutils::logsumexp (const MatrixXd& X) { const VectorXd mx = X.rowwise().maxCoeff(); // Get max of each row // Perform the sum(exp(x - mx)) part ArrayXd se = ((X.colwise() - mx).array().exp()).rowwise().sum(); // return total log(sum(exp(x))) - hoping for return value optimisation return (se.log()).matrix() + mx; }
//@{ const ArrayXd logLink::linkFun(const ArrayXd& mu) const {return mu.log();}
//@{ double inverseGaussianDist::aic (const ArrayXd& y, const ArrayXd& n, const ArrayXd& mu, const ArrayXd& wt, double dev) const { double wtsum(wt.sum()); return wtsum * (std::log(dev/wtsum * 2. * M_PI) + 1.) + 3. * (y.log() * wt).sum() + 2.; }
//@{ double GaussianDist::aic (const ArrayXd& y, const ArrayXd& n, const ArrayXd& mu, const ArrayXd& wt, double dev) const { double nn(mu.size()); return nn * (std::log(2. * M_PI * dev/nn) + 1.) + 2. - wt.log().sum(); }