Class: RandomGaussian
- Inherits:
-
Object
- Object
- RandomGaussian
- Defined in:
- lib/tensor_stream/evaluator/operation_helpers/random_gaussian.rb
Overview
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(mean, stddev, rand_helper = -> { Kernel.rand }) ⇒ RandomGaussian
constructor
A new instance of RandomGaussian.
- #rand ⇒ Object
Constructor Details
#initialize(mean, stddev, rand_helper = -> { Kernel.rand }) ⇒ RandomGaussian
Returns a new instance of RandomGaussian.
3 4 5 6 7 8 9 |
# 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 |
Class Method Details
.gaussian(mean, stddev, rand) ⇒ Object
23 24 25 26 27 28 29 30 |
# 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 |
Instance Method Details
#rand ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# 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 |