Improving iterations!

Use this forum to post Vensim related questions.
Post Reply
luisangelguzmang
Member
Posts: 42
Joined: Wed Apr 06, 2011 8:20 am

Improving iterations!

Post by luisangelguzmang »

Hi, can you help me to do this in a better, simple and/or elegante way?
I start whit the "matrix 0" and the vectors "generation" and attraction", these are constants and the result is the "matrox 6".
It is possible to do this in one step and do more iterations?
Thanks a lot!
Attachments
data_M.xlsx
Data files
(7.48 KiB) Downloaded 234 times
fratar.mdl
Vensim file
(3.98 KiB) Downloaded 213 times
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Re: Improving iterations!

Post by Administrator »

It's not clear to me what you are trying to do.

Does the FIND ZERO function help you at all? That can be used to iterate.
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
luisangelguzmang
Member
Posts: 42
Joined: Wed Apr 06, 2011 8:20 am

Re: Improving iterations!

Post by luisangelguzmang »

I tried with FIND ZERO function,but I can't (I did not know) do anything, because I got 2 subindex. I apologize if i was not clear.
I need to estimate a future matrix (in this case "matrix 6") which is derived from base year matrix ("matrix 0") and the vectors "generation" and "attraction". There are four basic steps to the calculation:
1. The vector "generation" is divide by the sum the row data for each zone in "matrix 0" to obtain a growth factor by rows.
2. Multiply the lines in the "matrix 0" by the appropriate factor found in the previous step ("matrix 1").
3. Now, the vector "attraction" is divide by the sum the column data for each zone in "matrix 1" to obtain a growth factor by columns. The result is "matrix 2".
4. Repeat the iteration process until the row or column factor being calculated is sufficiently close to 1.

The equation is:
eq
eq
img.jpg (9.72 KiB) Viewed 5657 times
where tij is the "maxtrix 0" data, t'ij is the result "matrix 6", Pi is the "generation" vector, Aj is the "attraction" vector, and pi and aj are the sum of rows and columns for each interation ("matrix k"), respectively. So, the iteration stops when Pi/pi and Aj/aj are equal to 1 (or very close).

In summary I will like to summarize all these loops (if is possible) in just one, doing several iterations, much more than 6...
Thks a lot!
Attachments
fratar.mdl
vensim file
(3.37 KiB) Downloaded 211 times
data_M.xlsx
data excel
(7.48 KiB) Downloaded 216 times
luisangelguzmang
Member
Posts: 42
Joined: Wed Apr 06, 2011 8:20 am

Re: Improving iterations!

Post by luisangelguzmang »

Hi, can you help me?? or is not possible?
Thks
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Re: Improving iterations!

Post by Administrator »

Can you upload the model you tried with FIND ZERO?
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Improving iterations!

Post by tomfid »

To use find zero, you'd have to define a one-dimensional array i_j of size ELMCOUNT(i)*ELMCOUNT(j) and map t[i,j] to t2[i_j]. Then you could use the find zero functionality to iterate.

This would probably work better as an external function though.
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Improving iterations!

Post by tomfid »

It would help to have a description of what you're trying to achieve with this calculation. There might be an easier way.
luisangelguzmang
Member
Posts: 42
Joined: Wed Apr 06, 2011 8:20 am

Re: Improving iterations!

Post by luisangelguzmang »

Hi, this is my problem. I have tried to be as specific as possible.
I get an initial 4x4 (ij) matrix (M0) into the Vensim model. I get another two additional vectors where information is available on the expected growth in data cells originating (Oi) and terminating (Dj) in each zone. I need to obtain a new matrix (M6), in this case with 6 iteractions (see attached model). But, what if I need additional iterations?
Returning to the example, this implies different growth rates for data in cells ij in and out of each zone and consequently having two sets of growth factors for each zone, say ai and bj. I need an iterative method to obtain an estimated new matrix (M6, in this case) which satisfies both sets of data-end constraints (Oi and Dj). I tried with FIN ZERO function, but I could not do anything.

So, I made this model calculating a set of intermediate correction coefficients which are then applied to cell entries in each row or column as appropriate. After applying these corrections to say, each row, the totals for each column are calculated and compared with the target values (Oi and Dj). If the differences are significant, new correction coefficients are calculated and applied as necessary. So,incorporating the growth rates into new variables ai and bj:

M6 = M0 x ai x bj

Where the factors ai and bj must be calculated so that the constraints are satisfied (sum i and sum j must be equal or very close to 1). This is achieved in an iterative process which in outline is as follows:

1. set all bj=1 and solve for ai; in this context, ‘solve for ai’ means find the correction factors ai that satisfy the Oi constraints;
2. with the latest ai solve for bj, e.g. satisfy the Dj constraints;
3. keeping the bj’s fixed, solve for ai and repeat steps (2) and (3) until the changes are sufficiently small (sum i and sum j equal or very close to 1).

In sum, I really want to know if there is any better (and elegant) way to solve this problem, or definitely the better way is doing as the attached model as many times as I needed.

Thanks a lot!
Attachments
fratar.mdl
Vensim file
(3.2 KiB) Downloaded 204 times
LAUJJL
Senior Member
Posts: 1427
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

Re: Improving iterations!

Post by LAUJJL »

Hi

you may find some information about using arrays for looping in the following thread

http://ventanasystems.co.uk/forum/viewt ... ilit=+loop

There are some references to some other threads interesting too.

Regards.

JJ
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Re: Improving iterations!

Post by Administrator »

I think you probably need to go to an external function with this.
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391

Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Post Reply