Class: Prolly::Ps

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(storage = nil) ⇒ Ps

Returns a new instance of Ps.



63
64
65
66
67
# File 'lib/prolly/ps.rb', line 63

def initialize(storage = nil)
  #@storage = Storage::Mongodb.new()
  @storage = Storage::Rubylist.new()
  #@storage = Storage::Redis.new()
end

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

.psObject



12
13
14
# File 'lib/prolly/ps.rb', line 12

def ps
  @ps ||= Ps.new
end

.resetObject



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

.stashObject



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