Class: Statistics::Histogram

Inherits:
Object
  • Object
show all
Defined in:
lib/Statistics/Histogram.rb,
lib/Statistics/Histogram/Bin.rb

Defined Under Namespace

Classes: Bin

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#binsObject (readonly)

Returns the value of attribute bins.



8
9
10
# File 'lib/Statistics/Histogram.rb', line 8

def bins
  @bins
end

#boundariesObject (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_countObject



14
15
16
# File 'lib/Statistics/Histogram.rb', line 14

def bin_count
  @bins.size
end

#modeObject



10
11
12
# File 'lib/Statistics/Histogram.rb', line 10

def mode
  @bins.max_by(&:count)
end

#to_sObject



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|
    bar = '*' * ((bin.count.to_f / max_count) * 40).round
    format('%8.2f...%-8.2f | %3d | %s', bin.interval.begin, bin.interval.end, bin.count, bar)
  end.join("\n")
end