Skip to content

Instantly share code, notes, and snippets.

@baogorek
Created April 7, 2019 00:54
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/446466133f9e8eb55e34bd8af61e0b74 to your computer and use it in GitHub Desktop.
Save baogorek/446466133f9e8eb55e34bd8af61e0b74 to your computer and use it in GitHub Desktop.
get_perf_params <- function(world_record_perf, able_bodied_perf, limit,
type = "running") {
# sum of squares around fixed point
rss <- function(a, b, world_record_perf, able_bodied_perf, limit) {
(1000 - b * log(a / (world_record_perf - limit))) ** 2 +
(0 - b * log(a / (able_bodied_perf - limit))) ** 2
}
stopifnot(type %in% c("running", "jumping"))
a_starting <- ifelse(type == "running", 5, -5)
b_starting <- 100
optim_results <- optim(c(a_starting, b_starting),
function(params) rss(params[1], params[2],
world_record_perf,
able_bodied_perf, limit))
list(a = optim_results$par[1], b = optim_results$par[2], limit = limit,
optim_results = optim_results)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment