Module: RankProduct

Defined in:
lib/rbbt/statistics/rank_product.rb

Class Method Summary collapse

Class Method Details

.permutations(num_signatures, num = 1000) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rbbt/statistics/rank_product.rb', line 15

def self.permutations(num_signatures, num = 1000)
  scores = []
  num.times{
     value = 0
     num_signatures.times{|size_and_log| 
       value += Math::log(rand)
     } 
     scores << value
  }
  scores
end

.permutations_full(signature_sizes) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rbbt/statistics/rank_product.rb', line 27

def self.permutations_full(signature_sizes)
  gene_ranks = {}
  signature_sizes.each{|size|
    (1..size).to_a.shuffle.each_with_index{|gene, pos|
      gene_ranks[gene] ||= []
      gene_ranks[gene] << pos + 1
    }
  }
  gene_ranks.delete_if{|code, positions| positions.length != signature_sizes.length}

  scores = score(gene_ranks, signature_sizes)
  scores.values
end

.score(gene_ranks, signature_sizes) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/rbbt/statistics/rank_product.rb', line 4

def self.score(gene_ranks, signature_sizes)
  scores = {}
  log_sizes = signature_sizes.collect{|size| Math::log(size)}
  gene_ranks.each{|gene, positions|
    scores[gene] = positions.collect{|p| p.nil? or (p.respond_to?(:empty?) and p.empty?) ? signature_sizes.max  : p }.zip(log_sizes).
      collect{|p| Math::log(p[0]) - p[1]}.   
      inject(0){|acc, v| acc += v  }
  }
  scores
end