Turi Create  4.0
regularizer_interface.hpp
1 /* Copyright © 2017 Apple Inc. All rights reserved.
2  *
3  * Use of this source code is governed by a BSD-3-clause license that can
4  * be found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
5  */
6 #ifndef TURI_REGULARIZER_INTERFACE_H_
7 #define TURI_REGULARIZER_INTERFACE_H_
8 
9 #include <string>
10 #include <core/data/flexible_type/flexible_type.hpp>
11 
12 // Eigen
13 #include <Eigen/Core>
14 #include <Eigen/SparseCore>
15 
16 // Optimizaiton
17 #include <ml/optimization/optimization_interface.hpp>
18 
19 // TODO: List of todo's for this file
20 //------------------------------------------------------------------------------
21 //
22 
23 namespace turi {
24 
25 namespace optimization {
26 
27 
28 /**
29  * \ingroup group_optimization
30  * \addtogroup regularizers Regularizers
31  * \{
32  */
33 
34 
35 
36 /**
37  *
38  * Interface for regularizers which are separable but not smooth.
39  * \note Smooth refers to functions with continuous derivatives of all orders.
40  *
41 */
43 
44  public:
45 
46  /**
47  * Default desctuctor.
48  */
49  virtual ~regularizer_interface() {};
50 
51 
52  /**
53  * Function to determine if the regularizer is smooth.
54  * \returns false
55  */
56  bool is_smooth() {return false;};
57 
58  /**
59  * Compute the function value of the regularizer at a given point.
60  * \param[in] point Point at which we are computing the gradient.
61  *
62  */
63  virtual double compute_function_value(const DenseVector &point) const = 0;
64 
65 
66  /**
67  * Compute the gradient (or subgradient) at the given point.
68  *
69  * \param[in] point Point at which we are computing the gradient.
70  * \param[out] gradient Dense gradient
71  *
72  */
73  virtual void compute_gradient(const DenseVector &point, DenseVector&
74  gradient) const = 0;
75 
76  /**
77  * Compute the proximal operator for the regularizer at a given point.
78  *
79  * \param[in,out] point Point at which we are computing the gradient.
80  * \param[in] penalty Penalty parameters.
81  *
82  * \note The proximal operator for a convex function f(.) at the point x is
83  * defined as
84  * prox_f(x) = argmin_v ( f(v) + 0.5 * penalty ||x-v||^2)
85  * The idea is an old concept in optimization but it well explained in (1).
86  *
87  * References:
88  *
89  * (1) Parikh, Neal, and Stephen Boyd. "Foundations and Trends in
90  * Optimization." (2014).
91  *
92  */
93  virtual void apply_proximal_operator(DenseVector &point, const double&
94  _penalty=0) const = 0;
95 
96 
97 };
98 
99 
100 /**
101  *
102  * Interface for regularizers that separable and smooth.
103  *
104 */
106 
107  public:
108 
109  /**
110  * Function to determine if the regularizer is smooth.
111  * \returns true
112  */
113  bool is_smooth() {return true;};
114 
115  /**
116  * Default desctuctor.
117  */
119 
120  /**
121  * Compute the hessian of the regularizer at a given point.
122  * \param[in] point Point at which we are computing the gradient.
123  * \param[in,out] hessian Diagonal matrix as the hessian gradient.
124  *
125  */
126  virtual void compute_hessian(const DenseVector &point, DiagonalMatrix
127  &hessian) const = 0;
128 
129 };
130 
131 
132 /// \}
133 
134 } // optimization
135 } // turicreate
136 
137 #endif
virtual void apply_proximal_operator(DenseVector &point, const double &_penalty=0) const =0
virtual double compute_function_value(const DenseVector &point) const =0
virtual void compute_gradient(const DenseVector &point, DenseVector &gradient) const =0