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-2009 Soeren Sonnenburg 00008 * Copyright (C) 1999-2009 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 float64_t CDistribution::get_log_likelihood_sample() 00025 { 00026 ASSERT(features); 00027 00028 float64_t sum=0; 00029 for (int32_t 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(float64_t **dst, int32_t *num) 00036 { 00037 ASSERT(features); 00038 00039 *num=features->get_num_vectors(); 00040 size_t sz=sizeof(float64_t)*(*num); 00041 *dst=(float64_t*) malloc(sz); 00042 ASSERT(dst); 00043 00044 for (int32_t i=0; i<(*num); i++) 00045 *(*dst+i)=get_log_likelihood_example(i); 00046 } 00047 00048 int32_t CDistribution::get_num_relevant_model_parameters() 00049 { 00050 int32_t total_num=get_num_model_parameters(); 00051 int32_t num=0; 00052 00053 for (int32_t 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 }