aboutsummaryrefslogtreecommitdiff
path: root/projectionhistory.h
blob: e20f16cdab5dbb04a88bc2c351b7706a8eb70595 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef PROJECTIONHISTORY_H
#define PROJECTIONHISTORY_H

#include <QObject>

#include <armadillo>

class ProjectionHistory
    : public QObject
{
    Q_OBJECT
public:
    enum ObserverType {
        ObserverCurrent,
        ObserverDiffPrevious,
        ObserverDiffFirst
    };

    ProjectionHistory(const arma::mat &X, const arma::uvec &cpIndices);

    const arma::mat &Y() const             { return m_Y; }
    const arma::mat &firstY() const        { return m_firstY; }
    const arma::mat &prevY() const         { return m_prevY; }
    const arma::mat &unreliability() const { return m_unreliability; }

    const arma::uvec &cpIndices() const { return m_cpIndices; }
    const arma::uvec &rpIndices() const { return m_rpIndices; }

    bool hasFirst() const { return m_hasFirst; }
    bool hasPrev() const  { return m_hasPrev; }

    void undo();
    void reset();

signals:
    void undoPerformed() const;
    void resetPerformed() const;

    void currentMapChanged(const arma::mat &Y) const;
    void valuesChanged(const arma::vec &values, bool rescale) const;
    void cpValuesChanged(const arma::vec &values, bool rescale) const;
    void rpValuesChanged(const arma::vec &values, bool rescale) const;

    void mapRewound(const arma::mat &Y) const;
    void valuesRewound(const arma::vec &values) const;
    void cpValuesRewound(const arma::vec &values) const;
    void rpValuesRewound(const arma::vec &values) const;

public slots:
    void addMap(const arma::mat &Y);

    bool setType(ObserverType type);
    void setCPSelection(const std::vector<bool> &cpSelection);
    void setRPSelection(const std::vector<bool> &rpSelection);

    void setRewind(double t);

private:
    bool emitValuesChanged() const;
    void updateUnreliability();

    ObserverType m_type;

    arma::mat m_X, m_Y, m_firstY, m_prevY;
    arma::mat m_distX, m_distY, m_firstDistY, m_prevDistY;
    arma::mat m_unreliability;
    arma::uvec m_cpIndices, m_rpIndices;

    bool m_cpSelectionEmpty, m_rpSelectionEmpty;
    std::vector<int> m_cpSelection, m_rpSelection;

    // alpha(i, j): the influence CP j has on RP i
    void computeAlphas();
    arma::mat m_alphas, m_influences;

    // TODO: one per implemented measure
    arma::vec m_values, m_firstValues, m_prevValues;

    bool m_hasFirst, m_hasPrev;
};

#endif // PROJECTIONHISTORY_H