Skip to content

Instantly share code, notes, and snippets.

@baogorek
Last active March 5, 2019 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baogorek/6d682e42079005b3bde951e98ebae89e to your computer and use it in GitHub Desktop.
Save baogorek/6d682e42079005b3bde951e98ebae89e to your computer and use it in GitHub Desktop.
Code Block 1. Simulating H.T.’s training and performance data using the fitness-fatigue model from Physiology.
train_df <- data.frame(day = 1:259, day_of_week = 0:258 %% 7)
train_df$period <- ifelse(train_df$day <= 147, "build-up", "competition")
train_df$w <- with(train_df, w <-
-24 * (day_of_week == 0) +
12 * (day_of_week == 1) +
8 * (day_of_week == 2) +
0 * (day_of_week == 3) +
6 * (day_of_week == 4) +
-8 * (day_of_week == 5) +
6 * (day_of_week == 6))
set.seed(1523)
train_df$w <- rpois(nrow(train_df),
train_df$w + ifelse(train_df$period == "build-up", 34, 24))
exp_decay <- function(t, tau) {
exp(-t / tau)
}
convolve_training <- function(training, n, tau) {
sum(training[1:(n - 1)] * exp_decay((n - 1):1, tau))
}
fitness <- sapply(1:nrow(train_df),
function(n) convolve_training(train_df$w, n, 60))
fatigue <- sapply(1:nrow(train_df),
function(n) convolve_training(train_df$w, n, 13))
E_perf <- 496 + .07 * fitness - .27 * fatigue
set.seed(45345)
train_df$perf <- E_perf + 7.0 * rnorm(nrow(train_df))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment