Class: Shades::DynamicHistogram

Inherits:
Object
  • Object
show all
Defined in:
lib/shades/histo.rb

Overview

streaming histograms: Ruby port of the Clojure library from BigML: github.com/bigmlcom/histogram

Instance Method Summary collapse

Constructor Details

#initialize(max_size) ⇒ DynamicHistogram

Returns a new instance of DynamicHistogram.



8
9
10
# File 'lib/shades/histo.rb', line 8

def initialize(max_size)
  @res = StreamReservoir.new(max_size)
end

Instance Method Details

#add(f) ⇒ Object



12
13
14
15
# File 'lib/shades/histo.rb', line 12

def add(f)
  @res.add(StreamBin.new(1, f))
  @res.compress
end

#ascii_art(output_width, log_base) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/shades/histo.rb', line 21

def ascii_art(output_width, log_base)
  @res.histo_text(output_width) do |x|
    if log_base != 0
      Math::log(x, log_base)
    else
      x
    end
  end
end

#linesObject



17
18
19
# File 'lib/shades/histo.rb', line 17

def lines
  @res.lines
end