fix crash when copy'ing latent plugins
[ardour.git] / libs / qm-dsp / maths / KLDivergence.h
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
2
3 /*
4     QM DSP Library
5
6     Centre for Digital Music, Queen Mary, University of London.
7     This file copyright 2008 QMUL.
8
9     This program is free software; you can redistribute it and/or
10     modify it under the terms of the GNU General Public License as
11     published by the Free Software Foundation; either version 2 of the
12     License, or (at your option) any later version.  See the file
13     COPYING included with this distribution for more information.
14 */
15
16 #ifndef KLDIVERGENCE_H
17 #define KLDIVERGENCE_H
18
19 #include <vector>
20
21 using std::vector;
22
23 /**
24  * Helper methods for calculating Kullback-Leibler divergences.
25  */
26 class KLDivergence
27 {
28 public:
29     KLDivergence() { }
30     ~KLDivergence() { }
31
32     /**
33      * Calculate a symmetrised Kullback-Leibler divergence of Gaussian
34      * models based on mean and variance vectors.  All input vectors
35      * must be of equal size.
36      */
37     double distanceGaussian(const vector<double> &means1,
38                             const vector<double> &variances1,
39                             const vector<double> &means2,
40                             const vector<double> &variances2);
41
42     /**
43      * Calculate a Kullback-Leibler divergence of two probability
44      * distributions.  Input vectors must be of equal size.  If
45      * symmetrised is true, the result will be the symmetrised
46      * distance (equal to KL(d1, d2) + KL(d2, d1)).
47      */
48     double distanceDistribution(const vector<double> &d1,
49                                 const vector<double> &d2,
50                                 bool symmetrised);
51 };
52
53 #endif
54