Class: Prolly::Ps
- Inherits:
-
Object
- Object
- Prolly::Ps
- Extended by:
- Forwardable
- Defined in:
- lib/prolly/ps.rb,
lib/prolly/ps/storage/base.rb,
lib/prolly/ps/storage/redis.rb,
lib/prolly/ps/storage/mongodb.rb,
lib/prolly/ps/storage/rubylist.rb
Defined Under Namespace
Modules: Storage
Class Method Summary collapse
- .add(datum) ⇒ Object
- .import(data) ⇒ Object
- .ps ⇒ Object
- .reset ⇒ Object
- .rv(*rand_vars) ⇒ Object
- .stash ⇒ Object
-
.uniq_vals(uspec_rvs) ⇒ Object
unique values for a random variable.
Instance Method Summary collapse
- #combo(list_of_vals) ⇒ Object
-
#initialize(storage = nil) ⇒ Ps
constructor
A new instance of Ps.
Constructor Details
Class Method Details
.add(datum) ⇒ Object
24 25 26 |
# File 'lib/prolly/ps.rb', line 24 def add(datum) ps.add(datum) end |
.import(data) ⇒ Object
16 17 18 |
# File 'lib/prolly/ps.rb', line 16 def import(data) ps.import(data) end |
.reset ⇒ Object
20 21 22 |
# File 'lib/prolly/ps.rb', line 20 def reset ps.reset end |
.rv(*rand_vars) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/prolly/ps.rb', line 28 def rv(*rand_vars) if rand_vars.empty? ps.rand_vars else RandVar.new(ps, *rand_vars) end end |
.stash ⇒ Object
36 37 38 |
# File 'lib/prolly/ps.rb', line 36 def stash ps.stash end |
.uniq_vals(uspec_rvs) ⇒ Object
unique values for a random variable.
If there are multiple random variables, then we get combinations of the unique values of the random variables
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/prolly/ps.rb', line 44 def uniq_vals(uspec_rvs) def combo(list_of_vals) if list_of_vals.length == 1 list_of_vals.first.map { |e| [e] } else combinations = combo(list_of_vals[1..-1]) list_of_vals.first.flat_map { |val| combinations.map { |e| [val] + e } } end end combo(uspec_rvs.map { |uspec_rv| @ps.uniq_vals(uspec_rv) }) end |
Instance Method Details
#combo(list_of_vals) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/prolly/ps.rb', line 46 def combo(list_of_vals) if list_of_vals.length == 1 list_of_vals.first.map { |e| [e] } else combinations = combo(list_of_vals[1..-1]) list_of_vals.first.flat_map { |val| combinations.map { |e| [val] + e } } end end |