/usr/share/doc/libitpp-dev/html/mog.html is in libitpp-doc 4.3.1-8.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Welcome to IT++!</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
<link rel="shortcut icon" href="favicon.ico">
</head>
<body>
<div style="width: 100%; height: 40px; background-color: #ffff00; border: 1px solid #b0b0b0; margin: 5px 5px 5px 0; padding: 2px;">
<a href="http://itpp.sourceforge.net"><img src="itpp_logo.png" alt="IT++ Logo" style="float: left; border: 0;"></a>
</div>
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
initMenu('',true,true,'search.php','Search');
$(document).ready(function() {
if ($('.searchresults').length > 0) { searchBox.DOMSearchField().focus(); }
});
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">Using Mixture of Gaussians (MOG) module to model data </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>This example demonstrates how to find the parameters of a MOG model via using the kmeans and EM based optimisers. Synthetic data is utilised.</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include <<a class="code" href="itstat_8h.html">itpp/itstat.h</a>></span></div><div class="line"></div><div class="line"><span class="preprocessor">#include <fstream></span></div><div class="line"><span class="preprocessor">#include <iostream></span></div><div class="line"><span class="preprocessor">#include <iomanip></span></div><div class="line"><span class="preprocessor">#include <ios></span></div><div class="line"></div><div class="line"><span class="keyword">using</span> std::cout;</div><div class="line"><span class="keyword">using</span> std::endl;</div><div class="line"><span class="keyword">using</span> std::fixed;</div><div class="line"><span class="keyword">using</span> std::setprecision;</div><div class="line"></div><div class="line"><span class="keyword">using namespace </span><a class="code" href="namespaceitpp.html">itpp</a>;</div><div class="line"></div><div class="line"><span class="keywordtype">int</span> main()</div><div class="line">{</div><div class="line"></div><div class="line"> <span class="keywordtype">bool</span> print_progress = <span class="keyword">false</span>;</div><div class="line"></div><div class="line"> <span class="comment">//</span></div><div class="line"> <span class="comment">// first, let's generate some synthetic data</span></div><div class="line"></div><div class="line"> <span class="keywordtype">int</span> N = 100000; <span class="comment">// number of vectors</span></div><div class="line"> <span class="keywordtype">int</span> D = 3; <span class="comment">// number of dimensions</span></div><div class="line"> <span class="keywordtype">int</span> K = 5; <span class="comment">// number of Gaussians</span></div><div class="line"></div><div class="line"> <a class="code" href="classitpp_1_1Array.html">Array<vec></a> X(N);</div><div class="line"> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> n = 0;n < N;n++) { X(n).set_size(D); X(n) = 0.0; }</div><div class="line"></div><div class="line"> <span class="comment">// the means</span></div><div class="line"></div><div class="line"> <a class="code" href="classitpp_1_1Array.html">Array<vec></a> mu(K);</div><div class="line"> mu(0) = <span class="stringliteral">"-6, -4, -2"</span>;</div><div class="line"> mu(1) = <span class="stringliteral">"-4, -2, 0"</span>;</div><div class="line"> mu(2) = <span class="stringliteral">"-2, 0, 2"</span>;</div><div class="line"> mu(3) = <span class="stringliteral">" 0, +2, +4"</span>;</div><div class="line"> mu(4) = <span class="stringliteral">"+2, +4, +6"</span>;</div><div class="line"></div><div class="line"></div><div class="line"> <span class="comment">// the diagonal variances</span></div><div class="line"></div><div class="line"> <a class="code" href="classitpp_1_1Array.html">Array<vec></a> var(K);</div><div class="line"> var(0) = <span class="stringliteral">"0.1, 0.2, 0.3"</span>;</div><div class="line"> var(1) = <span class="stringliteral">"0.2, 0.3, 0.1"</span>;</div><div class="line"> var(2) = <span class="stringliteral">"0.3, 0.1, 0.2"</span>;</div><div class="line"> var(3) = <span class="stringliteral">"0.1, 0.2, 0.3"</span>;</div><div class="line"> var(4) = <span class="stringliteral">"0.2, 0.3, 0.1"</span>;</div><div class="line"></div><div class="line"> cout << fixed << setprecision(3);</div><div class="line"> cout << <span class="stringliteral">"user configured means and variances:"</span> << endl;</div><div class="line"> cout << <span class="stringliteral">"mu = "</span> << mu << endl;</div><div class="line"> cout << <span class="stringliteral">"var = "</span> << var << endl;</div><div class="line"></div><div class="line"> <span class="comment">// randomise the order of Gaussians "generating" the vectors</span></div><div class="line"> <a class="code" href="classitpp_1_1I__Uniform__RNG.html">I_Uniform_RNG</a> rnd_uniform(0, K - 1);</div><div class="line"> ivec gaus_id = rnd_uniform(N);</div><div class="line"></div><div class="line"> ivec gaus_count(K);</div><div class="line"> gaus_count = 0;</div><div class="line"> <a class="code" href="classitpp_1_1Array.html">Array<vec></a> mu_test(K);</div><div class="line"> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> k = 0;k < K;k++) { mu_test(k).set_size(D); mu_test(k) = 0.0; }</div><div class="line"> <a class="code" href="classitpp_1_1Array.html">Array<vec></a> var_test(K);</div><div class="line"> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> k = 0;k < K;k++) { var_test(k).set_size(D); var_test(k) = 0.0; }</div><div class="line"></div><div class="line"> <a class="code" href="classitpp_1_1Normal__RNG.html">Normal_RNG</a> rnd_normal;</div><div class="line"> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> n = 0;n < N;n++) {</div><div class="line"></div><div class="line"> <span class="keywordtype">int</span> k = gaus_id(n);</div><div class="line"> gaus_count(k)++;</div><div class="line"></div><div class="line"> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> d = 0;d < D;d++) {</div><div class="line"> rnd_normal.<a class="code" href="classitpp_1_1Normal__RNG.html#a9c50b4c9b0bb07c69c9fbf16b9f01521">setup</a>(mu(k)(d), var(k)(d));</div><div class="line"> <span class="keywordtype">double</span> tmp = rnd_normal();</div><div class="line"> X(n)(d) = tmp;</div><div class="line"> mu_test(k)(d) += tmp;</div><div class="line"> }</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="comment">//</span></div><div class="line"> <span class="comment">// find the stats for the generated data</span></div><div class="line"></div><div class="line"> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> k = 0;k < K;k++) mu_test(k) /= gaus_count(k);</div><div class="line"></div><div class="line"> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> n = 0;n < N;n++) {</div><div class="line"> <span class="keywordtype">int</span> k = gaus_id(n);</div><div class="line"></div><div class="line"> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> d = 0;d < D;d++) {</div><div class="line"> <span class="keywordtype">double</span> tmp = X(n)(d) - mu_test(k)(d);</div><div class="line"> var_test(k)(d) += tmp * tmp;</div><div class="line"> }</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> k = 0;k < K;k++) var_test(k) /= (gaus_count(k) - 1.0);</div><div class="line"></div><div class="line"> cout << endl << endl;</div><div class="line"> cout << fixed << setprecision(3);</div><div class="line"> cout << <span class="stringliteral">"stats for X:"</span> << endl;</div><div class="line"></div><div class="line"> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> k = 0;k < K;k++) {</div><div class="line"> cout << <span class="stringliteral">"k = "</span> << k << <span class="stringliteral">" count = "</span> << gaus_count(k) << <span class="stringliteral">" weight = "</span> << gaus_count(k) / double(N) << endl;</div><div class="line"> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> d = 0;d < D;d++) cout << <span class="stringliteral">" d = "</span> << d << <span class="stringliteral">" mu_test = "</span> << mu_test(k)(d) << <span class="stringliteral">" var_test = "</span> << var_test(k)(d) << endl;</div><div class="line"> cout << endl;</div><div class="line"> }</div><div class="line"></div><div class="line"></div><div class="line"> <span class="comment">// make a model with initial values (zero mean and unit variance)</span></div><div class="line"> <span class="comment">// the number of gaussians and dimensions of the model is specified here</span></div><div class="line"></div><div class="line"> <a class="code" href="classitpp_1_1MOG__diag.html">MOG_diag</a> mog(K, D);</div><div class="line"></div><div class="line"> cout << endl;</div><div class="line"> cout << fixed << setprecision(3);</div><div class="line"> cout << <span class="stringliteral">"mog.avg_log_lhood(X) = "</span> << mog.avg_log_lhood(X) << endl;</div><div class="line"></div><div class="line"> <span class="comment">//</span></div><div class="line"> <span class="comment">// find initial parameters via k-means (which are then used as seeds for EM based optimisation)</span></div><div class="line"></div><div class="line"> cout << endl << endl;</div><div class="line"> cout << <span class="stringliteral">"running kmeans optimiser"</span> << endl << endl;</div><div class="line"></div><div class="line"> <a class="code" href="group__MOG.html#gadeb91bf337a38234135d6d402e3143b3">MOG_diag_kmeans</a>(mog, X, 10, 0.5, <span class="keyword">true</span>, print_progress);</div><div class="line"></div><div class="line"> cout << fixed << setprecision(3);</div><div class="line"> cout << <span class="stringliteral">"mog.get_means() = "</span> << endl << mog.get_means() << endl;</div><div class="line"> cout << <span class="stringliteral">"mog.get_diag_covs() = "</span> << endl << mog.get_diag_covs() << endl;</div><div class="line"> cout << <span class="stringliteral">"mog.get_weights() = "</span> << endl << mog.get_weights() << endl;</div><div class="line"></div><div class="line"> cout << endl;</div><div class="line"> cout << <span class="stringliteral">"mog.avg_log_lhood(X) = "</span> << mog.avg_log_lhood(X) << endl;</div><div class="line"></div><div class="line"></div><div class="line"> <span class="comment">//</span></div><div class="line"> <span class="comment">// EM ML based optimisation</span></div><div class="line"></div><div class="line"> cout << endl << endl;</div><div class="line"> cout << <span class="stringliteral">"running ML optimiser"</span> << endl << endl;</div><div class="line"></div><div class="line"> <a class="code" href="group__MOG.html#ga7b86d84e61a3056418f08b7ac0686805">MOG_diag_ML</a>(mog, X, 10, 0.0, 0.0, print_progress);</div><div class="line"></div><div class="line"> cout << fixed << setprecision(3);</div><div class="line"> cout << <span class="stringliteral">"mog.get_means() = "</span> << endl << mog.get_means() << endl;</div><div class="line"> cout << <span class="stringliteral">"mog.get_diag_covs() = "</span> << endl << mog.get_diag_covs() << endl;</div><div class="line"> cout << <span class="stringliteral">"mog.get_weights() = "</span> << endl << mog.get_weights() << endl;</div><div class="line"></div><div class="line"> cout << endl;</div><div class="line"> cout << <span class="stringliteral">"mog.avg_log_lhood(X) = "</span> << mog.avg_log_lhood(X) << endl;</div><div class="line"></div><div class="line"> <span class="keywordflow">return</span> 0;</div><div class="line">}</div></div><!-- fragment --> </div></div><!-- contents -->
<div style="clear: both; width: 100%; height: 31px; background-color: #ffff00; border: 1px solid #b0b0b0; margin: 5px 5px 5px 0; padding: 2px;">
<p style="padding-left: 10px; font-size: 85%;">Generated on Sat Sep 30 2017 07:04:09 for IT++ by <a href="http://www.doxygen.org/index.html">Doxygen</a> 1.8.13</p>
</div>
</body>
</html>
|