Login
Login

Constrained Optimization

Home 21090308 Forums Numerical Method Optimization Constrained Optimization

  • This topic is empty.
Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #2817
    ogreyesp
    Member

    Hello,

    Anyone can help me to understand how work the constraints in SuanShu library. I don’t understand how this example represents this constraint x>=1

    * A less than constraint for constrained optimization.
    105 */
    106 public static final LessThanConstraints C2 = new GeneralLessThanConstraints(
    107 new AbstractBivariateRealFunction() {
    108 @Override
    109 public double evaluate(double x, double y) {
    110 return 1 – x; // x >= 1
    111 }
    112 });

    If a have the following constraint:

    q1+q2+….+qn<=1 How I can implement this in the SuanShu library? Best regards, Oscar

    #2818
    hao.ding
    Member

    Hi,

    q1+q2+…+qn<=1 is a linear constraints, you can construct such a linear constraint in SuanShu use the following codes: Matrix A = new DenseMatrix(1, n); for (int i = 1; i <= n; i++) { A.set(1, i, 1.); } //A = [1,1,...,1] Vector b = new DenseVector(1.); // b = [1] LinearLessThanConstraints less = new LinearLessThanConstraints(A, b);

    #2819
    hao.ding
    Member

    In the example you mentioned, it represents the constraint x>=1 because it evaluates 1-x, and when the evaluation is smaller than 0, the constraint is satisfied.

    Therefore when you want to construct a constraint Ax>=b, in the evaluation part you should return b-AX.

    #2821
    ogreyesp
    Member

    Thanks you very much for your quickly response.

    Best regards,

    Oscar

    #2824
    ogreyesp
    Member

    Hello,

    I’ have defined an objetive function (it has some complexity) and 4 linear constraints (they are very simple). So, I have put the following code, as same as the example that comes with the SuanShu library:

    ///
    double gamma = 1e30;
    double epsilon = 1e-8;
    int maxIterations = 200;

    PenaltyMethodMinimizer optim = new PenaltyMethodMinimizer(
    PenaltyMethodMinimizer.DEFAULT_PENALTY_FUNCTION_FACTORY,
    gamma,
    new BFGSMinimizer(false, epsilon, maxIterations));

    IterativeMinimizer minimizer = optim.solve(problem);

    Vector xmin = minimizer.search(new DenseVector(q));

    //////////

    The problem that i have is the following: The BFGSMinimizer never outs from the 1 iteration, i.e it still executing in the 1st iteration of the BFGS algorithm and does’nt stop. I printed the value of the defined objetive function each time that it is evaluated for BFGS and for example this is the continiusly stream that appears in the screen:

    16079.194741736539
    16079.194729964249
    16079.194738279763
    16079.194733421027
    16079.194726798403
    16079.194744902386
    16079.194737157148
    16079.19473454364
    ….
    …..
    ….
    …. an go on.

    Anyone have an idea of why the BFGS algorithm does not stop.

    Best regards,

    Oscar

    #2825
    hao.ding
    Member

    Hi,

    It is hard to know the problem if the objective function, constraints and data are unknown. It would be helpful if you can provide them. From the information you provided currently, my guesses are:

    BFGS method is not good when the starting points are far from optimal point. Because it moves very slow. You can try other optimization method first, and use the results as starting points for BFGS to refine the results.

    Another possibility is that the starting point is a local minimum but not a global minimum. So BFGS cannot move away from the starting points. You may try other starting points.

    #2877
    webmaster
    Member

    Our site should allow uploading file types with extensions such as *.java, *.zip, *.docx, *.xlsx. Please try again.

    #2879
    ogreyesp
    Member

    Trying…..

    #2883
    ogreyesp
    Member

    The codes were uploaded

    #2896
    hao.ding
    Member

    Hi,

    I took a look at your constraint program, and found that your first, second and fourth constraints are same.
    First constraint: sum(q)<=batch Second constraint: sum(q)<= d.size/2 (although you loop i from 1 to split point, but sum is sum(d)) Fourth constraint: sum(q)<=d.size Would you please let me know if I understand your constraints correctly? Also may I have your data and the program where you call QuasiNewtonOptimizer so I can debug your problem? Thanks.

    #2901
    ogreyesp
    Member

    Hi Hao Ding.

    Thanks you soo much for your help. I have restricted the problem only to the first and third constraint and the issue was resolved. You are right, the first, second and fourth constraint express the same.

    Although, the BFGS method still runs ver slow, maybe due to the complexity of the objetive function. I will follow your past recomendation “try other optimization method first, and use the results as starting points for BFGS to refine the results.”

    Again, thanks very much for your help.

    Best regards,

    Oscar

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.