From a72bb7542b69d5b15143f7759e96818ea5d52e08 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Tue, 27 Mar 2018 15:20:53 +0200 Subject: [PATCH] Break after reaching small interactions. Refs #5. --- src/fmri/utils.hpp | 6 ++++-- src/fmri/visualisations.cpp | 10 +++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/fmri/utils.hpp b/src/fmri/utils.hpp index 95cabf3..07ed1e2 100644 --- a/src/fmri/utils.hpp +++ b/src/fmri/utils.hpp @@ -21,6 +21,8 @@ namespace fmri */ extern const float LAYER_X_OFFSET; + constexpr const float EPSILON = 1e-10f; + /** * Identity function that simply returns whatever is put in. * @@ -193,7 +195,7 @@ namespace fmri * @return A vector of the indices before the partitioning cut-off. */ template - std::vector arg_nth_element(Iter first, Iter middle, Iter last, Compare compare) + std::vector arg_partial_sort(Iter first, Iter middle, Iter last, Compare compare) { using namespace std; @@ -203,7 +205,7 @@ namespace fmri vector indices(total); iota(indices.begin(), indices.end(), 0u); - nth_element(indices.begin(), indices.begin() + n, indices.end(), [=](size_t a, size_t b) { + partial_sort(indices.begin(), indices.begin() + n, indices.end(), [=](size_t a, size_t b) { return compare(*(first + a), *(first + b)); }); diff --git a/src/fmri/visualisations.cpp b/src/fmri/visualisations.cpp index 65d18f6..a56aff6 100644 --- a/src/fmri/visualisations.cpp +++ b/src/fmri/visualisations.cpp @@ -113,14 +113,18 @@ static Animation *getFullyConnectedAnimation(const fmri::LayerData &prevState, c } const auto desiredSize = min(INTERACTION_LIMIT, numEntries); - auto idx = arg_nth_element(interactions.begin(), interactions.begin() + desiredSize, interactions.end(), [](auto a, auto b) { - return abs(a) > abs(b); - }); + auto idx = arg_partial_sort(interactions.begin(), interactions.begin() + desiredSize, interactions.end(), + [](auto a, auto b) { + return abs(a) > abs(b); + }); EntryList result; result.reserve(desiredSize); const auto normalizer = getNodeNormalizer(prevState); for (auto i : idx) { + if (abs(interactions[i]) < EPSILON){ + break; + } result.emplace_back(interactions[i], make_pair((i % shape[1]) / normalizer, i / shape[1])); }