Turi Create  4.0
constraint_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_CONSTRAINT_INTERFACE_H_
7 #define TURI_CONSTRAINT_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 optimization_constraints Optimization Constraints
31  * \{
32  */
33 
34 
35 
36 /**
37  *
38  * Interface for constraints for Gradient Projection solvers. See chapter 12
39  * of (1) for an intro to constrained optimization.
40  *
41  * Some implementations are based on Section 16.7 of (1).
42  *
43  *
44  * Background: Gradient Projection Methods
45  * --------------------------------------------------------------------------
46  *
47  * Gradient project methods are methods for solving bound constrained
48  * optimization problems.
49  *
50  * Traditionally, in unconstrained optimization, we solve the problem
51  * \min_x f(x) using a gradient descent method as follows:
52  *
53  * x_{k+1} = x_{k} - \alpha_k \grad f(x_k) (G)
54  *
55  * where \alpha_k is a step size.
56  *
57  * The gradient-projection framework performs solves the problem:
58  * \min_{x \in C} f(x) using a slight modification to the gradient step in (G)
59  *
60  * x_{k+1} = P_C(x_{k} - \alpha_k \grad f(x_k)) (PG)
61  *
62  * where P_C is the projection of a point on to the convex set.
63  *
64  * P_C(z) = \min_{x \in z} ||x-z||^2
65  *
66  * which works out to be the closest point to the set in C.
67  *
68  * Comparison of gradient projection with other methods
69  * -----------------------------------------------------------
70  *
71  * In solving bound constrained optimization problems, active set methods face
72  * criticism because the working set changes slowly; at each iteration, at most
73  * one constraint is added to or dropped from the working set. If there are k0
74  * constraints active at the initial W0, but kθ constraints active at the
75  * solution, then at least |kθ−k0| iterations are required for convergence.
76  * This property can be a serious disadvantage in large problems if the working
77  * set at the starting point is vastly different from the active set at the
78  * solution.
79  *
80  *
81  * The gradient-projection method is guaranteed to identify the active set at
82  * a solution in a finite number of iterations. After it has identified the
83  * correct active set, the gradient-projection algorithm reduces to the
84  * steepest-descent algorithm on the subspace of free variables.
85  *
86  * References:
87  *
88  * (1) Wright S.J and J. Nocedal. Numerical optimization. Vol. 2.
89  * New York: Springer, 1999. (Chapter 12)
90  *
91  *
92 */
94 
95  public:
96 
97  /**
98  * Default desctuctor.
99  */
100  virtual ~constraint_interface() {};
101 
102 
103  /**
104  * Project a dense point into the constraint space.
105  * \param[in,out] point Point which we are using to project the point.
106  *
107  * Given a convex set X, the projection operator is given by
108  *
109  * P(y) = \min_{x \in X} || x - y ||^2
110  *
111  */
112  virtual void project(DenseVector &point) const = 0;
113 
114  /**
115  * Project a dense a block of co-ordinates point into the constraint space.
116  *
117  * \param[in,out] point A block project the point.
118  * \param[in] block_start Start index of the block
119  * \param[in] block_size Size of the block
120  *
121  * Given a convex set X, the projection operator is given by
122  *
123  * P(y) = \min_{x \in X} || x - y ||^2
124  *
125  */
126  virtual void project_block(DenseVector &point, const size_t block_start,
127  const size_t block_size) const = 0;
128 
129  /**
130  * Boolean function to determine if a dense point is present in a constraint
131  * space.
132  * \param[in] point Point which we are querying.
133  *
134  */
135  virtual bool is_satisfied(const DenseVector &point) const = 0;
136 
137  /**
138  * A measure of the first order optimality conditions.
139  *
140  * \param[in] point Point which we are querying.
141  * \param[in] gradient Gradient at that point for a given function
142  *
143  * If you don't know what to do, then use
144  * ||P_C(x - grad) - x||
145  * where x is the point, grad is the gradient and P_C is the projection to
146  * the set in consideration.
147  *
148  */
149  virtual double first_order_optimality_conditions(const DenseVector &point,
150  const DenseVector& gradient) const = 0;
151 
152 
153 };
154 
155 /// \}
156 } // Optimization
157 } // Turi
158 
159 #endif
virtual bool is_satisfied(const DenseVector &point) const =0
virtual double first_order_optimality_conditions(const DenseVector &point, const DenseVector &gradient) const =0
virtual void project_block(DenseVector &point, const size_t block_start, const size_t block_size) const =0
virtual void project(DenseVector &point) const =0