SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
LikelihoodModel.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) The Shogun Machine Learning Toolbox
3  * Written (W) 2013 Heiko Strathmann
4  * Written (W) 2013 Roman Votyakov
5  * Written (W) 2012 Jacob Walker
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice, this
12  * list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * The views and conclusions contained in the software and documentation are those
29  * of the authors and should not be interpreted as representing official policies,
30  * either expressed or implied, of the Shogun Development Team.
31  *
32  */
34 
35 using namespace shogun;
36 
38 {
39 }
40 
42 {
43 }
44 
47 {
48  return get_log_zeroth_moments(mu, s2, lab);
49 }
50 
52  const CLabels* lab, SGMatrix<float64_t> F) const
53 {
54  REQUIRE(lab, "Given labels are NULL!\n");
55  REQUIRE(lab->get_num_labels()==F.num_rows, "Number of labels (%d) does "
56  "not match dimension of functions (%d)\n",
57  lab->get_num_labels(),F.num_rows);
58  REQUIRE(F.num_cols>0, "Number of passed functions (%d) must be positive\n",
59  F.num_cols);
60 
61  SGVector<float64_t> result(F.num_cols);
62  for (index_t i=0; i<F.num_cols; ++i)
63  {
64  /* extract current sample from matrix, assume col-major, dont copy */
65  SGVector<float64_t> f(&F.matrix[i*F.num_rows], F.num_rows, false);
67  }
68 
69  return result;
70 }
71 
73  SGVector<float64_t> s2, const CLabels* lab) const
74 {
75  REQUIRE(lab, "Labels are required (lab should not be NULL)\n")
76  REQUIRE((mu.vlen==s2.vlen) && (mu.vlen==lab->get_num_labels()),
77  "Length of the vector of means (%d), length of the vector of "
78  "variances (%d) and number of labels (%d) should be the same\n",
79  mu.vlen, s2.vlen, lab->get_num_labels())
80 
81  SGVector<float64_t> result(mu.vlen);
82 
83  for (index_t i=0; i<mu.vlen; i++)
84  result[i]=get_first_moment(mu, s2, lab, i);
85 
86  return result;
87 }
88 
90  SGVector<float64_t> s2, const CLabels* lab) const
91 {
92  REQUIRE(lab, "Labels are required (lab should not be NULL)\n")
93  REQUIRE((mu.vlen==s2.vlen) && (mu.vlen==lab->get_num_labels()),
94  "Length of the vector of means (%d), length of the vector of "
95  "variances (%d) and number of labels (%d) should be the same\n",
96  mu.vlen, s2.vlen, lab->get_num_labels())
97 
98  SGVector<float64_t> result(mu.vlen);
99 
100  for (index_t i=0; i<mu.vlen; i++)
101  result[i]=get_second_moment(mu, s2, lab, i);
102 
103  return result;
104 }
virtual SGVector< float64_t > get_first_moments(SGVector< float64_t > mu, SGVector< float64_t > s2, const CLabels *lab) const
virtual SGVector< float64_t > get_log_probability_f(const CLabels *lab, SGVector< float64_t > func) const =0
int32_t index_t
Definition: common.h:62
The class Labels models labels, i.e. class assignments of objects.
Definition: Labels.h:43
virtual int32_t get_num_labels() const =0
virtual SGVector< float64_t > get_log_zeroth_moments(SGVector< float64_t > mu, SGVector< float64_t > s2, const CLabels *lab) const =0
#define REQUIRE(x,...)
Definition: SGIO.h:206
index_t num_cols
Definition: SGMatrix.h:376
virtual SGVector< float64_t > get_second_moments(SGVector< float64_t > mu, SGVector< float64_t > s2, const CLabels *lab) const
virtual float64_t get_second_moment(SGVector< float64_t > mu, SGVector< float64_t > s2, const CLabels *lab, index_t i) const =0
index_t num_rows
Definition: SGMatrix.h:374
index_t vlen
Definition: SGVector.h:494
virtual SGVector< float64_t > get_log_probability_fmatrix(const CLabels *lab, SGMatrix< float64_t > F) const
virtual SGVector< float64_t > get_predictive_log_probabilities(SGVector< float64_t > mu, SGVector< float64_t > s2, const CLabels *lab=NULL)
static T sum(T *vec, int32_t len)
Return sum(vec)
Definition: SGVector.h:354
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
virtual float64_t get_first_moment(SGVector< float64_t > mu, SGVector< float64_t > s2, const CLabels *lab, index_t i) const =0

SHOGUN Machine Learning Toolbox - Documentation