-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expand arrays #8
Conversation
N_age <- parameter() | ||
dim(S0) <- N_age | ||
dim(I0) <- N_age | ||
dim(S) <- N_age | ||
dim(I) <- N_age | ||
dim(R) <- N_age | ||
dim(n_SI) <- N_age | ||
dim(n_IR) <- N_age | ||
dim(p_SI) <- N_age | ||
dim(m) <- c(N_age, N_age) | ||
dim(s_ij) <- c(N_age, N_age) | ||
dim(lambda) <- N_age |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wes' fixes here will make this nicer, we'll want to go back and add it
arrays.qmd
Outdated
|
||
Of course you may want to use higher-dimensional arrays! We currently supporting up to 8 dimensions, with index variables `i`, `j`, `k`, `l`, `i5`, `i6`, `i7` and `i8`. | ||
|
||
Be careful with array equations! It's possible that in an array equation you end up going out of bounds with an array used on the RHS. This can crash the program when running. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've got some thoughts on improving this, but it's a way off
arrays.qmd
Outdated
|
||
```r | ||
m_col_totals[] <- sum(m[, i]) | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other reduction functions that might be useful here are prod
, min
and max
, all of which work the same way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a note about those
# Force of infection | ||
m <- parameter() # age-structured contact matrix | ||
s_ij[, ] <- m[i, j] * sum(I[j, ]) | ||
lambda[] <- beta * sum(s_ij[i, ]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should spell out in the text that this is a matrix multiplication, and give the appropriate R code (lambda <- beta * (m %*% I)
I think) and say that we're looking to simplify this in future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a note about this!
arrays.qmd
Outdated
|
||
|
||
## Summing over arrays | ||
Frequently, you will want to take a sum over an array, or part of an array, using `sum`. To sum over all elements of an array, use `sum()` with the name of the array you would like to sum over: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section comes after the first bit of array modelling, so suggest a reordering? Perhaps build up to the SIR model you have by writing a simple model (e.g., something like SIR by hand for two cases, manually summing for the FOI, then merging, or even simpler two logistic growth curves then introduce the idea of summing)
Co-authored-by: Rich FitzJohn <r.fitzjohn@imperial.ac.uk>
No description provided.