Added a cache for track features, made the crossover ratio configurable, now using a fitness proportional selection

This commit is contained in:
emeric
2019-12-03 13:47:48 +01:00
parent 93cd3b6020
commit 74a5f6389d
6 changed files with 181 additions and 46 deletions
@@ -20,6 +20,7 @@
#pragma once
#include <map>
#include <optional>
#include <set>
#include <string>
@@ -70,6 +71,11 @@ class FeaturesSearcher
FeaturesCache toCache() const;
using FeaturesFetchFunc = std::function<std::optional<std::unordered_map<std::string, std::vector<double>>>(Database::IdType /*trackId*/, const std::unordered_set<std::string>& /*features*/)>;
// Default is to retrieve the features from the database (may be slow).
// Use this only if you want to train different searchers with the same data
static void setFeaturesFetchFunc(FeaturesFetchFunc func) { _featuresFetchFunc = func; }
private:
using ObjectPositions = std::map<Database::IdType, std::set<SOM::Position>>;
@@ -96,6 +102,7 @@ class FeaturesSearcher
SOM::Matrix<std::set<Database::IdType>> _tracksMap;
ObjectPositions _trackPositions;
static inline FeaturesFetchFunc _featuresFetchFunc;
};
} // ns Similarity