Module: FDR

Defined in:
lib/MARQ/fdr.rb

Class Method Summary collapse

Class Method Details

.adjust_hash!(data, field = nil) ⇒ Object

This will change the values of the floats in situ



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/MARQ/fdr.rb', line 115

def self.adjust_hash!(data, field = nil)
  keys = []
  values = []

  data.collect{|key, value| [key, field.nil? ? value : value[field]] }.sort{|a,b| 
    a[1] <=> b[1]
  }.each{|p|
    keys << p[0]
    values << p[1]
  }

  FDR.adjust!(values)

  data
end

.adjust_native(values) ⇒ Object

values should be sorted



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/MARQ/fdr.rb', line 20

def self.adjust_native(values)
  total = values.length.to_f

  adjusted = []
  last = 1
  values.reverse.each_with_index do |value, i|
    adj = [last, value * total / (total - i )].min
    last = adj
    adjusted << adj
  end

  adjusted.reverse
end

.step_up_native(values, rate) ⇒ Object

values should be sorted



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/MARQ/fdr.rb', line 6

def self.step_up_native(values, rate)
  total = values.length

  last = 0
  values.each_with_index  do |value, i|
    if value > rate * (i + 1).to_f / total
      return last
    end
    last = value
  end
  return last
end