This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef _ALIAS_SAMPLER_H_ | |
#define _ALIAS_SAMPLER_H_ | |
#include <vector> | |
#include <limits> | |
// Placed in the public domain by Chris Dyer <[email protected]> | |
// April 9, 2012 | |
// | |
// R. A. Kronmal and A. V. Peterson, Jr. (1977) On the alias method for |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef LOGVAL_H_ | |
#define LOGVAL_H_ | |
// represent values internally in the log domain (much larger effective range than float, | |
// double, or long double). useful for very small probabilities or very large unnormalized | |
// probabilities while avoiding underflows/overflows. | |
// | |
// this should be used as if it were a double or float, i.e. for doubles a and b: | |
// a * b = LogVal(a) * LogVal(b) | |
// a + b = LogVal(a) + LogVal(b) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// set use_cholesky if M is symmetric - it's faster and more stable | |
// for dep paring it won't be | |
template <typename MatrixType> | |
inline typename MatrixType::Scalar logdet(const MatrixType& M, bool use_cholesky = false) { | |
using namespace Eigen; | |
using std::log; | |
typedef typename MatrixType::Scalar Scalar; | |
Scalar ld = 0; | |
if (use_cholesky) { | |
LLT<Matrix<Scalar,Dynamic,Dynamic>> chol(M); |