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

Refactor the HSe functions #2

Closed
trosendal opened this issue Oct 28, 2016 · 4 comments
Closed

Refactor the HSe functions #2

trosendal opened this issue Oct 28, 2016 · 4 comments

Comments

@trosendal
Copy link
Member

These functions could vectorized. Currently the functions calculate, the HSe for a single herd given the distribution of animal risk groups in the farm. It uses the product function to solve this. However, if we want to be able to pass a vector of herds then the function needs to either take wide data, currently it is long form, or internally reshape the data to wide and pass these vectors to the function.

The current use required indexing of the dataframe many times which is slow. This will be a problem when using the function to test scenarios with a distribution of input parameters.

@trosendal trosendal assigned trosendal and unassigned trosendal Oct 28, 2016
@trosendal
Copy link
Member Author

trosendal commented Oct 28, 2016

Just tested the whole procedure over 5000 iterations, it took 43 seconds with 100 herds in 2 risk categories.
On a single thread using a i5-3320M CPU @ 2.60GHz

@trosendal
Copy link
Member Author

Whole process for 1000 herds, 5 risks categories for animals, 5 for herds. 100 iterations == 41 seconds.

This is probably not a good enough start as the models will become much more complex.... Several years and several components.

@trosendal
Copy link
Member Author

I had a discussion with @stewid about this problem. He suggested using tapply() to solve it. I have now refactored the code to use this approach.

@trosendal
Copy link
Member Author

Over 10000 iteractions the test in ´full_test.R` took:

user  system elapsed 
 39.748   0.000  40.381 

Using the new code:

user  system elapsed 
5.092    0.000  5.649 

I will merge this into the master

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

No branches or pull requests

1 participant