Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Optimization-problem with objective function scaling

Subject: Optimization-problem with objective function scaling

From: sparky

Date: 17 Aug, 2012 00:33:16

Message: 1 of 3

Hi,
I am trying to use GA, fmincon for optimization.
My program calls a function "opt.m" (user defined) using ga or fmincon command.
Within the file opt.m an objective function "J" is calculated. The goal of ga or fmincon is to minimize the value of "J".
The problem I am facing is that the stopping criteria for ga or fmincon is based on termination tolerances like Tolfun,TolX etc.
So whenever I change the scale of the parameters in my program, the value of "J" computed scales up or down, and so i need to change the termination tolerances accordingly to make the ga or fmincon run effectively.
To avoid the need to change Tolfun, TolX everytime, I wanted to normalize the value of "J" within the function "opt.m".
i.e. if J(1) is the value of J calculated in the first iteration, then I want to change my objective function to "R" where R(i)= J(i)/ J(1) for the "i"th iteration.
This way I can avoid any error due to scaling, since now my objective function "R" will always vary between 1 and 0.
But I am not able to figure out how to do this in Matlab. How can I store the value of J for the first iteration and then use it for the subsequent iterations.
I am not able to track the iteration number within the "opt.m" file when using the ga or fmincon commands.

I hope I was able to convey my problem. My program files need several inputs from other files so I cannot post it here.


 

Subject: Optimization-problem with objective function scaling

From: R

Date: 17 Aug, 2012 05:46:15

Message: 2 of 3

"sparky" wrote in message <k0k3gc$qcp$1@newscl01ah.mathworks.com>...
> Hi,
> I am trying to use GA, fmincon for optimization.
[snip]
> i.e. if J(1) is the value of J calculated in the first iteration, then I want to change my objective function to "R" where R(i)= J(i)/ J(1) for the "i"th iteration.
[snip]

The algorithm you suggest should work. Obviously, when you call fmincon, you have an initial seed value. Call this initial seed value b0.

Now, before you run fmincon, call your optimization function 'opt' at this initial value and save the result. Next, define an anonymous function that calls 'opt' as usual but then scales any outputs by that initial value. Finally, call fmincon using your scaled function. Haven't tried it, but I think this should even work if your function 'opt' generates a gradient.

b0 = 0; % Initial seed value
J1 = opt(parameters, b0); % Initial value
R = @(b)opt(parameters,b) / J1; % New, scaled objective function
fmincon( R , ..., 'tolx',1e-3,...)

Subject: Optimization-problem with objective function scaling

From: sparky

Date: 18 Aug, 2012 14:37:06

Message: 3 of 3

Hi "R",
Thanks for your response. yes, what you suggested works for fmincon.
The problem I face is when i am using GA, since unlike fmincon GA generates its own initial population for the first iteration, the initial value chosen is like a random value and varies each time you run the program.
so if the value of objective function after 1st iteration is "J_first".
When I call GA for subsequent iterations, it begins with a new set of initial population which is different from the 1st case. so the new value of objective function "J_first_new"
is not equal to the earlier case.
So the value R= J_first_new / J_first , is never equal to 1.

anyway, The value of J_first and J_first_new are comparatively closer. So I can still normalize it to have reasonable values and avoid changing the parameters TolX, Tolfun every time.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us