class RandomGaussian
Public Class Methods
gaussian(mean, stddev, rand)
click to toggle source
# File lib/tensor_stream/evaluator/operation_helpers/random_gaussian.rb, line 23 def self.gaussian(mean, stddev, rand) theta = 2 * Math::PI * rand.call rho = Math.sqrt(-2 * Math.log(1 - rand.call)) scale = stddev * rho x = mean + scale * Math.cos(theta) y = mean + scale * Math.sin(theta) [x, y] end
new(mean, stddev, rand_helper = -> { Kernel.rand }
click to toggle source
# File lib/tensor_stream/evaluator/operation_helpers/random_gaussian.rb, line 3 def initialize(mean, stddev, rand_helper = -> { Kernel.rand }) @rand_helper = rand_helper @mean = mean @stddev = stddev @valid = false @next = 0 end
Public Instance Methods
rand()
click to toggle source
# File lib/tensor_stream/evaluator/operation_helpers/random_gaussian.rb, line 11 def rand if @valid @valid = false @next else @valid = true x, y = self.class.gaussian(@mean, @stddev, @rand_helper) @next = y x end end