Main Page · Modules · All Classes · Class Hierarchy
MAAnalyzer.hpp
1 /*
2  * This file is part of the AiBO+ project
3  *
4  * Copyright (C) 2005-2016 Csaba Kertész (csaba.kertesz@gmail.com)
5  *
6  * AiBO+ is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * AiBO+ is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
19  *
20  */
21 
22 #pragma once
23 
24 #include "core/MACoreTypes.hpp"
25 
26 #include <MCLog.hpp>
27 
28 class MARobotState;
29 
30 #define MA_ANALYZER_ADD_FEATURE_NAME(_name) \
31  if (unlikely(!FeatureNamesReady)) \
32  { \
33  FeatureNames.push_back(#_name); \
34  }
35 
36 #define MA_ANALYZER_ADD_FEATURE_NAME_STR(_name) \
37  if (unlikely(!FeatureNamesReady)) \
38  { \
39  FeatureNames.push_back(_name); \
40  }
41 
42 #define MA_ANALYZER_ADD_FEATURE_NAME_WITH_INDEX(_name, _index) \
43  if (unlikely(!FeatureNamesReady)) \
44  { \
45  FeatureNames.push_back(std::string("\"")+#_name+MCToStr(_index)+'"'); \
46  }
47 
48 #define MA_ANALYZER_FEATURE_NAMES_COMMIT(_features) \
49  if (unlikely(!FeatureNamesReady)) \
50  { \
51  FeatureNamesReady = true; \
52  if (FeatureNames.size() != _features.size()) \
53  { \
54  MC_WARNING("Feature name and feature count are different (%d != %d)", \
55  FeatureNames.size(), _features.size()); \
56  } \
57  }
58 
68 {
69 public:
70  MAAnalyzer();
71  virtual ~MAAnalyzer() { };
72 
80  const MC::StringList& GetFeatureNames() const;
81 
89  virtual void AddSamples(const MARobotState& robot_state) = 0;
90 
96  virtual void Reset() = 0;
97 
105  virtual bool IsValid() const = 0;
106 
114  virtual MC::FloatList GetFeatureVector() = 0;
115 
130  static MC::FloatTable CompactFeatureVectors(const MC::FloatTable& feature_vectors,
131  const unsigned int window_size);
132 
133 protected:
135  MC::StringList FeatureNames;
138 };
139 
static MC::FloatTable CompactFeatureVectors(const MC::FloatTable &feature_vectors, const unsigned int window_size)
Compacting the feature vectors.
Definition: MAAnalyzer.cpp:37
Analyzer base class.
Definition: MAAnalyzer.hpp:67
bool FeatureNamesReady
Whether the feature names are defined.
Definition: MAAnalyzer.hpp:137
virtual bool IsValid() const =0
Check if enough samples were added to the analyzer.
virtual MC::FloatList GetFeatureVector()=0
Get a feature vector.
virtual void Reset()=0
Reset the analyzer and drop all samples.
MC::StringList FeatureNames
Feature names.
Definition: MAAnalyzer.hpp:135
virtual void AddSamples(const MARobotState &robot_state)=0
Add new samples from the robot state.
const MC::StringList & GetFeatureNames() const
Get the feature names.
Definition: MAAnalyzer.cpp:31
Robot state.