faif
ExpectationMaximization.hpp
1 #ifndef FAIF_SEARCH_EM_H
2 #define FAIF_SEARCH_EM_H
3 
4 //
5 //file with Excpectation Maximization algorithm
6 //
7 
8 #include "Space.hpp"
9 
10 namespace faif {
11  namespace search {
12 
13  /** \brief expectation policy (empty)
14  */
15  template<typename Space> struct ExpectationNone {
16 
17  typedef typename Space::Individual Individual;
18 
19  /** \brief expectation is an empty operation */
20  static Individual& expectation(Individual& p) {
21  return p;
22  }
23  };
24 
25  /** \brief expectation policy - custiom
26  */
27  template<typename Space> struct ExpectationCustom {
28 
29  typedef typename Space::Individual Individual;
30 
31  /** \brief expectation calls the method from template parameter */
32  static Individual& expectation(Individual& p) {
33  return Space::expectation(p);
34  }
35  };
36 
37  /** \brief maximization policy (empty)
38 n
39  */
40  template<typename Space> struct MaximizationNone {
41 
42  typedef typename Space::Individual Individual;
43 
44  /** \brief expectation is an empty operation */
45  static Individual& maximization( Individual& p) {
46  return p;
47  }
48  };
49 
50  /** \brief maximization policy - custiom
51  */
52  template<typename Space> struct MaximizationCustom {
53 
54  typedef typename Space::Individual Individual;
55 
56  /** \brief expectation calls the method from template parameter */
57  static Individual& maximization( Individual& p) {
58  return Space::maximization(p);
59  }
60  };
61 
62  /** \brief the Expectation-Maximization algorithm
63 
64  \param Expectation: ExpectationNone, ExpectationCustom
65  \param Maximization: MaximizationNone, MaximizationCustom
66  \param Stop: StopAfterNSteps
67  */
68  template< typename Space,
69  template <typename> class Expectation = ExpectationNone,
70  template <typename> class Maximization = MaximizationNone,
71  typename StopCondition = StopAfterNSteps<100>
72  >
74  public:
76 
77  typedef typename Space::Individual Individual;
78  typedef typename Space::Fitness Fitness;
79 
80  /** \brief the evolutionary algorithm - until stop repeat mutation, cross-over, selection, succession.
81  Modifies the initial population.
82  */
83  Individual& solve(Individual& init, StopCondition stop = StopCondition() ) {
84 
85  //the fitness is required
86  BOOST_CONCEPT_ASSERT((SpaceConcept<Space>));
87 
88  Individual& current(init);
89  stop.update(current);
90  while( !stop.isFinished() ) {
91  Expectation<Space>::expectation(current);
92  Maximization<Space>::maximization(current);
93  stop.update(current);
94  }
95  return current;
96  }
97  };
98 
99  } //namespace search
100 } //namespace faif
101 
102 #endif // FAIF_SEARCH_EM_H
maximization policy (empty) n
Definition: ExpectationMaximization.hpp:40
static Individual & expectation(Individual &p)
expectation calls the method from template parameter
Definition: ExpectationMaximization.hpp:32
Definition: Chain.h:17
the Expectation-Maximization algorithm
Definition: ExpectationMaximization.hpp:73
maximization policy - custiom
Definition: ExpectationMaximization.hpp:52
static Individual & expectation(Individual &p)
expectation is an empty operation
Definition: ExpectationMaximization.hpp:20
static Individual & maximization(Individual &p)
expectation calls the method from template parameter
Definition: ExpectationMaximization.hpp:57
the typedef-s for space, where the fitness is defined as double
Definition: Space.hpp:25
Stop condition, finish the algorithm after STEPS_NUM iterations.
Definition: Space.hpp:46
expectation policy (empty)
Definition: ExpectationMaximization.hpp:15
the concept for space with fitness
Definition: Space.hpp:33
static Individual & maximization(Individual &p)
expectation is an empty operation
Definition: ExpectationMaximization.hpp:45
expectation policy - custiom
Definition: ExpectationMaximization.hpp:27
Individual & solve(Individual &init, StopCondition stop=StopCondition())
the evolutionary algorithm - until stop repeat mutation, cross-over, selection, succession. Modifies the initial population.
Definition: ExpectationMaximization.hpp:83