From 8cc4c24249600392871cc802f3ac4dd27368d335 Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Mon, 18 Jan 2016 15:46:05 +0100 Subject: 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) --- projectionobserver.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 projectionobserver.cpp (limited to 'projectionobserver.cpp') 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 + +#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); +} -- cgit v1.2.3