From aafe95583dd1464aa6069de07a09bd6b423bf644 Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Wed, 31 Aug 2016 09:48:24 -0300 Subject: Removed labels handling and bundling when selecting regular points. --- main.cpp | 29 +++++++++++++++++++++++------ main.h | 13 +++++++------ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/main.cpp b/main.cpp index 8cc9323..5f7693d 100644 --- a/main.cpp +++ b/main.cpp @@ -43,6 +43,18 @@ arma::uvec extractCPs(const arma::mat &X) return indices.subvec(0, numCPs-1); } +arma::mat standardize(const arma::mat &X) +{ + arma::mat stdX = X; + for (arma::uword j = 0; j < X.n_cols; j++) { + double sd = arma::stddev(stdX.col(j)); + double mean = arma::mean(stdX.col(j)); + stdX.col(j) = (stdX.col(j) - mean) / sd; + } + + return stdX; +} + void overviewBundles(const Main *m) { const arma::mat &unreliability = m->projectionHistory->unreliability(); @@ -105,8 +117,7 @@ int main(int argc, char **argv) return 1; } - const arma::mat &X = m->X(); - //arma::vec labels = m->labels(); + const arma::mat &X = standardize(m->X()); arma::arma_rng::set_seed(RNG_SEED); arma::uvec cpIndices; @@ -121,6 +132,7 @@ int main(int argc, char **argv) if (indicesFile.exists()) { m->setIndicesSavePath(indicesFilename); cpIndices.load(indicesFilename.toStdString(), arma::raw_ascii); + cpIndices -= 1; } else { std::cerr << "No indices file, generating indices...\n"; cpIndices = extractCPs(X); @@ -147,6 +159,10 @@ int main(int argc, char **argv) return 1; } + // TODO: maybe put this inside m->setCP() method; for now, will be outside + // for more flexibility + Ys = arma::normalise(Ys); + // Sort indices (some operations become easier later) arma::uvec cpSortedIndices = arma::sort_index(cpIndices); cpIndices = cpIndices(cpSortedIndices); @@ -262,7 +278,7 @@ int main(int argc, char **argv) // Only the 10% largest values, filtered by the selected RPs const arma::mat &unreliability = m->projectionHistory->unreliability(); arma::uvec indicesLargest = arma::sort_index(unreliability.cols(selectedCPs), "descending"); - arma::uword numLargest = indicesLargest.n_elem * 0.1f; + arma::uword numLargest = indicesLargest.n_elem * 0.01f; indicesLargest = indicesLargest.subvec(0, numLargest-1); m->bundlePlot->setValues(unreliability(indicesLargest)); @@ -293,7 +309,8 @@ int main(int argc, char **argv) m->rpPlot, &Scatterplot::setSelection); QObject::connect(&rpSelectionHandler, &SelectionHandler::selectionChanged, m->rpBarChart, &BarChart::setSelection); - QObject::connect(&rpSelectionHandler, &SelectionHandler::selectionChanged, + // This still needs more tests + /*QObject::connect(&rpSelectionHandler, &SelectionHandler::selectionChanged, [m](const std::vector &rpSelection) { // given some RPs, see unexpected CPs *influencing* them std::vector selectedRPIndices; @@ -315,7 +332,7 @@ int main(int argc, char **argv) // Only the 10% largest values, filtered by the selected RPs const arma::mat &unreliability = m->projectionHistory->unreliability(); arma::uvec indicesLargest = arma::sort_index(unreliability.rows(selectedRPs), "descending"); - arma::uword numLargest = indicesLargest.n_elem * 0.1f; + arma::uword numLargest = indicesLargest.n_elem * 0.01f; indicesLargest = indicesLargest.subvec(0, numLargest-1); m->bundlePlot->setValues(unreliability(indicesLargest)); @@ -335,7 +352,7 @@ int main(int argc, char **argv) indices[2*i + 1] = RPs(i); } m->bundlePlot->setLines(indices, m->projectionHistory->Y()); - }); + });*/ // Brushing between each bar chart and respective scatterplot BrushingHandler cpBrushHandler; diff --git a/main.h b/main.h index 143d49e..9e7ca52 100644 --- a/main.h +++ b/main.h @@ -44,7 +44,9 @@ public: return ret; } - Q_INVOKABLE bool loadDataset(const std::string &path) { return m_dataset.load(path, arma::raw_ascii); } + Q_INVOKABLE bool loadDataset(const std::string &dataPath) { + return m_X.load(dataPath, arma::raw_ascii); + } Q_INVOKABLE void setIndicesSavePath(const std::string &path) { m_indicesSavePath = path; @@ -59,8 +61,7 @@ public: setCPSavePath(path.toStdString()); } - 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); } + arma::mat X() const { return m_X; } Q_INVOKABLE void setSelectRPs() { cpPlot->setAcceptedMouseButtons(Qt::NoButton); @@ -158,8 +159,8 @@ public slots: void setCPIndices(const arma::uvec &indices) { m_cpIndices = indices; - m_rpIndices.set_size(m_dataset.n_rows - m_cpIndices.n_elem); - NumericRange allIndices(0, m_dataset.n_rows); + m_rpIndices.set_size(m_X.n_rows - m_cpIndices.n_elem); + NumericRange allIndices(0, m_X.n_rows); std::set_symmetric_difference(allIndices.cbegin(), allIndices.cend(), m_cpIndices.cbegin(), m_cpIndices.cend(), m_rpIndices.begin()); } @@ -220,7 +221,7 @@ private: } } - arma::mat m_dataset, m_cp; + arma::mat m_X, m_cp; arma::uvec m_cpIndices, m_rpIndices; std::string m_indicesSavePath, m_cpSavePath; }; -- cgit v1.2.3