Class: Statistics::Histogram
- Inherits:
-
Object
- Object
- Statistics::Histogram
- Defined in:
- lib/Statistics/Histogram.rb,
lib/Statistics/Histogram/Bin.rb
Defined Under Namespace
Classes: Bin
Instance Attribute Summary collapse
-
#bins ⇒ Object
readonly
Returns the value of attribute bins.
-
#boundaries ⇒ Object
readonly
Returns the value of attribute boundaries.
Instance Method Summary collapse
Instance Attribute Details
#bins ⇒ Object (readonly)
Returns the value of attribute bins.
8 9 10 |
# File 'lib/Statistics/Histogram.rb', line 8 def bins @bins end |
#boundaries ⇒ Object (readonly)
Returns the value of attribute boundaries.
8 9 10 |
# File 'lib/Statistics/Histogram.rb', line 8 def boundaries @boundaries end |
Instance Method Details
#bin_count ⇒ Object
14 15 16 |
# File 'lib/Statistics/Histogram.rb', line 14 def bin_count @bins.size end |
#mode ⇒ Object
10 11 12 |
# File 'lib/Statistics/Histogram.rb', line 10 def mode @bins.max_by(&:count) end |
#to_s ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/Statistics/Histogram.rb', line 18 def to_s max_count = @bins.map(&:count).max @bins.map do |bin| = '*' * ((bin.count.to_f / max_count) * 40).round format('%8.2f...%-8.2f | %3d | %s', bin.interval.begin, bin.interval.end, bin.count, ) end.join("\n") end |