Main Page · Modules · All Classes · Class Hierarchy
MAAnalyzer.cpp
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 #include "MAAnalyzer.hpp"
23 
24 #include <MCContainers.hpp>
25 
26 MAAnalyzer::MAAnalyzer() : FeatureNamesReady(false)
27 {
28 }
29 
30 
31 const MC::StringList& MAAnalyzer::GetFeatureNames() const
32 {
33  return FeatureNames;
34 }
35 
36 
37 MC::FloatTable MAAnalyzer::CompactFeatureVectors(const MC::FloatTable& feature_vectors,
38  const unsigned int window_size)
39 {
40  if (feature_vectors.empty() || window_size < 3)
41  return MC::FloatTable();
42 
43  MC::FloatTable CompactTable;
44 
45  for (int i = 0; i < (int)feature_vectors.size(); i += (int)window_size / 3)
46  {
47  // Skip the last window if it is too small
48  if (feature_vectors.size()-i < window_size)
49  break;
50 
51  const int FrameSize = (i <= (int)feature_vectors.size()-(int)window_size ? (int)window_size :
52  (int)feature_vectors.size()-i);
53  MC::FloatTable TempTable(feature_vectors.begin()+i, feature_vectors.begin()+i+FrameSize);
54 
55  // Mean and standard deviation can't be calculated for a one-row table
56  if (TempTable.size() == 1)
57  break;
58  MC::FloatTable Results = MCCalculateMeanStDevForTableColumns(TempTable);
59 
60  MCMergeContainers(Results[0], Results[1]);
61  CompactTable.push_back(Results[0]);
62  }
63  return CompactTable;
64 }
static MC::FloatTable CompactFeatureVectors(const MC::FloatTable &feature_vectors, const unsigned int window_size)
Compacting the feature vectors.
Definition: MAAnalyzer.cpp:37
void MCMergeContainers(U &target, const U &other)
Merge two containers.
const MC::StringList & GetFeatureNames() const
Get the feature names.
Definition: MAAnalyzer.cpp:31
std::vector< std::vector< float > > MCCalculateMeanStDevForTableColumns(const V &table)
Calculate standard deviation and arithmetic mean for table columns.