# forum.alglib.net

ALGLIB forum
 It is currently Mon Sep 16, 2024 8:20 pm

 All times are UTC

### Forum rules

1. This forum can be used for discussion of both ALGLIB-related and general numerical analysis questions
2. This forum is English-only - postings in other languages will be removed.

 Page 1 of 1 [ 5 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: How can I limit step length of each variable?Posted: Sun Feb 20, 2011 8:12 am

Joined: Mon Feb 14, 2011 8:09 am
Posts: 5
Hi, I'm using minasa subpackage to optimize a real 1d array x.
Now I want to limit step length of each element of x.
Of course, I can define the maximum step length StpMax.
However, this parameter seems only limit the step sum of the whole array but not a single variable.(Yes?)
So how can I limit step length of each element of x?

Top

 Post subject: Re: How can I limit step length of each variable?Posted: Mon Feb 21, 2011 10:13 am

Joined: Fri May 07, 2010 7:06 am
Posts: 922
Current version of ALGLIB doesn't support different step limits for different coordinates. But why do you need such functionality? Are your variables have different scales?

Top

 Post subject: Re: How can I limit step length of each variable?Posted: Tue Feb 22, 2011 3:40 am

Joined: Mon Feb 14, 2011 8:09 am
Posts: 5
Sergey.Bochkanov wrote:
Current version of ALGLIB doesn't support different step limits for different coordinates. But why do you need such functionality? Are your variables have different scales?

All variables have the same scale.
Suppose the vector to be optimized is v0 = [a0; b0; c0; d0].
After one iteration, v becomes v1 = [a1; b1; c1; d1].
Current version of ALGLIB can limit the step of v : ||v1 - v0|| < step,
but what I need is to limit the steps of each variable : ||a1 - a0|| < step, ||b1 - b0|| < step, ||c1 - c0|| < step, ||d1 - d0|| < step,
though all these step limits are the same.

Top

 Post subject: Re: How can I limit step length of each variable?Posted: Tue Feb 22, 2011 8:10 am

Joined: Fri May 07, 2010 7:06 am
Posts: 922
It is possible to place such limit on step length, but it will require modification of the ALGLIB internals. Fortunately, you can do it yourself with only a little guidance from my side.

There are two places in the minasa subpackage where step can be limited: a) internal iterations of the gradient projection algorithm, and b) internal internal iterations of the nonlinear CG. You have to apply modifications to both places.

1. you should find "Two types of search are needed because we can't" in the source of the optimization package. You can find if/then block several lines below with ASAD1Norm(State)<=State.StpMax condition. You have to replace it by max(i=0..n-1 : abs(state.d[i]))<=State.StpMax. These lines correspond to unit step in the direction given by State.D.

2. after "alpha=1 is too large, try smaller values" you can find if/then block if State.StpMax>0 then State.Stp:=Min(State.Stp,State.StpMax). You should replace this if/then block by loop which calculates upper limit on State.Stp. You should make sure that Abs(State.D[])*State.Stp<=step_limit for all i=0..n-1. Be careful because State.D[] can be zero for some i (exactly zero, if we are at the boundary given by BndL or BndU).

3. finally, you should find two calls to MCSRCH() function below the "Make a CG step in direction given by DK[]" line. These calls use State.StpMax as upper limit on the step length. You should calculate your own step limit using same condition Abs(State.D[])*State.CurrentStepLimit<=step_limit. I recommend you to calculate it once before the first call to the MCSRCH(), and to store it as the member of the State object. Never use locals to store information because minasaiteration() function periodically returns to the calling subroutine and all information stored by you in the local variables will be lost.

Top

 Post subject: Re: How can I limit step length of each variable?Posted: Wed Feb 23, 2011 4:01 am

Joined: Mon Feb 14, 2011 8:09 am
Posts: 5
Sergey.Bochkanov wrote:
It is possible to place such limit on step length, but it will require modification of the ALGLIB internals. Fortunately, you can do it yourself with only a little guidance from my side.

There are two places in the minasa subpackage where step can be limited: a) internal iterations of the gradient projection algorithm, and b) internal internal iterations of the nonlinear CG. You have to apply modifications to both places.

1. you should find "Two types of search are needed because we can't" in the source of the optimization package. You can find if/then block several lines below with ASAD1Norm(State)<=State.StpMax condition. You have to replace it by max(i=0..n-1 : abs(state.d[i]))<=State.StpMax. These lines correspond to unit step in the direction given by State.D.

2. after "alpha=1 is too large, try smaller values" you can find if/then block if State.StpMax>0 then State.Stp:=Min(State.Stp,State.StpMax). You should replace this if/then block by loop which calculates upper limit on State.Stp. You should make sure that Abs(State.D[])*State.Stp<=step_limit for all i=0..n-1. Be careful because State.D[] can be zero for some i (exactly zero, if we are at the boundary given by BndL or BndU).

3. finally, you should find two calls to MCSRCH() function below the "Make a CG step in direction given by DK[]" line. These calls use State.StpMax as upper limit on the step length. You should calculate your own step limit using same condition Abs(State.D[])*State.CurrentStepLimit<=step_limit. I recommend you to calculate it once before the first call to the MCSRCH(), and to store it as the member of the State object. Never use locals to store information because minasaiteration() function periodically returns to the calling subroutine and all information stored by you in the local variables will be lost.

It's so kind of you to help me like this.

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 5 posts ]

 All times are UTC

#### Who is online

Users browsing this forum: No registered users and 2 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for: