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 <shogun/distributions/Distribution.h> 00012 #include <shogun/mathematics/Math.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 SGVector<float64_t> CDistribution::get_log_likelihood() 00038 { 00039 ASSERT(features); 00040 00041 int32_t num=features->get_num_vectors(); 00042 float64_t* vec=SG_MALLOC(float64_t, num); 00043 00044 for (int32_t i=0; i<num; i++) 00045 vec[i]=get_log_likelihood_example(i); 00046 00047 return SGVector<float64_t>(vec,num); 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 }