aboutsummaryrefslogtreecommitdiff
path: root/projectionobserver.cpp
diff options
context:
space:
mode:
authorSamuel Fadel <samuelfadel@gmail.com>2016-01-18 15:46:05 +0100
committerSamuel Fadel <samuelfadel@gmail.com>2016-01-18 15:46:05 +0100
commit8cc4c24249600392871cc802f3ac4dd27368d335 (patch)
tree9bfde6414953828b379ee3728f5d92bbb772558d /projectionobserver.cpp
parentd0ba4bbd9eb7b550cf71bb421e2a6f8b83018b48 (diff)
Added observer to update values displayed based on some metric.
* Modified main() function to connect signals/slots to display calculated values * Color scales are no longer shared; they are also normalized to each component's own data * Stub mouse handling in BarChart (changes cursor shape)
Diffstat (limited to 'projectionobserver.cpp')
-rw-r--r--projectionobserver.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/projectionobserver.cpp b/projectionobserver.cpp
new file mode 100644
index 0000000..33869a8
--- /dev/null
+++ b/projectionobserver.cpp
@@ -0,0 +1,52 @@
+#include "projectionobserver.h"
+
+#include <cmath>
+
+#include "mp.h"
+
+static void aggregatedError(const arma::mat &distX, const arma::mat &distY, arma::vec &v)
+{
+ double maxX = distX.max();
+ double maxY = distY.max();
+
+ for (arma::uword i = 0; i < v.n_elem; i++) {
+ v[i] = 0;
+ for (arma::uword j = 0; j < v.n_elem; j++) {
+ if (i == j) {
+ continue;
+ }
+
+ v[i] += fabs(distY(i, j) / maxY - distX(i, j) / maxX);
+ }
+ }
+}
+
+ProjectionObserver::ProjectionObserver(const arma::mat &X,
+ const arma::uvec &cpIndices)
+ : m_X(X)
+ , m_cpIndices(cpIndices)
+{
+ m_distX = mp::dist(m_X);
+ m_values.set_size(m_X.n_rows);
+}
+
+void ProjectionObserver::setMap(const arma::mat &Y)
+{
+ // update previous map
+ if (m_prevY.n_elem == 0 && m_Y.n_elem > 0) {
+ m_prevY = m_Y;
+ m_distPrevY = m_distY;
+ }
+
+ m_Y = Y;
+ m_distY = mp::dist(Y);
+
+ // method called for the first time; set original Y
+ if (m_origY.n_elem == 0) {
+ m_origY = m_Y;
+ m_distOrigY = m_distY;
+ }
+
+ aggregatedError(m_distX, m_distY, m_values);
+ emit mapChanged(m_values);
+}