Class: Statistics::Histogram::Bin

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#countObject (readonly)

class << self



54
55
56
# File 'lib/Statistics/Histogram/Bin.rb', line 54

def count
  @count
end

#intervalObject (readonly)

class << self



54
55
56
# File 'lib/Statistics/Histogram/Bin.rb', line 54

def interval
  @interval
end

Class Method Details

.bin_for_value(value, bins, bottom_boundary, bin_width) ⇒ Object



33
34
35
36
# File 'lib/Statistics/Histogram/Bin.rb', line 33

def bin_for_value(value, bins, bottom_boundary, bin_width)
  index = index_for_value(value, bins.count, bottom_boundary, bin_width)
  bins[index]
end

.boundaries(values, bin_width: nil, bin_count: nil, method: :square_root) ⇒ Object



28
29
30
31
# File 'lib/Statistics/Histogram/Bin.rb', line 28

def boundaries(values, bin_width: nil, bin_count: nil, method: :square_root)
  w = bin_width || width(values, bin_count: bin_count, method: method)
  values.first.step(to: values.last + w, by: w).to_a
end

.count(values, method: :square_root) ⇒ Object



20
21
22
# File 'lib/Statistics/Histogram/Bin.rb', line 20

def count(values, method: :square_root)
  send("#{method}_count", values)
end

.data_range(values) ⇒ Object



24
25
26
# File 'lib/Statistics/Histogram/Bin.rb', line 24

def data_range(values)
  values.last - values.first
end

.width(values, bin_width: nil, bin_count: nil, method: :square_root) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/Statistics/Histogram/Bin.rb', line 8

def width(values, bin_width: nil, bin_count: nil, method: :square_root)
  if bin_width
    bin_width
  elsif bin_count
    data_range(values) / bin_count.to_f
  elsif data_range(values) == 0
    1.0
  else
    send("#{method}_width", values)
  end
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/Statistics/Histogram/Bin.rb', line 64

def empty?
  @count == 0
end

#incrementObject



56
57
58
# File 'lib/Statistics/Histogram/Bin.rb', line 56

def increment
  @count += 1
end

#widthObject



60
61
62
# File 'lib/Statistics/Histogram/Bin.rb', line 60

def width
  @interval.end - @interval.begin
end