File: mog_diag_em.h

package info (click to toggle)
libitpp 4.0.4-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 7,520 kB
  • ctags: 6,341
  • sloc: cpp: 51,608; sh: 9,248; makefile: 636; fortran: 8
file content (159 lines) | stat: -rw-r--r-- 5,601 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*!
 * \file
 * \brief Expectation Maximisation (EM) based optimisers for MOG - header file
 * \author Conrad Sanderson
 *
 * -------------------------------------------------------------------------
 *
 * IT++ - C++ library of mathematical, signal processing, speech processing,
 *        and communications classes and functions
 *
 * Copyright (C) 1995-2008  (see AUTHORS file for a list of contributors)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 *
 * -------------------------------------------------------------------------
 */

#ifndef MOG_DIAG_EM_H
#define MOG_DIAG_EM_H

#include <itpp/stat/mog_diag.h>


namespace itpp {

  /*!
    \brief support class for MOG_diag_ML() and MOG_diag_MAP()
    \author Conrad Sanderson
  */
  class MOG_diag_EM_sup : public MOG_diag {

    public:

    //! Default constructor
    MOG_diag_EM_sup() { verbose=false; }

    //! Default destructor
    ~MOG_diag_EM_sup() { }

    //! ADD DOCUMENTATION HERE
    void ml(MOG_diag &model_in, Array<vec> &X_in, int max_iter_in=10, double var_floor_in=0.0, double weight_floor_in=0.0, bool verbose_in=false);
    //! ADD DOCUMENTATION HERE
    void map(MOG_diag &model_in, MOG_diag &prior_model, Array<vec> &X_in, int max_iter_in=10, double alpha_in=0.5, double var_floor_in=0.0, double weight_floor_in=0.0, bool verbose_in=false);

    protected:

    //! Whether we print the progress
    bool verbose;

    //! number of training vectors
    int N;

    //! Maximum number of iterations
    int max_iter;

    //! 'C' pointers to training vectors
    double ** c_X;

    //! ADD DOCUMENTATION HERE
    double var_floor;
    //! ADD DOCUMENTATION HERE
    double weight_floor;

    //! ADD DOCUMENTATION HERE
    void inline update_internals();
    //! ADD DOCUMENTATION HERE
    void inline sanitise_params();
    //! ADD DOCUMENTATION HERE
    double ml_update_params();
    //! ADD DOCUMENTATION HERE
    void ml_iterate();

    private:

    vec tmpvecK;
    vec tmpvecD;
    vec acc_loglhood_K;

    Array<vec> acc_means;
    Array<vec> acc_covs;

    double * c_tmpvecK;
    double * c_tmpvecD;
    double * c_acc_loglhood_K;

    double ** c_acc_means;
    double ** c_acc_covs;


  };

  //
  // convenience functions

  /*!
    \ingroup MOG
    \author Conrad Sanderson

    Maximum Likelihood Expectation Maximisation based optimisation of the
    parameters of an instance of the MOG_diag class. The seed values
    (starting points) are typically first obtained via MOG_diag_kmeans().
    See [CSB06] and the references therein for detailed mathematical descriptions.

    - [CSB06]
      <a href="http://ieeexplore.ieee.org/xpl/abs_free.jsp?arNumber=1561601">
      F. Cardinaux, C. Sanderson and S. Bengio,
      "User authentication via adapted statistical models of face images",
      IEEE Transactions on Signal Processing, Vol 54, No. 1, 2006, pp. 361-373.
      </a>

    \param model_in The model to optimise (MOG_diag)
    \param X_in The training data (array of vectors)
    \param max_iter_in Maximum number of iterations. Default is 10.
    \param var_floor_in Variance floor (lowest allowable variance).  Default is 0.0 (but see the note below)
    \param weight_floor_in  Weight floor (lowest allowable weight).  Default is 0.0 (but see the note below)
    \param verbose_in  Whether progress in printed.  Default is false.

    \note The variance and weight floors are set to std::numeric_limits<double>::min()
          if they are below that value. As such, they are machine dependant.
          The largest allowable weight floor is 1/K, where K is the number of Gaussians.
  */
  void MOG_diag_ML(MOG_diag &model_in, Array<vec> &X_in, int max_iter_in=10, double var_floor_in=0.0, double weight_floor_in=0.0, bool verbose_in=false);

  /*!
    NOT YET IMPLEMENTED.
    Maximum a Posteriori (MAP) Expectation Maximisation optimiser for Mixtures of Gaussians.

    \param model_in The model to optimise (MOG_diag)
    \param prior_model_in The model representing the prior
    \param X_in The training data (array of vectors)
    \param max_iter_in Maximum number of iterations
    \param alpha_in Coefficient for combining the parameters with the prior.  0 <= _alpha <= 1.
    \param var_floor_in Variance floor (lowest allowable variance).  Set to 0.0 to use the default.
    \param weight_floor_in  Weight floor (lowest allowable weight).  Set to 0.0 to use the default.
    \param verbose_in ADD DOCUMENTATION HERE

    \note NOT YET IMPLEMENTED.
    \note The variance and weight floors are set to std::numeric_limits<double>::min()
          if they are below that value.
          The largest allowable weight floor is 1/K, where K is the number of Gaussians.
  */
  void MOG_diag_MAP(MOG_diag &model_in, MOG_diag &prior_model_in, Array<vec> &X_in, int max_iter_in=10, double alpha_in=0.5, double var_floor_in=0.0, double weight_floor_in=0.0, bool verbose_in=false);

}

#endif // #ifndef MOG_DIAG_EM_H