Break after reaching small interactions. Refs #5.

This commit is contained in:
2018-03-27 15:20:53 +02:00
parent a237058560
commit a72bb7542b
2 changed files with 11 additions and 5 deletions

View File

@@ -21,6 +21,8 @@ namespace fmri
*/ */
extern const float LAYER_X_OFFSET; extern const float LAYER_X_OFFSET;
constexpr const float EPSILON = 1e-10f;
/** /**
* Identity function that simply returns whatever is put in. * 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. * @return A vector of the indices before the partitioning cut-off.
*/ */
template<class Iter, class Compare> template<class Iter, class Compare>
std::vector<std::size_t> arg_nth_element(Iter first, Iter middle, Iter last, Compare compare) std::vector<std::size_t> arg_partial_sort(Iter first, Iter middle, Iter last, Compare compare)
{ {
using namespace std; using namespace std;
@@ -203,7 +205,7 @@ namespace fmri
vector<size_t> indices(total); vector<size_t> indices(total);
iota(indices.begin(), indices.end(), 0u); 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)); return compare(*(first + a), *(first + b));
}); });

View File

@@ -113,14 +113,18 @@ static Animation *getFullyConnectedAnimation(const fmri::LayerData &prevState, c
} }
const auto desiredSize = min(INTERACTION_LIMIT, numEntries); const auto desiredSize = min(INTERACTION_LIMIT, numEntries);
auto idx = arg_nth_element(interactions.begin(), interactions.begin() + desiredSize, interactions.end(), [](auto a, auto b) { auto idx = arg_partial_sort(interactions.begin(), interactions.begin() + desiredSize, interactions.end(),
return abs(a) > abs(b); [](auto a, auto b) {
}); return abs(a) > abs(b);
});
EntryList result; EntryList result;
result.reserve(desiredSize); result.reserve(desiredSize);
const auto normalizer = getNodeNormalizer(prevState); const auto normalizer = getNodeNormalizer(prevState);
for (auto i : idx) { for (auto i : idx) {
if (abs(interactions[i]) < EPSILON){
break;
}
result.emplace_back(interactions[i], make_pair((i % shape[1]) / normalizer, i / shape[1])); result.emplace_back(interactions[i], make_pair((i % shape[1]) / normalizer, i / shape[1]));
} }