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 "features/Features.h" 00015 #include "lib/Mathematics.h" 00016 #include "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 00112 virtual void get_log_likelihood(float64_t** dst, int32_t *num); 00113 00119 virtual inline float64_t get_model_parameter(int32_t num_param) 00120 { 00121 return exp(get_log_model_parameter(num_param)); 00122 } 00123 00130 virtual inline float64_t get_derivative( 00131 int32_t num_param, int32_t num_example) 00132 { 00133 return exp(get_log_derivative(num_param, num_example)); 00134 } 00135 00141 virtual inline float64_t get_likelihood_example(int32_t num_example) 00142 { 00143 return exp(get_log_likelihood_example(num_example)); 00144 } 00145 00150 virtual inline void set_features(CFeatures* f) 00151 { 00152 SG_UNREF(features); 00153 SG_REF(f); 00154 features=f; 00155 } 00156 00161 virtual inline CFeatures* get_features() 00162 { 00163 SG_REF(features); 00164 return features; 00165 } 00166 00171 virtual inline void set_pseudo_count(float64_t pseudo) { pseudo_count=pseudo; } 00172 00177 virtual inline float64_t get_pseudo_count() { return pseudo_count; } 00178 00179 protected: 00181 CFeatures* features; 00183 float64_t pseudo_count; 00184 }; 00185 } 00186 #endif