Last active
December 24, 2018 16:58
-
-
Save baogorek/062fdc50db536393b10c39f98ad0ca89 to your computer and use it in GitHub Desktop.
Nonlinear optimization to fit the fitness-fatigue model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Recover parameters using non-linear regression | |
rss <- function(theta) { | |
int <- theta[1] # performance baseline | |
k1 <- theta[2] # fitness weight | |
k2 <- theta[3] # fatigue weight | |
tau1 <- theta[4] # fitness decay | |
tau2 <- theta[5] # fatigue decay | |
fitness <- sapply(1:nrow(train_df), | |
function(n) convolve_training(train_df$w, n, tau1)) | |
fatigue <- sapply(1:nrow(train_df), | |
function(n) convolve_training(train_df$w, n, tau2)) | |
perf_hat <- int + k1 * fitness - k2 * fatigue | |
return(sum((train_df$perf - perf_hat) ^ 2)) | |
} | |
optim_results <- optim(c(400, .05, .15, 20, 5), rss, method = "BFGS", | |
hessian = TRUE, control = list(maxit = 1000)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment