getRandomWalk: Random walk

Description Usage Arguments Details Value Examples

View source: R/utilities_math.R

Description

Internal soundgen function.

Usage

1
2
getRandomWalk(len, rw_range = 1, rw_smoothing = 0.2, method = c("linear",
  "spline")[2], trend = 0)

Arguments

len

an integer specifying the required length of random walk. If len is 1, returns a single draw from a gamma distribution with mean=1 and sd=rw_range

rw_range

the upper bound of the generated random walk (the lower bound is set to 0)

rw_smoothing

specifies the amount of smoothing, from 0 (no smoothing) to 1 (maximum smoothing to a straight line)

method

specifies the method of smoothing: either linear interpolation ('linear', see approx) or cubic splines ('spline', see spline)

trend

mean of generated normal distribution (vectors are also acceptable, as long as their length is an integer multiple of len). If positive, the random walk has an overall upwards trend (good values are between 0 and 0.5 or -0.5). Trend = c(1,-1) gives a roughly bell-shaped rw with an upward and a downward curve. Larger absolute values of trend produce less and less random behavior

Details

Generates a random walk with flexible control over its range, trend, and smoothness. It works by calling rnorm at each step and taking a cumulative sum of the generated values. Smoothness is controlled by initially generating a shorter random walk and upsampling.

Value

Returns a numeric vector of length len and range from 0 to rw_range.

Examples

1
2
3
4
5
6
plot(soundgen:::getRandomWalk(len = 1000, rw_range = 5,
  rw_smoothing = .2))
plot(soundgen:::getRandomWalk(len = 1000, rw_range = 15,
  rw_smoothing = .2, trend = c(.5, -.5)))
plot(soundgen:::getRandomWalk(len = 1000, rw_range = 15,
  rw_smoothing = .2, trend = c(15, -1)))

tatters/soundgen_beta documentation built on May 14, 2019, 9 a.m.