Class: Lm::Petrick
- Inherits:
-
Object
- Object
- Lm::Petrick
- Defined in:
- lib/lm/petrick.rb
Instance Method Summary collapse
- #essential_columns ⇒ Object
- #essential_rows ⇒ Object
-
#factors ⇒ Object
factors from the petrick table.
- #grouplist ⇒ Object
-
#initialize(chart) ⇒ Petrick
constructor
A new instance of Petrick.
- #string122 ⇒ Object
- #uncovered_columns ⇒ Object
Constructor Details
#initialize(chart) ⇒ Petrick
Returns a new instance of Petrick.
5 6 7 |
# File 'lib/lm/petrick.rb', line 5 def initialize(chart) @chart = chart end |
Instance Method Details
#essential_columns ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/lm/petrick.rb', line 28 def essential_columns @essential_columns ||= begin varcounts = {} grouplist.each_with_index do |group, _idx| group.split(",").each do |v| varcounts[v] ||= 0 varcounts[v] += 1 end end varcounts.select { |_k, v| v == 1 }.to_h.keys end end |
#essential_rows ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/lm/petrick.rb', line 41 def essential_rows @essential_rows ||= begin rows = [] essential_columns.each do |x| grouplist.each_with_index do |group, idx| vars = Set.new(group.split(",")) if vars.include?(x) rows << idx break end end end rows end end |
#factors ⇒ Object
factors from the petrick table
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/lm/petrick.rb', line 14 def factors factorlist = [] uncovered_columns.each do |var| factor = [] grouplist.each_with_index do |group, idx| vlist = Set.new(group.split(",")) factor << [idx] if vlist.include?(var) end factorlist << factor end factorlist + essential_rows.map { |x| [[x]] } end |
#grouplist ⇒ Object
9 10 11 |
# File 'lib/lm/petrick.rb', line 9 def grouplist @grouplist ||= @chart.keys end |
#string122 ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/lm/petrick.rb', line 69 def string122 factors .map do |sums| sums.map do |prducts| prducts.map { |x| (x.ord + 48).chr }.join("") end.join("+") end .join(",") end |
#uncovered_columns ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/lm/petrick.rb', line 58 def uncovered_columns @uncovered_columns ||= begin touched = Set.new essential_rows.each do |idx| touched += grouplist.to_a[idx].split(",") end @chart.variables - touched end end |