ImportanceFilter.cpp
Go to the documentation of this file.
1 #include "ImportanceFilter.h"
2 
3 
5 {
6 
8 {
9  auto start = std::chrono::high_resolution_clock::now();
10  bool instances_accepted = false;
11 
12  e.forEachInstance([this, &instances_accepted](armem::wm::EntityInstance& i){
13  if(!instances_accepted){ //if no instance was accepted yet
14  instances_accepted = important(i); //see if another instance triggers acceptance
15  }
16  });
17 
18  //set stats:
19  auto end = std::chrono::high_resolution_clock::now();
20  stats.end_time = end;
21  stats.additional_time += (end - start);
22  if(instances_accepted){
23  stats.accepted += 1;
24  } else {
25  stats.rejected += 1;
26  }
27 
28  return instances_accepted;
29 }
30 
31 void SnapshotImportanceFilter::configure(const nlohmann::json &json)
32 {
33  if(json.find(PARAM_THRESHOLD) != json.end()){
34  this->threshold = json.at(PARAM_THRESHOLD);
35  ARMARX_INFO << VAROUT(this->threshold);
36  stats.additional_info += "Threshold for importance: ";
37  stats.additional_info += std::to_string(this->threshold);
38  }
39  if(json.find(PARAM_TYPE) != json.end()){
40  auto t = json.at(PARAM_TYPE);
41  if(t == "Confidence"){
42  this->type = ImportanceType::CONFIDENCE;
43  }
44  if(t == "Accesses"){
45  this->type = ImportanceType::ACCESSES;
46  }
47  stats.importance_type = t;
49  }
50 
51  stats.start_time = std::chrono::high_resolution_clock::now();
53  stats.similarity_type = aron::similarity::NDArraySimilarity::Type::NONE; //information for statistics export
54 }
55 
57 {
58  return this->stats;
59 }
60 
62 {
63  return this->NAME;
64 }
65 
66 bool SnapshotImportanceFilter::important(armem::wm::EntityInstance &i)
67 {
68  if(this->type == ImportanceType::CONFIDENCE){
69  auto c = i.metadata().confidence;
70  if ( c > this->threshold){
71  //for now the whole entity snapshot is accepted if at least one instance has a confidence higher than the threshold
72  return true;
73  }
74  } else if (this->type == ImportanceType::ACCESSES){
75  auto a = i.metadata().numAccessed;
76  if (a > this->threshold){
77  return true;
78  }
79  }
80  return false;
81 }
82 
83 
84 }
armarx::armem::server::ltm::processor::filter::SnapshotImportanceFilter::PARAM_THRESHOLD
static const constexpr char * PARAM_THRESHOLD
Definition: ImportanceFilter.h:21
armarx::armem::base::EntityInstanceMetadata::numAccessed
unsigned long numAccessed
A counter how often the instance has been accessed.
Definition: EntityInstanceBase.h:60
armarx::armem::server::ltm::processor::SnapshotFilter::FilterStatistics::end_time
std::chrono::high_resolution_clock::time_point end_time
Definition: Filter.h:42
armarx::armem::server::ltm::processor::filter::SnapshotImportanceFilter::PARAM_TYPE
static const constexpr char * PARAM_TYPE
Definition: ImportanceFilter.h:22
armarx::armem::wm::EntityInstance
Client-side working entity instance.
Definition: memory_definitions.h:32
armarx::armem::server::ltm::processor::filter::SnapshotImportanceFilter::NAME
static const constexpr char * NAME
Definition: ImportanceFilter.h:20
armarx::armem::base::EntitySnapshotBase::forEachInstance
bool forEachInstance(InstanceFunctionT &&func)
Definition: EntitySnapshotBase.h:178
armarx::armem::server::ltm::processor::filter::SnapshotImportanceFilter::accept
virtual bool accept(const armem::wm::EntitySnapshot &e) override
Definition: ImportanceFilter.cpp:7
armarx::armem::server::ltm::processor::filter::SnapshotImportanceFilter::getName
std::string getName() override
Definition: ImportanceFilter.cpp:61
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::armem::server::ltm::processor::SnapshotFilter::FilterStatistics::rejected
double rejected
Definition: Filter.h:37
armarx::armem::server::ltm::processor::filter::CONFIDENCE
@ CONFIDENCE
Definition: ImportanceFilter.h:12
armarx::armem::server::ltm::processor::SnapshotFilter::FilterStatistics::importance_type
std::string importance_type
Definition: Filter.h:44
armarx::ctrlutil::a
double a(double t, double a0, double j)
Definition: CtrlUtil.h:45
armarx::armem::server::ltm::processor::SnapshotFilter::FilterStatistics::number_of_compared_objects
int number_of_compared_objects
Definition: Filter.h:43
armarx::armem::server::ltm::processor::filter::SnapshotImportanceFilter::getFilterStatistics
FilterStatistics getFilterStatistics() override
Definition: ImportanceFilter.cpp:56
armarx::armem::server::ltm::processor::SnapshotFilter::FilterStatistics::start_time
std::chrono::high_resolution_clock::time_point start_time
Definition: Filter.h:41
armarx::armem::wm::EntitySnapshot
Client-side working memory entity snapshot.
Definition: memory_definitions.h:80
ImportanceFilter.h
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:40
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::aron::similarity::FloatSimilarity::NONE
@ NONE
Definition: FloatSimilarity.h:11
VAROUT
#define VAROUT(x)
Definition: StringHelpers.h:182
armarx::armem::server::ltm::processor::filter::ACCESSES
@ ACCESSES
Definition: ImportanceFilter.h:13
armarx::armem::server::ltm::processor::SnapshotFilter::FilterStatistics::additional_info
std::string additional_info
Definition: Filter.h:39
armarx::armem::server::ltm::processor::SnapshotFilter::FilterStatistics::similarity_type
aron::similarity::NDArraySimilarity::Type similarity_type
Definition: Filter.h:40
armarx::armem::server::ltm::processor::filter::SnapshotImportanceFilter::configure
void configure(const nlohmann::json &json) override
Definition: ImportanceFilter.cpp:31
armarx::armem::server::ltm::processor::filter
Definition: EqualityFilter.cpp:9
armarx::armem::base::EntityInstanceMetadata::confidence
float confidence
An optional confidence, may be used for things like decay.
Definition: EntityInstanceBase.h:54
armarx::armem::server::ltm::processor::SnapshotFilter::FilterStatistics
Definition: Filter.h:35
armarx::armem::base::EntityInstanceBase::metadata
MetadataT & metadata()
Definition: EntityInstanceBase.h:117
armarx::armem::server::ltm::processor::SnapshotFilter::FilterStatistics::accepted
double accepted
Definition: Filter.h:36
armarx::armem::server::ltm::processor::SnapshotFilter::FilterStatistics::additional_time
std::chrono::duration< double > additional_time
Definition: Filter.h:38