gov_init {governor}R Documentation

Initialize a governor to control the speed of a loop

Description

Initialize a governor to control the speed of a loop

Usage

gov_init(interval, alpha = 0.4, alpha_decay = 0.95, alpha_target = 0.05)

Arguments

interval

desired interval in seconds E.g. interval = 1.5 sets the time-per-loop to 1.5 seconds. E.g. interval = 1/30 sets the loop to run at 30 times per second

alpha

initial learning rate used to adjust wait time. Default: 0.4

alpha_decay

rate at which alpha decays. Default: 0.95 i.e. 5 each iteration

alpha_target

the baseline alpha to reach when running long term. default: 0.05

Value

gov object to be used with gov_wait()

Examples

# This loop should take approx 1 second as the governor will limit
# the loop to run every thirtieth of a second.
gov <- gov_init(1/30)
system.time({
  for (i in 1:30) {
    gov_wait(gov)
  }
})

[Package governor version 0.1.2 Index]