NDArraySimilarity.cpp
Go to the documentation of this file.
1 #include "NDArraySimilarity.h"
2 
3 #include <cmath>
4 #include "mse.h"
5 #include "mae.h"
6 #include "chernoff.h"
7 #include "../../cosine.h"
8 
10 
11 
13  {
14  switch(type){
15  case Type::MSE:
16  //ARMARX_INFO << "Calculate MSE";
18  case Type::MAE:
20  case Type::CHERNOFF:
22  case Type::COSINE:
24  default:
25  ARMARX_WARNING << "Trying to calculate similarity with unspecified similarity measurement";
26  return -1;
27  }
28  }
29 
31  {
32  switch(t){
33  case MSE:
34  return "MSE";
35  case MAE:
36  return "MAE";
37  case CHERNOFF:
38  return "Chernoff";
39  case COSINE:
40  return "Cosine";
41  default:
42  return "No similarity type information";
43  }
44  }
45 
46  double NDArraySimilarity::calculate_similarity_multi(std::vector<data::NDArrayPtr> images, armarx::aron::data::NDArrayPtr p, Type type)
47  {
48  double sim = 0;
49  for(auto& image: images){
50  //ARMARX_INFO << "Before calculation";
51  sim += calculate_similarity(image, p, type);
52  //ARMARX_INFO << "Sim is currently: " << sim;
53  }
54  return sim / (images.size() + 1); // to average it over the distances, makes it easier to find good parameters
55  }
56 
57 }
armarx::aron::similarity::NDArraySimilarity::CHERNOFF
@ CHERNOFF
Definition: NDArraySimilarity.h:11
mse.h
armarx::aron::similarity::mse::compute_similarity
double compute_similarity(const aron::data::NDArrayPtr p1, const aron::data::NDArrayPtr p2)
Definition: mse.cpp:9
armarx::aron::similarity
Definition: cosine.cpp:6
armarx::aron::data::NDArrayPtr
std::shared_ptr< NDArray > NDArrayPtr
Definition: NDArray.h:46
armarx::aron::similarity::FloatSimilarity::MAE
@ MAE
Definition: FloatSimilarity.h:10
armarx::aron::similarity::chernoff::compute_similarity
double compute_similarity(const aron::data::NDArrayPtr p1, const aron::data::NDArrayPtr p2)
Definition: chernoff.cpp:10
armarx::aron::similarity::NDArraySimilarity::COSINE
@ COSINE
Definition: NDArraySimilarity.h:12
armarx::aron::similarity::NDArraySimilarity::to_string
std::string to_string(Type t)
Definition: NDArraySimilarity.cpp:30
armarx::aron::similarity::FloatSimilarity::MSE
@ MSE
Definition: FloatSimilarity.h:9
mae.h
armarx::aron::similarity::cosine::compute_similarity
double compute_similarity(const aron::data::NDArrayPtr p1, const aron::data::NDArrayPtr p2)
Definition: cosine.cpp:9
armarx::aron::similarity::NDArraySimilarity::calculate_similarity_multi
double calculate_similarity_multi(std::vector< armarx::aron::data::NDArrayPtr > images, armarx::aron::data::NDArrayPtr p, Type type)
calculate_similarity_multi compares the image p with all images from the images vector,...
Definition: NDArraySimilarity.cpp:46
armarx::aron::similarity::FloatSimilarity::calculate_similarity
double calculate_similarity(armarx::aron::data::FloatPtr f1, armarx::aron::data::FloatPtr f2, Type t)
Definition: FloatSimilarity.cpp:7
NDArraySimilarity.h
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
chernoff.h
armarx::aron::similarity::NDArraySimilarity::Type
Type
Definition: NDArraySimilarity.h:8
armarx::aron::similarity::NDArraySimilarity::calculate_similarity
double calculate_similarity(armarx::aron::data::NDArrayPtr p1, armarx::aron::data::NDArrayPtr p2, Type type)
Definition: NDArraySimilarity.cpp:12
armarx::aron::similarity::mae::compute_similarity
double compute_similarity(const data::NDArrayPtr p1, const data::NDArrayPtr p2)
Definition: mae.cpp:6