SHOGUN  4.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ConstMean.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) The Shogun Machine Learning Toolbox
3  * Written (w) 2014 Wu Lin
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * The views and conclusions contained in the software and documentation are those
27  * of the authors and should not be interpreted as representing official policies,
28  * either expressed or implied, of the Shogun Development Team.
29  *
30  * Adapted from the GPML toolbox, specifically meanConst.m
31  * http://www.gaussianprocess.org/gpml/code/matlab/doc/
32  */
33 
35 
36 using namespace shogun;
37 
39 {
40  init();
41 }
42 
44 {
45 }
46 
48  : CMeanFunction()
49 {
50  init();
51  m_mean=mean;
52 }
53 
54 void CConstMean::init()
55 {
56  m_mean=0.0;
57  SG_ADD(&m_mean, "mean", "const value of mean function", MS_AVAILABLE, GRADIENT_AVAILABLE);
58 }
59 
61 {
62  SGVector<float64_t> result(features->get_num_vectors());
63  result.set_const(m_mean);
64  return result;
65 }
66 
68  const TParameter* param, index_t index)
69 {
70  REQUIRE(features,"The features should NOT be NULL\n");
71  REQUIRE(param,"The param should NOT be NULL\n");
72 
73  if (!strcmp(param->m_name, "mean"))
74  {
75  SGVector<float64_t> derivative(features->get_num_vectors());
76  derivative.set_const(1.0);
77  return derivative;
78  }
79  else
80  {
81  SG_ERROR("Can't compute derivative wrt %s parameter\n", param->m_name);
82  return SGVector<float64_t>();
83  }
84 }
int32_t index_t
Definition: common.h:62
parameter struct
virtual int32_t get_num_vectors() const =0
#define SG_ERROR(...)
Definition: SGIO.h:129
#define REQUIRE(x,...)
Definition: SGIO.h:206
An abstract class of the mean function.
Definition: MeanFunction.h:49
double float64_t
Definition: common.h:50
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
virtual ~CConstMean()
Definition: ConstMean.cpp:43
virtual SGVector< float64_t > get_parameter_derivative(const CFeatures *features, const TParameter *param, index_t index=-1)
Definition: ConstMean.cpp:67
virtual SGVector< float64_t > get_mean_vector(const CFeatures *features) const
Definition: ConstMean.cpp:60
The class Features is the base class of all feature objects.
Definition: Features.h:68
#define SG_ADD(...)
Definition: SGObject.h:81
void set_const(T const_elem)
Definition: SGVector.cpp:152

SHOGUN Machine Learning Toolbox - Documentation