10 #ifndef MARKOV_HPP_INCLUDED
11 #define MARKOV_HPP_INCLUDED
15 #include "Database.hpp"
21 #include <boost/type_traits.hpp>
22 #include <boost/rational.hpp>
44 using ObsId = unsigned;
45 using StateId = unsigned;
76 virtual void saveToFile(
const std::string & fname)
const = 0;
79 virtual void learn(
Database& db,
const std::string& style) = 0;
101 class HMM_backend : public
HMM
103 static_assert(boost::has_left_shift<std::ostream,Obs>::value,
"error : the template argument Obs must provide a stream operator to ostream");
104 static_assert(function_traits::has_TypeID<Obs>::value,
"error : the template argument Obs must provide a static member describing its type id");
105 static_assert(function_traits::has_getClosestObs<Obs,HMM::ObsId(
const std::vector<Obs>&)>::value,
"error : the template argument must provide a public getClosestObs method of type std::vector<Obs> -> ObsId");
110 friend class HMM_backend;
116 operator unsigned()
const{
return m_stateID;};
144 void saveToFile(
const std::string & fname)
const;
148 void learn(
Database& db,
const std::string& style);
149 void learn_unsupervised(
Database& db,
const std::string& style);
152 void forwardProcedure(
const std::vector<Obs> & o);
153 void backwardProcedure(
const std::vector<Obs> & o);
154 void updateProcedure(
const std::vector<Obs> & o);
155 void generateObsSet(
const std::vector<Data>& entries);
158 std::vector<Proba> m_pi;
159 std::vector<State> m_states;
160 std::vector<std::vector<Proba> > m_transition;
161 std::vector<std::vector<Proba> > m_observation;
162 std::vector<Obs> m_obsSet;
164 std::vector<std::vector<Proba>> m_alpha;
165 std::vector<std::vector<Proba>> m_beta;
176 #include "Markov.cpp"
177 #endif // MARKOV_HPP_INCLUDED
virtual void saveToFile(const std::string &fname) const =0
Save the class to a given file.
#define CREATE_MEMBER_DETECTOR(X)
Definition: Traits.hpp:106
This file contains the descriptions of what can be observation types. Each observation class should i...
unsigned m_position
Position of the chord in the progression (rank, between 1 and 4)
Definition: Markov.hpp:112
double Proba
Return a list of chord progressions with scores.
Definition: Markov.hpp:43
This file contains useful traits to check some properties of class (namely the implementation of stat...
This file defines all the data structures related to music objects.
#define CREATE_STATIC_MEMBER_DETECTOR(X)
Definition: Traits.hpp:127
Describes a melody.
Definition: Music.hpp:629
Definition: Markov.hpp:107
Describe a chord.
Definition: Music.hpp:502
HMM * loadFromFile(std::string fname)
Load the HMM from a given file.
Unified interface for HMMs, independant of the observation type.
Definition: Markov.hpp:30
input operator for NoteName The format is capital or small letters for the NoteName ...
Definition: Database.hpp:101
Backend for a Hidden Markov Model object, templated over the observation type.
Definition: Markov.hpp:101
void saveToFile(const std::string &fname) const
Save the class to a given file.
virtual std::vector< std::pair< ChordProgression, Score > > getBestProgressions(Melody M, unsigned n=1) const =0
Return a list of chord progressions with scores.
unsigned getMaxProgressionsNbr() const
virtual unsigned getMaxProgressionsNbr() const =0
friend HMM * loadFromFile(std::string fname)
Load the HMM from a given file.
std::vector< std::pair< ChordProgression, Score > > getBestProgressions(Melody M, unsigned n=1) const
Return a list of chord progressions with scores.
Chord m_c
Description of the chord.
Definition: Markov.hpp:111