summaryrefslogtreecommitdiff
path: root/lib/algorithm.rb
blob: fb4738593cb99e28dc00b74d089cdf7fb9287d0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
=begin
* Name: algorithm.rb
* Description: General algorithms
* Author: Andreas Maunz <andreas@maunz.de>
* Date: 10/2012
=end

module OpenTox
  class Algorithm

    # Minimum Frequency
    # @param [Integer] per-mil value
    # return [Integer] min-frequency
    def self.min_frequency(training_dataset,prediction_feature,per_mil)
      nr_labeled_cmpds=0
      f_idx=training_dataset.features.collect{|f| f.uri}.index prediction_feature.uri
      training_dataset.compounds.each_with_index { |cmpd, c_idx|
        if ( training_dataset.data_entries[c_idx] )
             unless training_dataset.data_entries[c_idx][f_idx].nil?
               nr_labeled_cmpds += 1 
             end
        end
      }
      minfreq = per_mil * nr_labeled_cmpds.to_f / 1000.0 # AM sugg. 8-10 per mil for BBRC, 50 per mil for LAST
      minfreq = 2 unless minfreq > 2
      Integer (minfreq)
    end

  end
end