blob: 781aba9b1242345b8fc1993d38850685f7b927c1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#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();
#pragma omp parallel for shared(maxX, maxY, distX, distY, v)
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);
}
|