I have a few questions related to number arrays.
Question 1. What is the syntax for taking a partial sum of an array? I would expect something like SUM(array[i!],min_index,max_index)
I am including my mdl file for the next few questions.
Question 2. I want my array to update only when a certain value is non zero. Am I using the IF THEN ELSE syntax correctly in the variable "FailureTable"?
Question 3. The variable "FailureTable" is an array of 8 values. When "breed" is non-zero, these values should shift up one index and be multiplied by the FailureRate. The first index is filled with a different function. Again, I'm not sure my syntax is correct in the variable "FailureTable".
Question 4. I would like to do a weighted sum to compute the variable "Pregnant Feed Requirements". I'm not sure how to 'index' the queue fifo variable "pregnant ewes" so I can perform the weighted sum.
I have tried to use comments on these variables to describe further what is happening. Please feel free to ask any questions you might have.
Thank you!
question about sum and arrays
question about sum and arrays
- Attachments
-
- simpleewesAug5.mdl
- (8.34 KiB) Downloaded 181 times
-
- Super Administrator
- Posts: 4593
- Joined: Wed Mar 05, 2003 3:10 am
Re: question about sum and arrays
You will need to create an array index parameter,What is the syntax for taking a partial sum of an array? I would expect something like SUM(array[i!],min_index,max_index)
i ID = i
Then
sum ( if them else ( i ID[i!] >- min_index :and: i ID[i!] <= max_index, array[i!] , 0 ) )
Question 2. I want my array to update only when a certain value is non zero. Am I using the IF THEN ELSE syntax correctly in the variable "FailureTable"?
I cannot decipher what you are attempting to do here so this is a guess. I think you need SAMPLE IF TRUE
failuretable[Failure] = SAMPLE IF TRUE ( breed >= 0.0001 , failuretable[failure]*failurerate )
Question 3. The variable "FailureTable" is an array of 8 values. When "breed" is non-zero, these values should shift up one index and be multiplied by the FailureRate. The first index is filled with a different function. Again, I'm not sure my syntax is correct in the variable "FailureTable".
No it's not. Can you explain why you need to do this and I'll see if I can think of a way?
Question 4. I would like to do a weighted sum to compute the variable "Pregnant Feed Requirements". I'm not sure how to 'index' the queue fifo variable "pregnant ewes" so I can perform the weighted sum.
Do you mean to use the following?
SUM( Pregnant Ewes[pregage!] * FEED BY AGE IN QUEUE[pregage!])
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
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Re: question about sum and arrays
I avoid this kind of for-loop logic as much as possible.What is the syntax for taking a partial sum of an array? I would expect something like SUM(array[i!],min_index,max_index)
If the partial sum is over some predictable subset, use a subrange, e.g.
Code: Select all
range : a,b,c,d,e,f
subrange : a, d, f
y = SUM( x[subrange!] )
Code: Select all
i ID[i] = INITIAL( i )
A faster (but slightly harder) solution is to use mapping, like:
Code: Select all
range : a,b,c,d,e,f
lowElements : a,b,c,d,e -> highElements
highElements : b,c,d,e,f -> lowElements
y[a] = x[a]
y[high elements] = y[lowElements] + x[highElements]
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Re: question about sum and arrays
Hello thank you for the fast reply.
Question 1: Thank you. That is what I was looking for.
Questions 2 & 3:
Question 1: Thank you. That is what I was looking for.
Questions 2 & 3:
I have a group of animals that enter a breeding pool. 30 days later X of them have bred and Y have not. The ones that breed move through the rest of the model and 250 days later the successful X, the unsuccessful Y, and new group Z animals enter the breeding pool. Some percent will breed, and some percent will fail. I need to track the number that fail for the 2nd-8th time because we'll be removing animals that fail to breed N times from the population. (where N is an input number between 2-8). I'm doing it statistically by creating an array variable that retains the number of animals that failed to breed in the previous cycle. Each time a new breed pool is populated I update my array variables to tell me how many animals are expected to fail for their Nth time in the present breeding cycle.Administrator wrote:I cannot decipher what you are attempting to do here so this is a guess. I think you need SAMPLE IF TRUE
failuretable[Failure] = SAMPLE IF TRUE ( breed >= 0.0001 , failuretable[failure]*failurerate )
No it's not. Can you explain why you need to do this and I'll see if I can think of a way?
That is what I would like, can I really access the content of a queue fifo with a simple index? If so, this makes life much easier. Also, if so, does that index start at 1 or 0, and does the queue fifo interpolate for a non-whole number index?Administrator wrote:Do you mean to use the following?Question 4. I would like to do a weighted sum to compute the variable "Pregnant Feed Requirements". I'm not sure how to 'index' the queue fifo variable "pregnant ewes" so I can perform the weighted sum.
SUM( Pregnant Ewes[pregage!] * FEED BY AGE IN QUEUE[pregage!])
Re: question about sum and arrays
Hi Tom,tomfid wrote:I avoid this kind of for-loop logic as much as possible.What is the syntax for taking a partial sum of an array? I would expect something like SUM(array[i!],min_index,max_index)
If the partial sum is over some predictable subset, use a subrange, e.g.
If you do need y = SUM( x[ elements up to i ] ), you can use admin's solution. The index parameter can be wrapped in an INITIAL for efficiency, i.e.Code: Select all
range : a,b,c,d,e,f subrange : a, d, f y = SUM( x[subrange!] )
Code: Select all
i ID[i] = INITIAL( i )
It is a predictable subset, but the size of the subset is set by an excel lookup.
So for example, if the variable in excel says, max_index= 4, then I will want the subrange to be subrange: a,b,c,d. Since I don't know how to set a subrange based on an input variable, I assume that I should probably use
Code: Select all
sum ( if then else ( i ID[i!] >=1 :and: i ID[i!] <= max_index, array[i!] , 0 ) )
-
- Super Administrator
- Posts: 4593
- Joined: Wed Mar 05, 2003 3:10 am
Re: question about sum and arrays
I'm not sure this is how I would approach this in Vensim.ebr567 wrote:I have a group of animals that enter a breeding pool. 30 days later X of them have bred and Y have not. The ones that breed move through the rest of the model and 250 days later the successful X, the unsuccessful Y, and new group Z animals enter the breeding pool. Some percent will breed, and some percent will fail. I need to track the number that fail for the 2nd-8th time because we'll be removing animals that fail to breed N times from the population. (where N is an input number between 2-8). I'm doing it statistically by creating an array variable that retains the number of animals that failed to breed in the previous cycle. Each time a new breed pool is populated I update my array variables to tell me how many animals are expected to fail for their Nth time in the present breeding cycle.
Have a look at the tubs example in Vensim, this involves water flowing from one tub to another (similar to an ageing chain). There is also an ageing chain model in the documentation.
And the following might also be useful if you are a DSS user,
http://www.systemdynamics.org/conferenc ... /P1064.pdf
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
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Re: question about sum and arrays
I might do this the old-fashioned way, with an explicit chain of stocks rather than arrays. It might be a little more work to set up, but it's more visible.
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Re: question about sum and arrays
Also, this might be a good Ventity model. You'd make each breeding stock with N failures an entity, and create the N needed entities automatically via an action.
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/