Class: Skab::Output::Differential

Inherits:
Object
  • Object
show all
Defined in:
lib/skab/output/differential.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(out) ⇒ Differential

Returns a new instance of Differential.



4
5
6
# File 'lib/skab/output/differential.rb', line 4

def initialize(out)
  @out = out
end

Class Method Details

.helpObject



27
28
29
30
31
32
33
34
35
# File 'lib/skab/output/differential.rb', line 27

def self.help
  <<-HELP
Usage: skab differential [model] [parameters]
\tOutputs the discrete probability distribution for (B - A) as returned by the
\tspecified model. The output is a two columns CSV file, where the first
\tcolumn is the absolute value of (B - A) and the second column the
\tcorresponding discrete probability
  HELP
end

Instance Method Details

#output(model) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/skab/output/differential.rb', line 8

def output(model)
  data = model.differential
  
  range = 0
  data.each do |k, v|
    if v != 0 && abs(k) > range
      range = abs(k)
    end
  end

  range += range / 10

  Hash[data.sort].each do |k, v|
    if abs(k) <= range
      @out.puts "#{k},#{v}"
    end
  end
end