diff options
author | Samuel Fadel <samuelfadel@gmail.com> | 2015-05-19 18:54:20 -0300 |
---|---|---|
committer | Samuel Fadel <samuelfadel@gmail.com> | 2015-05-19 18:54:20 -0300 |
commit | ecc6ada9f64a9858f29b5da2e733fec0ec6f8bad (patch) | |
tree | b46d14818c3e4fba0de968f7fde55eddc7d743a1 /main.cpp | |
parent | 7c4333eed407886114f33d803a3199c50556e4e3 (diff) |
Initial selection implementation.
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 59 |
1 files changed, 32 insertions, 27 deletions
@@ -1,49 +1,54 @@ #include <cmath> +#include <QSurfaceFormat> #include <QGuiApplication> -#include <QtQuick/QQuickView> +#include <QQmlApplicationEngine> #include "mp.h" #include "scatterplot.h" -arma::uvec getSample(arma::uword n) -{ - return arma::randi<arma::uvec>((arma::uword) 3*sqrt(n), arma::distr_param(0, n-1)); -} - -arma::mat getProjection(const arma::mat &X) -{ - arma::uword n = X.n_rows; - arma::uvec sampleIndices = getSample(n); - arma::mat Ys = arma::randn(sampleIndices.n_elem, 2); - Ys = mp::forceScheme(mp::dist(X.rows(sampleIndices)), Ys); - return mp::lamp(X, sampleIndices, Ys); -} - int main(int argc, char **argv) { QGuiApplication app(argc, argv); qmlRegisterType<Scatterplot>("PM", 1, 0, "Scatterplot"); - QQuickView view; + /*QQuickView view; QSurfaceFormat format = view.format(); format.setSamples(16); view.setFormat(format); view.setResizeMode(QQuickView::SizeRootObjectToView); - view.setSource(QUrl("qrc:///main_view.qml")); + view.setSource(QUrl("qrc:///main_view.qml"));*/ + QSurfaceFormat fmt; + fmt.setSamples(16); + QSurfaceFormat::setDefaultFormat(fmt); + QQmlApplicationEngine engine(QUrl("qrc:///main_view.qml")); if (argc > 1) { - arma::mat X; - X.load(argv[1], arma::raw_ascii); - - Scatterplot *plot = view.rootObject()->findChild<Scatterplot *>("plot"); - arma::mat scatterData(X.n_rows, 3); - scatterData.cols(0, 1) = getProjection(X.cols(0, X.n_cols - 2)); - scatterData.col(2) = X.col(X.n_cols - 1); - plot->setData(scatterData); + arma::mat dataset; + dataset.load(argv[1], arma::raw_ascii); + arma::mat X = dataset.cols(0, dataset.n_cols - 2); + arma::vec labels = dataset.col(dataset.n_cols - 1); + + arma::uword n = dataset.n_rows; + arma::uword subsampleSize = (arma::uword) sqrt(n) * 3; + arma::uvec sampleIndices = arma::randi<arma::uvec>(subsampleSize, arma::distr_param(0, n-1)); + arma::mat Ys = arma::randn(subsampleSize, 2); + Ys = mp::forceScheme(mp::dist(X.rows(sampleIndices)), Ys); + + // Plot the subsample + Scatterplot *plot = engine.rootObjects()[0]->findChild<Scatterplot *>("subsamplePlot"); + arma::mat subsampleData(subsampleSize, 3); + subsampleData.cols(0, 1) = Ys; + subsampleData.col(2) = labels(sampleIndices); + plot->setData(subsampleData); + + // Plot entire dataset + plot = engine.rootObjects()[0]->findChild<Scatterplot *>("plot"); + arma::mat reducedData(n, 3); + reducedData.cols(0, 1) = mp::lamp(X, sampleIndices, Ys); + reducedData.col(2) = labels; + plot->setData(reducedData); } - view.show(); - return app.exec(); } |