blob: b6bed67eac6df4e3d33b2c9e2ce06e8f9b50880a (
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
|
#ifndef MAIN_H
#define MAIN_H
#include <QObject>
#include <armadillo>
#include "interactionhandler.h"
class Main : public QObject
{
Q_OBJECT
public:
static Main *instance() {
// FIXME: Possibly dangerous
static Main *m = 0;
if (m == 0) {
m = new Main();
}
return m;
}
Q_INVOKABLE bool saveData() const {
bool ret = true;
if (m_subsample.n_elem > 0 && m_indicesSavePath.size() > 0) {
ret = ret && m_subsample.save(m_subsampleSavePath, arma::raw_ascii);
}
if (m_subsampleIndices.n_elem > 0 && m_subsampleSavePath.size() > 0) {
ret = ret && m_subsampleIndices.save(m_indicesSavePath, arma::raw_ascii);
}
return ret;
}
Q_INVOKABLE bool loadDataset(const std::string &path) { return m_dataset.load(path, arma::raw_ascii); }
Q_INVOKABLE void setIndicesSavePath(const std::string &path) { m_indicesSavePath = path; }
Q_INVOKABLE void setIndicesSavePath(const QString &path) { setIndicesSavePath(path.toStdString()); }
Q_INVOKABLE void setSubsampleSavePath(const std::string &path) { m_subsampleSavePath = path; }
Q_INVOKABLE void setSubsampleSavePath(const QString &path) { setSubsampleSavePath(path.toStdString()); }
void setInteractionHandler(InteractionHandler *interactionHandler) {
m_interactionHandler = interactionHandler;
}
Q_INVOKABLE void setTechnique(int technique) {
if (m_interactionHandler) {
m_interactionHandler->setTechnique((InteractionHandler::Technique) technique);
}
}
arma::mat X() const { return m_dataset.cols(0, m_dataset.n_cols - 2); }
arma::vec labels() const { return m_dataset.col(m_dataset.n_cols - 1); }
public slots:
void setSubsampleIndices(const arma::uvec &indices) { m_subsampleIndices = indices; }
void setSubsample(const arma::mat &subsample) {
if (subsample.n_cols != 2
|| subsample.n_rows != m_subsampleIndices.n_elem) {
return;
}
m_subsample = subsample;
}
private:
Main(QObject *parent = 0)
: QObject(parent)
, m_interactionHandler(0)
{}
~Main() {}
Q_DISABLE_COPY(Main)
arma::mat m_dataset, m_subsample;
arma::uvec m_subsampleIndices;
std::string m_indicesSavePath, m_subsampleSavePath;
InteractionHandler *m_interactionHandler;
};
#endif // MAIN_H
|