ImportanceFilter.cpp
Go to the documentation of this file.
1 #include "ImportanceFilter.h"
2 
4 {
5 
6  bool
8  {
9  auto start = std::chrono::high_resolution_clock::now();
10  bool instances_accepted = false;
11 
13  [this, &instances_accepted](armem::wm::EntityInstance& i)
14  {
15  if (!instances_accepted)
16  { //if no instance was accepted yet
17  instances_accepted = important(i); //see if another instance triggers acceptance
18  }
19  });
20 
21  //set stats:
22  auto end = std::chrono::high_resolution_clock::now();
23  stats.end_time = end;
24  stats.additional_time += (end - start);
25  if (instances_accepted)
26  {
27  stats.accepted += 1;
28  }
29  else
30  {
31  stats.rejected += 1;
32  }
33 
34  return instances_accepted;
35  }
36 
37  void
38  SnapshotImportanceFilter::configure(const nlohmann::json& json)
39  {
40  if (json.find(PARAM_THRESHOLD) != json.end())
41  {
42  this->threshold = json.at(PARAM_THRESHOLD);
43  ARMARX_INFO << VAROUT(this->threshold);
44  stats.additional_info += "Threshold for importance: ";
45  stats.additional_info += std::to_string(this->threshold);
46  }
47  if (json.find(PARAM_TYPE) != json.end())
48  {
49  auto t = json.at(PARAM_TYPE);
50  if (t == "Confidence")
51  {
52  this->type = ImportanceType::CONFIDENCE;
53  }
54  if (t == "Accesses")
55  {
56  this->type = ImportanceType::ACCESSES;
57  }
58  stats.importance_type = t;
60  }
61 
62  stats.start_time = std::chrono::high_resolution_clock::now();
64  stats.similarity_type =
65  aron::similarity::NDArraySimilarity::Type::NONE; //information for statistics export
66  }
67 
70  {
71  return this->stats;
72  }
73 
74  std::string
76  {
77  return this->NAME;
78  }
79 
80  bool
81  SnapshotImportanceFilter::important(armem::wm::EntityInstance& i)
82  {
83  if (this->type == ImportanceType::CONFIDENCE)
84  {
85  auto c = i.metadata().confidence;
86  if (c > this->threshold)
87  {
88  //for now the whole entity snapshot is accepted if at least one instance has a confidence higher than the threshold
89  return true;
90  }
91  }
92  else if (this->type == ImportanceType::ACCESSES)
93  {
94  auto a = i.metadata().numAccessed;
95  if (a > this->threshold)
96  {
97  return true;
98  }
99  }
100  return false;
101  }
102 
103 
104 } // namespace armarx::armem::server::ltm::processor::filter
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:43
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::getName
std::string getName() override
Definition: ImportanceFilter.cpp:75
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
armarx::armem::server::ltm::processor::SnapshotFilter::FilterStatistics::rejected
double rejected
Definition: Filter.h:38
armarx::armem::server::ltm::processor::filter::CONFIDENCE
@ CONFIDENCE
Definition: ImportanceFilter.h:13
armarx::armem::server::ltm::processor::SnapshotFilter::FilterStatistics::importance_type
std::string importance_type
Definition: Filter.h:45
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:44
armarx::armem::server::ltm::processor::filter::SnapshotImportanceFilter::getFilterStatistics
FilterStatistics getFilterStatistics() override
Definition: ImportanceFilter.cpp:69
armarx::armem::server::ltm::processor::SnapshotFilter::FilterStatistics::start_time
std::chrono::high_resolution_clock::time_point start_time
Definition: Filter.h:42
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:41
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
armarx::aron::similarity::FloatSimilarity::NONE
@ NONE
Definition: FloatSimilarity.h:14
VAROUT
#define VAROUT(x)
Definition: StringHelpers.h:198
armarx::armem::server::ltm::processor::filter::ACCESSES
@ ACCESSES
Definition: ImportanceFilter.h:14
armarx::armem::server::ltm::processor::SnapshotFilter::FilterStatistics::additional_info
std::string additional_info
Definition: Filter.h:40
armarx::armem::server::ltm::processor::SnapshotFilter::FilterStatistics::similarity_type
aron::similarity::NDArraySimilarity::Type similarity_type
Definition: Filter.h:41
armarx::armem::server::ltm::processor::filter::SnapshotImportanceFilter::configure
void configure(const nlohmann::json &json) override
Definition: ImportanceFilter.cpp:38
armarx::armem::server::ltm::processor::filter
Definition: EqualityFilter.cpp:10
armarx::armem::server::ltm::processor::filter::SnapshotImportanceFilter::accept
virtual bool accept(const armem::wm::EntitySnapshot &e, bool simulatedVersion) override
Definition: ImportanceFilter.cpp:7
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:37
armarx::armem::server::ltm::processor::SnapshotFilter::FilterStatistics::additional_time
std::chrono::duration< double > additional_time
Definition: Filter.h:39