From 2007ebb8e431d1341583a03c22d440a7d0f79194 Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Mon, 5 Oct 2015 14:20:47 -0300 Subject: Re-added effectiveness observer (still needs work). --- effectivenessobserver.cpp | 12 +++++++----- effectivenessobserver.h | 6 ++++-- main.cpp | 25 +++++++++++++------------ 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/effectivenessobserver.cpp b/effectivenessobserver.cpp index 305b3f8..61bc264 100644 --- a/effectivenessobserver.cpp +++ b/effectivenessobserver.cpp @@ -6,7 +6,7 @@ EffectiveInteractionEnforcer::EffectiveInteractionEnforcer(const arma::uvec &sam { } -void EffectiveInteractionEnforcer::setSelection(const arma::uvec &selection) +void EffectiveInteractionEnforcer::setSelection(const QSet &selection) { m_selection = selection; } @@ -15,13 +15,15 @@ void EffectiveInteractionEnforcer::setMeasureDifference(const arma::vec &measure { m_measure = measure; - if (m_selection.n_elem == 0) { + if (m_selection.isEmpty()) { return; } - arma::uvec selectionIndices(m_selection); - for (auto it = selectionIndices.begin(); it != selectionIndices.end(); it++) { - *it = m_sampleIndices[*it]; + arma::uvec selectionIndices(m_selection.size()); + int i = 0; + for (auto it = m_selection.cbegin(); it != m_selection.cend(); it++) { + selectionIndices[i] = m_sampleIndices[*it]; + i++; } double diff = arma::mean(m_measure(selectionIndices)); diff --git a/effectivenessobserver.h b/effectivenessobserver.h index 8331916..80ee368 100644 --- a/effectivenessobserver.h +++ b/effectivenessobserver.h @@ -2,6 +2,7 @@ #define EFFECTIVEINTERACTIONENFORCER_H #include +#include #include class EffectiveInteractionEnforcer : public QObject @@ -14,13 +15,14 @@ signals: void effectivenessChanged(const arma::vec &effectiveness); public slots: - void setSelection(const arma::uvec &selection); + void setSelection(const QSet &selection); void setMeasureDifference(const arma::vec &measure); private: + arma::uvec m_sampleIndices; arma::mat m_effectiveness; - arma::uvec m_sampleIndices, m_selection; arma::vec m_measure; + QSet m_selection; }; #endif // EFFECTIVEINTERACTIONENFORCER_H diff --git a/main.cpp b/main.cpp index 559d554..5dbbe8b 100644 --- a/main.cpp +++ b/main.cpp @@ -39,10 +39,10 @@ int main(int argc, char **argv) arma::vec labels = dataset.col(dataset.n_cols - 1); arma::uword n = dataset.n_rows; - arma::uword subsampleSize = (arma::uword) sqrt(n) * 3; + arma::uword subsampleSize = (arma::uword) n / 10.f; arma::uvec sampleIndices = arma::randi(subsampleSize, arma::distr_param(0, n-1)); arma::mat Ys(subsampleSize, 2, arma::fill::randn); - Ys = mp::forceScheme(mp::dist(X.rows(sampleIndices)), Ys); + mp::forceScheme(mp::dist(X.rows(sampleIndices)), Ys); ColorScale colorScale{ QColor("#1f77b4"), @@ -60,7 +60,6 @@ int main(int argc, char **argv) //ContinuousColorScale colorScale = ContinuousColorScale::builtin(ContinuousColorScale::RED_GRAY_BLUE); //colorScale.setExtents(-1, 1); Scatterplot *subsamplePlot = engine.rootObjects()[0]->findChild("subsamplePlot"); - HistoryGraph *history = engine.rootObjects()[0]->findChild("history"); subsamplePlot->setAcceptedMouseButtons(Qt::LeftButton | Qt::MiddleButton | Qt::RightButton); // subsamplePlot->setColorData(arma::zeros(subsampleSize)); subsamplePlot->setColorScale(&colorScale); @@ -74,18 +73,21 @@ int main(int argc, char **argv) &interactionHandler, SLOT(setSubsample(const arma::mat &))); QObject::connect(&interactionHandler, SIGNAL(subsampleChanged(const arma::mat &)), plot, SLOT(setXY(const arma::mat &))); - QObject::connect(subsamplePlot, SIGNAL(xyInteractivelyChanged(const arma::mat &)), - history, SLOT(addHistoryItem(const arma::mat &))); - QObject::connect(history, SIGNAL(currentItemChanged(const arma::mat &)), - subsamplePlot, SLOT(setXY(const arma::mat &))); + // linking between selections in subsample plot and full dataset plot SelectionHandler selectionHandler(sampleIndices); QObject::connect(subsamplePlot, SIGNAL(selectionChanged(const QSet &)), &selectionHandler, SLOT(setSelection(const QSet &))); QObject::connect(&selectionHandler, SIGNAL(selectionChanged(const QSet &)), plot, SLOT(setSelection(const QSet &))); - /* + HistoryGraph *history = engine.rootObjects()[0]->findChild("history"); + // connections between history graph and subsample plot + QObject::connect(subsamplePlot, SIGNAL(xyInteractivelyChanged(const arma::mat &)), + history, SLOT(addHistoryItem(const arma::mat &))); + QObject::connect(history, SIGNAL(currentItemChanged(const arma::mat &)), + subsamplePlot, SLOT(setXY(const arma::mat &))); + DistortionObserver distortionObs(X, sampleIndices); std::unique_ptr distortionMeasure(new NPDistortion()); distortionObs.setMeasure(distortionMeasure.get()); @@ -95,13 +97,12 @@ int main(int argc, char **argv) plot, SLOT(setColorData(const arma::vec &))); EffectiveInteractionEnforcer enforcer(sampleIndices); - QObject::connect(subsamplePlot, SIGNAL(selectionChanged(const arma::uvec &)), - &enforcer, SLOT(setSelection(const arma::uvec &))); + QObject::connect(subsamplePlot, SIGNAL(selectionChanged(const QSet &)), + &enforcer, SLOT(setSelection(const QSet &))); QObject::connect(plot, SIGNAL(colorDataChanged(const arma::vec &)), &enforcer, SLOT(setMeasureDifference(const arma::vec &))); QObject::connect(&enforcer, SIGNAL(effectivenessChanged(const arma::vec &)), subsamplePlot, SLOT(setColorData(const arma::vec &))); - */ /* ContinuousColorScale ccolorScale = ContinuousColorScale::builtin(ContinuousColorScale::RED_GRAY_BLUE); @@ -109,11 +110,11 @@ int main(int argc, char **argv) plot->setColorScale(&ccolorScale); */ plot->setColorScale(&colorScale); - plot->setColorData(labels); history->addHistoryItem(Ys); subsamplePlot->setXY(Ys); subsamplePlot->setColorData(labels(sampleIndices)); + plot->setColorData(labels); return app.exec(); } -- cgit v1.2.3