Class: Spark::Sampler::Poisson
- Inherits:
-
Base
- Object
- Base
- Spark::Sampler::Poisson
show all
- Defined in:
- lib/spark/sampler.rb
Overview
Instance Attribute Summary
Attributes inherited from Base
#fraction, #seed
Instance Method Summary
collapse
Methods inherited from Base
#initialize
Instance Method Details
#lazy_sample(iterator) ⇒ Object
57
58
59
60
61
62
|
# File 'lib/spark/sampler.rb', line 57
def lazy_sample(iterator)
Enumerator::Lazy.new(iterator) do |yielder, value|
count = rng.rand
count.times { yielder << value }
end
end
|
#sample(iterator) ⇒ Object
47
48
49
50
51
52
53
54
55
|
# File 'lib/spark/sampler.rb', line 47
def sample(iterator)
iterator.map! do |item|
count = rng.rand
Array.new(count) { item }
end
iterator.flatten!
iterator.compact!
iterator
end
|