Class: RandomSet::GaussianTrend

Inherits:
Object
  • Object
show all
Defined in:
lib/random_set/gaussian_trend.rb

Overview

Generates a Gaussian trend. For each sample, a Gaussian random number is generated using Gaussian, and its value is taken as the mean value for the next value. This produces a natural trend.

Instance Method Summary collapse

Constructor Details

#initialize(start, volatility = 0.2, rand_helper = lambda { Kernel.rand }) ⇒ GaussianTrend

Initializes the generator.

Parameters:

  • start (Float)

    The first mean value.

  • volatility (Float) (defaults to: 0.2)

    This number is multiplied with the mean to provide the standard deviation. The higher the number, the ‘wilder’ the trend will become. A value of 0.2 (default) produces a natural trend.

  • rand_helper (Proc) (defaults to: lambda { Kernel.rand })


20
21
22
23
24
# File 'lib/random_set/gaussian_trend.rb', line 20

def initialize(start, volatility = 0.2, rand_helper = lambda { Kernel.rand })
  @prev = start
  @volatility = volatility
  @rand_helper = rand_helper
end

Instance Method Details

#nextObject



26
27
28
# File 'lib/random_set/gaussian_trend.rb', line 26

def next
  @prev = Gaussian.new(@prev, @prev * @volatility, @rand_helper).next
end