Skip to content
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

Merged
merged 6 commits into from
Nov 8, 2024
Merged

Expand arrays #8

merged 6 commits into from
Nov 8, 2024

Conversation

edknock
Copy link
Contributor

@edknock edknock commented Nov 7, 2024

No description provided.

@edknock edknock marked this pull request as draft November 7, 2024 11:56
@edknock edknock marked this pull request as ready for review November 7, 2024 15:09
@edknock edknock requested review from richfitz and MJomaba November 7, 2024 15:36
Comment on lines +58 to +69
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
Copy link
Member

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.
Copy link
Member

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 Show resolved Hide resolved
arrays.qmd Outdated Show resolved Hide resolved
arrays.qmd Outdated Show resolved Hide resolved
arrays.qmd Outdated

```r
m_col_totals[] <- sum(m[, i])
```
Copy link
Member

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

Copy link
Contributor Author

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

Comment on lines +105 to +108
# Force of infection
m <- parameter() # age-structured contact matrix
s_ij[, ] <- m[i, j] * sum(I[j, ])
lambda[] <- beta * sum(s_ij[i, ])
Copy link
Member

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?

Copy link
Contributor Author

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:
Copy link
Member

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)

edknock and others added 3 commits November 7, 2024 16:39
@edknock edknock requested a review from richfitz November 8, 2024 12:08
@richfitz richfitz merged commit dfd5cc1 into main Nov 8, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants