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 using namespace shogun; 00015 00016 CDistribution::CDistribution() 00017 : CSGObject(), features(NULL), pseudo_count(1e-10) 00018 { 00019 } 00020 00021 00022 CDistribution::~CDistribution() 00023 { 00024 } 00025 00026 float64_t CDistribution::get_log_likelihood_sample() 00027 { 00028 ASSERT(features); 00029 00030 float64_t sum=0; 00031 for (int32_t i=0; i<features->get_num_vectors(); i++) 00032 sum+=get_log_likelihood_example(i); 00033 00034 return sum/features->get_num_vectors(); 00035 } 00036 00037 void CDistribution::get_log_likelihood(float64_t **dst, int32_t *num) 00038 { 00039 ASSERT(features); 00040 00041 *num=features->get_num_vectors(); 00042 size_t sz=sizeof(float64_t)*(*num); 00043 *dst=(float64_t*) malloc(sz); 00044 ASSERT(dst); 00045 00046 for (int32_t i=0; i<(*num); i++) 00047 *(*dst+i)=get_log_likelihood_example(i); 00048 } 00049 00050 int32_t CDistribution::get_num_relevant_model_parameters() 00051 { 00052 int32_t total_num=get_num_model_parameters(); 00053 int32_t num=0; 00054 00055 for (int32_t i=0; i<total_num; i++) 00056 { 00057 if (get_log_model_parameter(i)>CMath::ALMOST_NEG_INFTY) 00058 num++; 00059 } 00060 return num; 00061 }