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 #ifndef _DISTRIBUTION_H___ 00012 #define _DISTRIBUTION_H___ 00013 00014 #include <shogun/features/Features.h> 00015 #include <shogun/mathematics/Math.h> 00016 #include <shogun/base/SGObject.h> 00017 00018 namespace shogun 00019 { 00020 class CFeatures; 00021 class CMath; 00041 class CDistribution : public CSGObject 00042 { 00043 public: 00045 CDistribution(); 00046 virtual ~CDistribution(); 00047 00056 virtual bool train(CFeatures* data=NULL)=0; 00057 00064 virtual int32_t get_num_model_parameters()=0; 00065 00071 virtual int32_t get_num_relevant_model_parameters(); 00072 00079 virtual float64_t get_log_model_parameter(int32_t num_param)=0; 00080 00089 virtual float64_t get_log_derivative( 00090 int32_t num_param, int32_t num_example)=0; 00091 00099 virtual float64_t get_log_likelihood_example(int32_t num_example)=0; 00100 00105 virtual float64_t get_log_likelihood_sample(); 00106 00111 virtual SGVector<float64_t> get_log_likelihood(); 00112 00118 virtual inline float64_t get_model_parameter(int32_t num_param) 00119 { 00120 return exp(get_log_model_parameter(num_param)); 00121 } 00122 00129 virtual inline float64_t get_derivative( 00130 int32_t num_param, int32_t num_example) 00131 { 00132 return exp(get_log_derivative(num_param, num_example)); 00133 } 00134 00140 virtual inline float64_t get_likelihood_example(int32_t num_example) 00141 { 00142 return exp(get_log_likelihood_example(num_example)); 00143 } 00144 00149 virtual inline void set_features(CFeatures* f) 00150 { 00151 SG_UNREF(features); 00152 SG_REF(f); 00153 features=f; 00154 } 00155 00160 virtual inline CFeatures* get_features() 00161 { 00162 SG_REF(features); 00163 return features; 00164 } 00165 00170 virtual inline void set_pseudo_count(float64_t pseudo) { pseudo_count=pseudo; } 00171 00176 virtual inline float64_t get_pseudo_count() { return pseudo_count; } 00177 00178 protected: 00180 CFeatures* features; 00182 float64_t pseudo_count; 00183 }; 00184 } 00185 #endif