Page 1 of 1

Optimize for particular value at a specific time

Posted: Sun Feb 28, 2010 6:36 pm
by karankhosla
Greetings!

Please see the sample model I made; how can I optimize parameters to fulfill a value constraint and also a time constraint? I would like the population to be near 300 by time 20 (months).

Thanks!

Karan

Posted: Sun Feb 28, 2010 8:47 pm
by karankhosla
I presume one way would be too end the simulation at the time of interest and values would be optimized accordingly.

optimize

Posted: Sun Feb 28, 2010 10:02 pm
by LAUJJL
Hi Karan

You are right. You must put the final time equal 20 and optimize the population. But to optimize you must minimize the square of the difference between the desired population and the population at the final time. You do not have to integrate the square values. You must calculate a payoff that is equal to zero during the simulation and equal to the square at the end of the simulation and put that payoff in the vpd file with a weight of -1. Look for 'payoff computation' in the Vensim help. The calculation of the payoff is explained.
Regards.
JJ

Posted: Mon Mar 01, 2010 7:44 am
by karankhosla
Thanks JJ!

optimize

Posted: Mon Mar 01, 2010 8:42 am
by LAUJJL
Hi Karan

Obviously the interval of possible nutrition is not wide enough.
Joined a model where you can have a final time later than 20 and does the job. I was obliged to modify the lookup to make it compatible to the extension of the interval of possible nutrition. Of course this is pure math and may not correspond to anything reality.
Regards.
JJ

Posted: Mon Mar 01, 2010 10:17 am
by karankhosla
Thanks a lot JJ, yes it was just a trial to see if I could get fulfill a time constraint as well. I was just reviewing Geoff Coyle's book (the section on optimizing) he defines the objective function as a level of a penalty, e.g. pen.k = pen.j +dt*(Desired Population - Population)^2: pen0 = 0. Then minimize the penalty. Would this not work?

Optîmize

Posted: Mon Mar 01, 2010 10:31 am
by LAUJJL
Hi Karan

I do not see any contradiction with Coyle's objective function.
Your objective is that at time 20 the population is equal to 300. One has then to define a payoff that is equal to 0 everywhere but when time = 20, because Vensim integrates automatically the defined payoff in the vpd file. See the 'payoff computation' explanation in the Vensim help.
I have not Coyle's book with me at the time. See my u to U message.
Regards.
JJ

Posted: Mon Mar 01, 2010 11:07 am
by karankhosla
Aha! JJ - Thank you!

population

Posted: Mon Mar 01, 2010 2:31 pm
by LAUJJL
Hi Karan

I think that the specifications of your problem you start from are ideal. It is extremely simple which is very good and you can still spend quite a lot of time, analyzing it and trying to test already at this level, the level of implementability which is fundamental if you want to build a useful model later on. You can run sensibility analysis with the parameters, desired population, desired time, nutrition, lookup effect that should be replaced by an algebraic formula to make sensibility analysis easier. Try all sorts of optimization. Build as many as possible reality checks (takes a lot of time to be expert with it and preferable to test with very simple models) etc...
Contrary to what is commonly taught I have experienced that it is not necessary to include in a model, all the significant factors, nor extended boundaries to be useful. Simplicity and undestandability is much more important than closeness to the reality even if the potential policies found at this stage are not concretely implementable. But it should at least help to get a better overall view of the problem that will help greatly when adding progressively later on more material to the model.
Regards.
JJ

Posted: Tue Mar 02, 2010 10:51 pm
by tomfid
pen.k = pen.j +dt*(Desired Population - Population)^2: pen0 = 0.
You don't need to perform the integration step in Coyle's formula, because Vensim integrates payoffs for you. The equivalent would be:

*C
population|desired population/weight

If you make your weight something like PULSE( target_time, target_width) with target_time = 20, you can evaluate the fit near your desired time. Then you don't have to stop the model at that point.

Posted: Wed Mar 03, 2010 7:42 am
by karankhosla
Thanks Tom! I'm going to try it out. I presume the logic behind it is that, as the weight is multiplied to the payoff at each time step, the pulse function forces the value of the payoff to be "x" at a particular time and zero elsewhere, which forces the optimizer to (if so desired) to minimize the only non-zero in its calculation.

[Edited on 3-3-2010 by karankhosla]

optimize

Posted: Wed Mar 03, 2010 9:31 am
by LAUJJL
One can do the same with an interval of fitness with a small change on the previous model sent.
With an interval of two months lasting 5 months, one gets a value of nutrition of 13.51 with the interval and 13.58 with no interval.
Regards.
JJ

Posted: Wed Mar 03, 2010 10:27 am
by karankhosla
JJ That works very well too. Thank you.

optimize

Posted: Wed Mar 03, 2010 10:37 am
by LAUJJL
You can too try to keep the maximum difference within the fitness interval minimal.
It gives the following model that proves that there are many ways to skin a cat giving the same result than the optimize_2 model.
Regards.
JJ

Posted: Wed Mar 10, 2010 12:14 am
by tomfid
Originally posted by karankhosla
Thanks Tom! I'm going to try it out. I presume the logic behind it is that, as the weight is multiplied to the payoff at each time step, the pulse function forces the value of the payoff to be "x" at a particular time and zero elsewhere, which forces the optimizer to (if so desired) to minimize the only non-zero in its calculation.
That's right. It's also possible to use IF THEN ELSE and SAMPLE IF TRUE for similar purposes.

One caveat: using IF THEN ELSE to test for Time = desired time can fail unexpectedly, because of round off error in the accumulation of time steps. That's why I used PULSE (which has logic to test for whether the next time interval includes the desired time) rather than IF THEN.

Posted: Wed Mar 10, 2010 5:31 pm
by karankhosla
Thanks Tom.