Class: Spark::Sampler::Uniform

Inherits:
Base
  • Object
show all
Defined in:
lib/spark/sampler.rb

Overview

Uniform Sampler


Instance Attribute Summary

Attributes inherited from Base

#fraction, #seed

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Spark::Sampler::Base

Instance Method Details

#lazy_sample(iterator) ⇒ Object



79
80
81
82
83
# File 'lib/spark/sampler.rb', line 79

def lazy_sample(iterator)
  iterator.select do |item|
    rng.rand <= fraction
  end
end

#rngObject



85
86
87
# File 'lib/spark/sampler.rb', line 85

def rng
  @rng ||= Random.new(seed)
end

#sample(iterator) ⇒ Object



74
75
76
77
# File 'lib/spark/sampler.rb', line 74

def sample(iterator)
  iterator.select!{|item| rng.rand <= fraction}
  iterator
end