6 #ifndef TURI_CONSTRAINTS_H_ 7 #define TURI_CONSTRAINTS_H_ 10 #include <core/data/flexible_type/flexible_type.hpp> 14 #include <Eigen/SparseCore> 17 #include <ml/optimization/utils.hpp> 18 #include <ml/optimization/optimization_interface.hpp> 19 #include <ml/optimization/constraint_interface.hpp> 27 namespace optimization {
53 variables = _variables;
71 inline void project(DenseVector &point)
const {
72 DASSERT_EQ(variables, point.size());
73 point = point.cwiseMax(0);
87 inline void project_block(DenseVector &point,
const size_t block_start,
const 88 size_t block_size)
const {
89 DASSERT_LE(variables, block_start + block_size);
90 DASSERT_EQ(block_size, point.size());
91 point = point.cwiseMax(0);
101 DASSERT_EQ(variables, point.size());
102 for(
size_t i=0; i < size_t(point.size()); i++){
121 const DenseVector& gradient)
const{
123 DenseVector proj_gradient = gradient;
124 for(
size_t i=0; i < size_t(point.size()); i++){
126 proj_gradient(i) = std::min(0.0, gradient(i));
128 proj_gradient(i) = gradient(i);
160 variables = _variables;
161 lb.resize(variables);
163 ub.resize(variables);
175 variables = _lb.size();
176 DASSERT_EQ(variables, _ub.size());
196 inline void project(DenseVector &point)
const {
197 DASSERT_EQ(variables, point.size());
198 for(
size_t i=0; i < size_t(point.size()); i++){
199 point(i) = std::min(std::max(point(i), lb(i)), ub(i));
214 inline void project_block(DenseVector &point,
const size_t block_start,
const 215 size_t block_size)
const {
216 DASSERT_GE(variables, block_start + block_size);
217 DASSERT_EQ(block_size, point.size());
218 for(
size_t i=0; i < block_size; i++){
219 point(i) = std::min(std::max(point(i),
220 lb(block_start + i)), ub(block_start + i));
231 DASSERT_EQ(variables, point.size());
232 for(
size_t i=0; i < size_t(point.size()); i++){
252 const DenseVector& gradient)
const{
254 DenseVector proj_gradient = gradient;
255 for(
size_t i=0; i < size_t(point.size()); i++){
257 proj_gradient(i) = std::min(0.0, gradient(i));
259 proj_gradient(i) = std::max(0.0, gradient(i));
261 proj_gradient(i) = gradient(i);
bool is_satisfied(const DenseVector &point) const
double first_order_optimality_conditions(const DenseVector &point, const DenseVector &gradient) const
const double OPTIMIZATION_ZERO
Optimization method zero.
non_negative_orthant(const size_t &_variables)
bool is_satisfied(const DenseVector &point) const
void project(DenseVector &point) const
double first_order_optimality_conditions(const DenseVector &point, const DenseVector &gradient) const
void project_block(DenseVector &point, const size_t block_start, const size_t block_size) const
double compute_residual(const DenseVector &gradient)
box_constraints(const double &_lb, const double &_ub, const size_t &_variables)
void project_block(DenseVector &point, const size_t block_start, const size_t block_size) const
void project(DenseVector &point) const
box_constraints(const DenseVector &_lb, const DenseVector &_ub)
#define DASSERT_TRUE(cond)