SHOGUN  4.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SMDMinimizer.cpp
Go to the documentation of this file.
1  /* * Copyright (c) The Shogun Machine Learning Toolbox
2  * Written (w) 2015 Wu Lin
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this
9  * list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  * The views and conclusions contained in the software and documentation are those
26  * of the authors and should not be interpreted as representing official policies,
27  * either expressed or implied, of the Shogun Development Team.
28  *
29  */
31 #include <shogun/base/Parameter.h>
32 using namespace shogun;
33 
36 {
37  init();
38 }
39 
41 {
43 }
44 
47 {
48  init();
49 }
50 
52 {
53  REQUIRE(m_mapping_fun, "Mapping function must set\n");
56  SGVector<float64_t> dual_variable=m_mapping_fun->get_dual_variable(variable_reference);
58  REQUIRE(fun,"the cost function must be a stochastic cost function\n");
60  {
61  fun->begin_sample();
62  while(fun->next_sample())
63  {
65  float64_t learning_rate=1.0;
66  if(m_learning_rate)
68 
70  update_gradient(grad,variable_reference);
71  m_gradient_updater->update_variable(dual_variable,grad,learning_rate);
72  m_mapping_fun->update_variable(variable_reference,dual_variable);
73  }
74  }
75  float64_t cost=m_fun->get_cost();
76  return cost+get_penalty(variable_reference);
77 }
78 
79 void SMDMinimizer::init()
80 {
81  m_mapping_fun=NULL;
82  SG_ADD((CSGObject **)&m_mapping_fun, "SMDMinimizer__m_mapping_fun",
83  "m_mapping_fun in SMDMinimizer", MS_NOT_AVAILABLE);
84 }
85 
87 {
88  REQUIRE(mapping_fun, "mapping/projection function must be set\n");
89  if(m_mapping_fun!=mapping_fun)
90  {
91  SG_REF(mapping_fun);
93  m_mapping_fun=mapping_fun;
94  }
95 }
96 
98 {
100 }
virtual SGVector< float64_t > get_gradient()=0
The base mapping function for mirror descend.
virtual void update_variable(SGVector< float64_t > variable, SGVector< float64_t > dual_variable)=0
FirstOrderCostFunction * m_fun
#define REQUIRE(x,...)
Definition: SGIO.h:206
virtual void init_minimization()
virtual void update_variable(SGVector< float64_t > variable_reference, SGVector< float64_t > negative_descend_direction, float64_t learning_rate)=0
virtual float64_t minimize()
The first order stochastic cost function base class.
#define SG_REF(x)
Definition: SGObject.h:54
The base class for stochastic first-order gradient-based minimizers.
virtual void update_gradient(SGVector< float64_t > gradient, SGVector< float64_t > var)
MappingFunction * m_mapping_fun
Definition: SMDMinimizer.h:79
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:115
virtual SGVector< float64_t > get_dual_variable(SGVector< float64_t > variable)=0
double float64_t
Definition: common.h:50
virtual float64_t get_penalty(SGVector< float64_t > var)
virtual float64_t get_cost()=0
virtual void set_mapping_function(MappingFunction *mapping_fun)
#define SG_UNREF(x)
Definition: SGObject.h:55
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
virtual float64_t get_learning_rate(int32_t iter_counter)=0
#define SG_ADD(...)
Definition: SGObject.h:84
virtual SGVector< float64_t > obtain_variable_reference()=0

SHOGUN Machine Learning Toolbox - Documentation