Distribution.cpp

Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 1999-2008 Soeren Sonnenburg
00008  * Copyright (C) 1999-2008 Fraunhofer Institute FIRST and Max-Planck-Society
00009  */
00010 
00011 #include "distributions/Distribution.h"
00012 #include "lib/Mathematics.h"
00013 
00014 CDistribution::CDistribution()
00015 : CSGObject(), features(NULL), pseudo_count(1e-10)
00016 {
00017 }
00018 
00019 
00020 CDistribution::~CDistribution()
00021 {
00022 }
00023 
00024 DREAL CDistribution::get_log_likelihood_sample()
00025 {
00026     ASSERT(features);
00027 
00028     DREAL sum=0;
00029     for (INT i=0; i<features->get_num_vectors(); i++)
00030         sum+=get_log_likelihood_example(i);
00031 
00032     return sum/features->get_num_vectors();
00033 }
00034 
00035 void CDistribution::get_log_likelihood(DREAL **dst, INT *num)
00036 {
00037     ASSERT(features);
00038 
00039     *num=features->get_num_vectors();
00040     size_t sz=sizeof(DREAL)*(*num);
00041     *dst=(DREAL*) malloc(sz);
00042     ASSERT(dst);
00043 
00044     for (INT i=0; i<(*num); i++)
00045         *(*dst+i)=get_log_likelihood_example(i);
00046 }
00047 
00048 INT CDistribution::get_num_relevant_model_parameters()
00049 {
00050     INT total_num=get_num_model_parameters();
00051     INT num=0;
00052 
00053     for (INT i=0; i<total_num; i++)
00054     {
00055         if (get_log_model_parameter(i)>CMath::ALMOST_NEG_INFTY)
00056             num++;
00057     }
00058     return num;
00059 }

SHOGUN Machine Learning Toolbox - Documentation