Skip to content

How to write a constraint function for SUMT #69

Open
@soonsk-vcu

Description

@soonsk-vcu

Hello,

I am somewhat new to C++, and wanted to use this library for a constrained minimization problem. I am practicing with sumt using a simple case $f(x) = x^2$ with initial value $2$, and I intend to minimize $f(x)$ with constraint $x \geq 1$ (i.e. the solution should be $x=1$). However, running the code outputs $x=2$ instead.

From reading the function description on the website, I originally assumed that the constraint function needed to return a vector in the form $[g_1(x), g_2(x)... g_n(x)]$ matching constraint $g_i(x) \geq 0$ for each $i \in 1...n$. This assumption seems to be wrong though, given the output. Could someone please clarify the correct implementation for the constraint function? I have included my code below.

Many Thanks,
Sam

double square(const Eigen::VectorXd& vals_inp, Eigen::VectorXd* grad_out, void* opt_data){
  return pow(vals_inp(0),2);
}

Eigen::VectorXd square_cons(const Eigen::VectorXd& vals_inp, Eigen::MatrixXd* jacob_out, void* constr_data){
  Eigen::VectorXd ones = Eigen::VectorXd::Ones(vals_inp.size());
  return vals_inp - ones;
}


Eigen::VectorXd test(){
  Eigen::VectorXd guess = 2.0 * Eigen::VectorXd::Ones(1);
  bool success = optim::sumt(guess, square, nullptr, square_cons, nullptr);
  
  return guess;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions