XMM - Probabilistic Models for Motion Recognition and Mapping

xmmTrainingSet.hpp
Go to the documentation of this file.
1 /*
2  * xmmTrainingSet.hpp
3  *
4  * Multimodal Training Set
5  *
6  * Contact:
7  * - Jules Francoise <jules.francoise@ircam.fr>
8  *
9  * This code has been initially authored by Jules Francoise
10  * <http://julesfrancoise.com> during his PhD thesis, supervised by Frederic
11  * Bevilacqua <href="http://frederic-bevilacqua.net>, in the Sound Music
12  * Movement Interaction team <http://ismm.ircam.fr> of the
13  * STMS Lab - IRCAM, CNRS, UPMC (2011-2015).
14  *
15  * Copyright (C) 2015 UPMC, Ircam-Centre Pompidou.
16  *
17  * This File is part of XMM.
18  *
19  * XMM is free software: you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation, either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * XMM is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with XMM. If not, see <http://www.gnu.org/licenses/>.
31  */
32 
33 #ifndef xmmTrainingSet_h
34 #define xmmTrainingSet_h
35 
36 #include "xmmPhrase.hpp"
37 #include <map>
38 #include <set>
39 
40 namespace xmm {
46 class TrainingSet : public Writable {
47  public:
54  Multimodality multimodality = Multimodality::Unimodal);
55 
60  TrainingSet(TrainingSet const& src);
61 
66  explicit TrainingSet(Json::Value const& root);
67 
72  TrainingSet& operator=(TrainingSet const& src);
73 
79  virtual ~TrainingSet();
80 
82 
89  bool ownMemory() const;
90 
96  bool bimodal() const;
97 
99 
101 
107  bool empty() const;
108 
113  unsigned int size() const;
114 
118  std::map<int, std::shared_ptr<xmm::Phrase>>::iterator begin();
119 
123  std::map<int, std::shared_ptr<xmm::Phrase>>::iterator end();
124 
128  std::map<int, std::shared_ptr<xmm::Phrase>>::reverse_iterator rbegin();
129 
133  std::map<int, std::shared_ptr<xmm::Phrase>>::reverse_iterator rend();
134 
138  std::map<int, std::shared_ptr<xmm::Phrase>>::const_iterator cbegin() const;
139 
143  std::map<int, std::shared_ptr<xmm::Phrase>>::const_iterator cend() const;
144 
148  std::map<int, std::shared_ptr<xmm::Phrase>>::const_reverse_iterator
149  crbegin() const;
150 
154  std::map<int, std::shared_ptr<xmm::Phrase>>::const_reverse_iterator crend()
155  const;
156 
165  void addPhrase(int phraseIndex, std::string label = "");
166 
174  void addPhrase(int phraseIndex, Phrase const& phrase);
175 
184  void addPhrase(int phraseIndex, std::shared_ptr<Phrase> phrase);
185 
193  void removePhrase(int phraseIndex);
194 
202  void removePhrasesOfClass(std::string const& label);
203 
209  std::shared_ptr<xmm::Phrase> getPhrase(int phraseIndex) const;
210 
221  TrainingSet* getPhrasesOfClass(std::string const& label);
222 
228  void clear();
229 
234  const std::set<std::string>& labels() const { return labels_; }
235 
237 
239 
245  Json::Value toJson() const;
246 
252  void fromJson(Json::Value const& root);
253 
255 
257 
263  std::vector<float> mean() const;
264 
271  std::vector<float> standardDeviation() const;
272 
278  std::vector<std::pair<float, float>> minmax() const;
279 
285  void rescale(std::vector<float> offset, std::vector<float> gain);
286 
291  void normalize();
292 
294 
299 
304 
309 
310  protected:
314  void onPhraseEvent(PhraseEvent const& e);
315 
319  virtual void onAttributeChange(AttributeBase* attr_pointer);
320 
325  virtual void update();
326 
331 
335  bool bimodal_;
336 
340  std::set<std::string> labels_;
341 
347  std::map<int, std::shared_ptr<Phrase>> phrases_;
348 
352  std::map<std::string, TrainingSet> sub_training_sets_;
353 };
354 }
355 
356 #endif
std::map< int, std::shared_ptr< xmm::Phrase > >::const_iterator cend() const
constant iterator to the end of phrases
Definition: xmmTrainingSet.cpp:202
Data phrase.
Definition: xmmPhrase.hpp:133
std::map< int, std::shared_ptr< Phrase > > phrases_
Training Phrases.
Definition: xmmTrainingSet.hpp:347
std::vector< float > mean() const
Compute the global mean of all data phrases along the time axis.
Definition: xmmTrainingSet.cpp:315
std::map< int, std::shared_ptr< xmm::Phrase > >::reverse_iterator rbegin()
reverse iterator to the beginning of phrases
Definition: xmmTrainingSet.cpp:187
std::map< int, std::shared_ptr< xmm::Phrase > >::const_iterator cbegin() const
constant iterator to the beginning of phrases
Definition: xmmTrainingSet.cpp:197
bool ownMemory() const
checks if the training set is owns the data
Definition: xmmTrainingSet.cpp:132
Multimodality
Number of modalities in the data phrase.
Definition: xmmPhrase.hpp:68
Attribute< unsigned int > dimension
total dimension of the training data
Definition: xmmTrainingSet.hpp:298
std::shared_ptr< xmm::Phrase > getPhrase(int phraseIndex) const
Access Phrase by index.
Definition: xmmTrainingSet.cpp:216
TrainingSet & operator=(TrainingSet const &src)
Assignment Operator.
Definition: xmmTrainingSet.cpp:105
std::set< std::string > labels_
Set containing all the labels present in the training set.
Definition: xmmTrainingSet.hpp:340
void clear()
delete all phrases
Definition: xmmTrainingSet.cpp:270
std::vector< float > standardDeviation() const
Compute the global standard deviation of all data phrases along the time axis.
Definition: xmmTrainingSet.cpp:333
void onPhraseEvent(PhraseEvent const &e)
Monitors the training of each Model of the group.
Definition: xmmTrainingSet.cpp:284
std::map< int, std::shared_ptr< xmm::Phrase > >::reverse_iterator rend()
reverse iterator to the end of phrases
Definition: xmmTrainingSet.cpp:192
virtual void onAttributeChange(AttributeBase *attr_pointer)
notification function called when a member attribute is changed
Definition: xmmTrainingSet.cpp:142
void normalize()
normalize the training set by rescaling all phrases to the mean/std of the whole training set ...
Definition: xmmTrainingSet.cpp:401
void rescale(std::vector< float > offset, std::vector< float > gain)
rescale a phrase given an offset and gain
Definition: xmmTrainingSet.cpp:394
std::map< int, std::shared_ptr< xmm::Phrase > >::const_reverse_iterator crbegin() const
constant reverse iterator to the beginning of phrases
Definition: xmmTrainingSet.cpp:207
void removePhrase(int phraseIndex)
delete a phrase
Definition: xmmTrainingSet.cpp:250
std::map< int, std::shared_ptr< xmm::Phrase > >::iterator end()
iterator to the end of phrases
Definition: xmmTrainingSet.cpp:182
bool empty() const
checks if the training set is empty
Definition: xmmTrainingSet.cpp:136
TrainingSet * getPhrasesOfClass(std::string const &label)
get the pointer to the sub-training set containing all phrases with a given label ...
Definition: xmmTrainingSet.cpp:276
Base Class for Generic Attributes.
Definition: xmmAttribute.hpp:105
unsigned int size() const
Size of the training set.
Definition: xmmTrainingSet.cpp:138
std::vector< std::pair< float, float > > minmax() const
Compute the global min/max of all data phrases along the time axis.
Definition: xmmTrainingSet.cpp:355
Json::Value toJson() const
Write the object to a JSON Structure.
Definition: xmmTrainingSet.cpp:408
const std::set< std::string > & labels() const
get the list of labels currently in the training set
Definition: xmmTrainingSet.hpp:234
bool bimodal_
defines if the phrase is bimodal
Definition: xmmTrainingSet.hpp:335
void fromJson(Json::Value const &root)
Read the object from a JSON Structure.
Definition: xmmTrainingSet.cpp:428
Base class for the definition of training sets.
Definition: xmmTrainingSet.hpp:46
Attribute< std::vector< std::string > > column_names
labels of the columns of the training set (e.g. descriptor names)
Definition: xmmTrainingSet.hpp:308
Abstract class for handling JSON + File I/O.
Definition: xmmJson.hpp:50
void addPhrase(int phraseIndex, std::string label="")
add a new phrase, or reset the phrase if existing
Definition: xmmTrainingSet.cpp:221
virtual void update()
create all the sub-training sets: one for each label
Definition: xmmTrainingSet.cpp:290
std::map< int, std::shared_ptr< xmm::Phrase > >::const_reverse_iterator crend() const
constant reverse iterator to the end of phrases
Definition: xmmTrainingSet.cpp:212
void removePhrasesOfClass(std::string const &label)
delete all phrases of a given class
Definition: xmmTrainingSet.cpp:255
Event that can be thrown by a phrase to a training set.
Definition: xmmPhrase.hpp:88
Definition: xmmAttribute.hpp:42
std::map< int, std::shared_ptr< xmm::Phrase > >::iterator begin()
iterator to the beginning of phrases
Definition: xmmTrainingSet.cpp:178
std::map< std::string, TrainingSet > sub_training_sets_
Sub-ensembles of the training set for specific classes.
Definition: xmmTrainingSet.hpp:352
TrainingSet(MemoryMode memoryMode=MemoryMode::OwnMemory, Multimodality multimodality=Multimodality::Unimodal)
Constructor.
Definition: xmmTrainingSet.cpp:35
bool bimodal() const
checks if the training set is bimodal
Definition: xmmTrainingSet.cpp:134
single modality (i.e. 1 data array)
MemoryMode
Type of memory management for training sets and phrases.
Definition: xmmPhrase.hpp:50
Attribute< unsigned int > dimension_input
dimension of the input modality in bimodal mode
Definition: xmmTrainingSet.hpp:303
virtual ~TrainingSet()
Destructor.
Definition: xmmTrainingSet.cpp:130
bool own_memory_
defines if the phrase has its own memory
Definition: xmmTrainingSet.hpp:330
memory is owned by the Phrase container.