Log In | Get Help   
Home My Page Projects Code Snippets Project Openings Mareframe
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files
[mareframe] Annotation of /trunk/gadget/multinomial.cc
[mareframe] / trunk / gadget / multinomial.cc Repository:
ViewVC logotype

Annotation of /trunk/gadget/multinomial.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : agomez 1 #include "multinomial.h"
2 :     #include "mathfunc.h"
3 :     #include "errorhandler.h"
4 :     #include "gadget.h"
5 :     #include "global.h"
6 :    
7 :     double Multinomial::calcLogLikelihood(const DoubleVector& data, const DoubleVector& dist) {
8 :    
9 :     int i;
10 :     double minp = 1.0 / (dist.Size() * bigvalue);
11 :     double sumdist, sumdata, sumlog, likely, tmp;
12 :    
13 :     if (data.Size() != dist.Size())
14 :     handle.logMessage(LOGFAIL, "Error in multinomial - vectors not the same size");
15 :    
16 :     sumdist = sumdata = sumlog = likely = 0.0;
17 :     for (i = 0; i < data.Size(); i++) {
18 :     sumdist += dist[i];
19 :     sumdata += data[i];
20 :     sumlog += logFactorial(data[i]);
21 :     }
22 :    
23 :     if (isZero(sumdist))
24 :     return 0.0;
25 :    
26 :     tmp = 1.0 / sumdist;
27 :     for (i = 0; i < data.Size(); i++) {
28 :     if (isZero(data[i]))
29 :     likely += 0.0;
30 :     else if (((dist[i] * tmp) > minp) || (isEqual((dist[i] * tmp), minp)))
31 :     likely -= data[i] * log(dist[i] * tmp);
32 :     else
33 :     likely -= data[i] * log(minp);
34 :     }
35 :    
36 :     sumlog -= logFactorial(sumdata);
37 :     tmp = 2.0 * (likely + sumlog);
38 :     if (tmp < 0.0)
39 :     handle.logMessage(LOGWARN, "Warning in multinomial - negative total", tmp);
40 :    
41 :     loglikelihood += tmp;
42 :     return tmp;
43 :     }

root@forge.cesga.es
ViewVC Help
Powered by ViewVC 1.0.0  

Powered By FusionForge