aboutsummaryrefslogtreecommitdiff
path: root/measures.cpp
diff options
context:
space:
mode:
authorSamuel Fadel <samuelfadel@gmail.com>2016-02-09 21:36:34 -0200
committerSamuel Fadel <samuelfadel@gmail.com>2016-02-09 21:36:34 -0200
commit5c26dd04dd171112d14bfb24db96cf286566e19b (patch)
tree62a2dd9370a54968bf543344153ef69a85561840 /measures.cpp
parent886bdd0fa43a2fcdeca306648b643b623af99f88 (diff)
Slightly reworked rewinding; added values rewinding.
Needs a solution to the problem of which values must be displayed and/or interpolated. Currently, whenever the user rewinds, the current error measure is displayed, regardless of what was being displayed before. This will probably be trivial to solve once we have a nice way of changing the current measure. * Also changed all OpenMP-powered for loops to use signed integers, requirements of OMP2.x (which is what MSVC supports currently) * The above change comes with a new header for utility functions
Diffstat (limited to 'measures.cpp')
-rw-r--r--measures.cpp40
1 files changed, 35 insertions, 5 deletions
diff --git a/measures.cpp b/measures.cpp
index daf3c78..2a3908f 100644
--- a/measures.cpp
+++ b/measures.cpp
@@ -4,15 +4,19 @@
#include <cmath>
#include <algorithm>
+#include "utils.h"
+
+static const float EPSILON = 1e-6f;
+
arma::vec mp::neighborhoodPreservation(const arma::mat &distA,
const arma::mat &distB,
arma::uword k)
{
- arma::uword n = distA.n_rows;
+ int n = uintToInt<arma::uword, int>(distA.n_rows);
arma::vec np(n);
#pragma omp parallel for shared(np, n)
- for (arma::uword i = 0; i < n; i++) {
+ for (int i = 0; i < n; i++) {
arma::uvec nnA(k);
arma::uvec nnB(k);
arma::vec dist(k);
@@ -39,6 +43,32 @@ arma::vec mp::silhouette(const arma::mat &distA,
return arma::vec(distA.n_rows, arma::fill::zeros);
}
+void mp::aggregatedError(const arma::mat &distX,
+ const arma::mat &distY,
+ arma::vec &v)
+{
+ int n = uintToInt<arma::uword, int>(v.n_elem);
+ double maxX = distX.max();
+ double maxY = distY.max();
+
+ #pragma omp parallel for shared(maxX, maxY, distX, distY, v, n)
+ for (int i = 0; i < n; i++) {
+ v[i] = 0;
+ for (int j = 0; j < n; j++) {
+ if (i == j) {
+ continue;
+ }
+
+ double diff = fabs(distY(i, j) / maxY - distX(i, j) / maxX);
+ if (diff < EPSILON) {
+ continue;
+ }
+
+ v[i] += diff;
+ }
+ }
+}
+
/*
double mp::stress(const arma::mat &Dp, const arma::mat &Dq)
{
@@ -66,16 +96,16 @@ arma::vec mp::klDivergence(const arma::mat &P, const arma::mat &Q)
return diver;
}
-void mp::klDivergence(const arma::mat &P, const arma::mat &Q, arma::vec &diver)
+void mp::klDivergence(const arma::mat &P, const arma::mat &Q, arma::vec &diverg)
{
assert(P.n_rows == P.n_cols);
assert(Q.n_rows == Q.n_cols);
assert(P.n_rows == Q.n_cols);
- assert(diver.n_elem == P.n_rows);
+ assert(diverg.n_elem == P.n_rows);
arma::uword n = P.n_rows;
for (arma::uword i = 0; i < n; i++)
- diver(i) = klDivergence(P.row(i), Q.row(i));
+ diverg(i) = klDivergence(P.row(i), Q.row(i));
}
double mp::klDivergence(const arma::rowvec &pi, const arma::rowvec &qi)