Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Getting parameters from looping maximize()

    Hello,

    I need to optimize a function that seems to have flat areas, so when i run maximize(), after some iterations the algorithm gives the same value of the function but does not stop.

    Seems like it encounters a flat area. What I want is the algorithm to stop once the value of the function does not change much from iteration to iteration, and give me a value of the parameters (that i use to maximize the function) that corresponds to this maximum.

    I can not figure out how to:

    1. compare values of the function from different iterations
    2. save the value of the parameter (so i can call it outside myeval).

    y is a function of input data and 4 parameters (param[1]:param[4])

    What i need logically should do things like this, but it doesn't work obviously

    mata

    void myeval(todo, param, y, g, H) {


    y=function(param[1],param[2],param[3],param[4])

    if (abs(y_i-y_i-1))<eps {
    p=param
    break
    }


    }
    S = optimize_init()
    optimize_init_evaluator(S, &myeval())
    optimize_init_params(S, (530,540,535,544))
    r = optimize(S)
    r


    If something is not clear, please let me know.

    Thank you in advance for your help,
    Olga Meshcheriakova

  • #2
    Hi Olga,

    I can't speak to a solution to point 2, but for point 1 I think what you want to do is make use of optimize_init_conv_vtol(). This will allow you to compare the values of y at successive iterations. Its second argument is essentially what you've called eps above. How that helps!

    Michael

    Comment

    Working...
    X