SHOGUN  5.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
Distribution.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 1999-2009 Soeren Sonnenburg
8  * Written (W) 2014 Parijat Mazumdar
9  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
10  */
11 
14 
15 using namespace shogun;
16 
18 : CSGObject(), features(NULL), pseudo_count(1e-10)
19 {
20 }
21 
22 
24 {
26 }
27 
29 {
31 
32  float64_t sum=0;
33  for (int32_t i=0; i<features->get_num_vectors(); i++)
35 
36  return sum/features->get_num_vectors();
37 }
38 
40 {
42 
43  int32_t num=features->get_num_vectors();
44  float64_t* vec=SG_MALLOC(float64_t, num);
45 
46  for (int32_t i=0; i<num; i++)
48 
49  return SGVector<float64_t>(vec,num);
50 }
51 
53 {
54  int32_t total_num=get_num_model_parameters();
55  int32_t num=0;
56 
57  for (int32_t i=0; i<total_num; i++)
58  {
60  num++;
61  }
62  return num;
63 }
64 
66 {
68  int32_t num=features->get_num_vectors();
69  ASSERT(num>0);
70 
72  for (int32_t i=0; i<num; i++)
73  result[i]=get_likelihood_example(i);
74 
75  return result;
76 }
77 
79 {
80  SG_WARNING("Not implemented in this class. This class cannot be used for Mixture models.\n")
82  return -1;
83 }
84 
86 {
87  if (!object)
88  return NULL;
89 
90  CDistribution* casted=dynamic_cast<CDistribution*>(object);
91  if (!casted)
92  return NULL;
93 
94  return casted;
95 }
static CDistribution * obtain_from_generic(CSGObject *object)
virtual SGVector< float64_t > get_log_likelihood()
virtual int32_t get_num_vectors() const =0
#define SG_NOTIMPLEMENTED
Definition: SGIO.h:139
virtual int32_t get_num_relevant_model_parameters()
Base class Distribution from which all methods implementing a distribution are derived.
Definition: Distribution.h:44
static const float64_t ALMOST_NEG_INFTY
almost neg (log) infinity
Definition: Math.h:2052
virtual float64_t get_log_model_parameter(int32_t num_param)=0
virtual float64_t get_log_likelihood_sample()
#define ASSERT(x)
Definition: SGIO.h:201
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:115
double float64_t
Definition: common.h:50
virtual float64_t update_params_em(float64_t *alpha_k, int32_t len)
virtual float64_t get_likelihood_example(int32_t num_example)
Definition: Distribution.h:145
virtual SGVector< float64_t > get_likelihood_for_all_examples()
#define SG_UNREF(x)
Definition: SGObject.h:55
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
#define SG_WARNING(...)
Definition: SGIO.h:128
virtual float64_t get_log_likelihood_example(int32_t num_example)=0
virtual int32_t get_num_model_parameters()=0

SHOGUN Machine Learning Toolbox - Documentation