diff options
author | Samuel Fadel <samuelfadel@gmail.com> | 2015-06-01 18:12:25 -0300 |
---|---|---|
committer | Samuel Fadel <samuelfadel@gmail.com> | 2015-06-01 18:12:25 -0300 |
commit | a3858735ec68d518f830307da65606694345dca1 (patch) | |
tree | 6e59742318e43811c03a67d7be61f2e73a82f5ab | |
parent | 81f67ff9a729e84e9fff8718081860f4f94d3ea1 (diff) |
Bugfix klDivergence.
-rw-r--r-- | measures.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/measures.cpp b/measures.cpp index dff8494..8829ee8 100644 --- a/measures.cpp +++ b/measures.cpp @@ -43,7 +43,8 @@ void mp::klDivergence(const arma::mat &P, const arma::mat &Q, arma::vec diver) double mp::klDivergence(const arma::rowvec &pi, const arma::rowvec &qi) { - return arma::accu(removeJ % (pi % arma::log(pi / qi))); + // Pii and Qii should both be 1, zeroing the i-th term in the sum below + return arma::accu(pi % arma::log(pi / qi)); } arma::mat mp::d2p(const arma::mat &D, const arma::vec &sigmas) @@ -58,7 +59,6 @@ void mp::d2p(const arma::mat &D, const arma::vec &sigmas, arma::mat &P) /* * WARNING: assumes D and sigmas are already squared */ - assert(D.n_rows == D.n_cols); assert(P.n_rows == P.n_cols); assert(D.n_rows == P.n_rows); @@ -72,4 +72,4 @@ void mp::d2p(const arma::mat &D, const arma::vec &sigmas, arma::mat &P) for (arma::uword j = 0; j < n; j++) P(i, j) = exp(-D(i, j) / sigmas(i)) / den; } -}
\ No newline at end of file +} |