Module: Util
- Defined in:
- ../lib/store.rb,
../lib/utils.rb,
../lib/report.rb,
../lib/config.rb,
../lib/work_pipes.rb,
../lib/individual.rb,
../lib/alps_individual.rb,
../lib/piped_individual.rb
Defined Under Namespace
Modules: AlpsIndividual
Classes: ConfigYaml, Individual, PipedIndividual, Report, ReportStream, ReportText, Store, WorkPipes
Class Method Summary
(collapse)
Class Method Details
+ (Object) diversity(arr)
27
28
29
30
31
32
33
34
35
|
# File '../lib/utils.rb', line 27
def Util.diversity arr
count = Hash.new 0
if block_given?
arr.each { |val| count[ yield(val) ] += 1 }
else
arr.each { |val| count[ val ] += 1 }
end
count.values.sort {|a,b| b <=> a}
end
|
+ (Object) percent(nominator, denominator)
37
38
39
40
41
42
43
|
# File '../lib/utils.rb', line 37
def Util.percent( nominator, denominator )
if denominator == 0
'N/A%'
else
"#{(100.0*nominator/denominator).round}%"
end
end
|
+ (Object) permutate(arr, rnd = Kernel)
45
46
47
48
49
50
51
52
53
|
# File '../lib/utils.rb', line 45
def Util.permutate( arr, rnd=Kernel )
src = arr.clone
res = []
until src.empty?
i = rnd.rand src.size
res << src.delete_at( i )
end
res
end
|
+ (Object) statistics(arr)
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File '../lib/utils.rb', line 4
def Util.statistics arr
max = nil
min = nil
sum = 0.0
n = 0
arr.each do |i|
next if i.nil?
if i.to_f.infinite?
max = i
next
end
value = block_given? ? yield(i) : i
max = (max.nil? || value>max) ? value : max
min = (min.nil? || value<min) ? value : min
sum += value
n += 1
end
return min, max, sum/n, n if n>0
return nil, nil, nil, 0
end
|