diff options
author | dv <dv@dv.de> | 2011-07-27 18:55:05 +0200 |
---|---|---|
committer | dv <dv@dv.de> | 2011-07-27 18:55:05 +0200 |
commit | 1dcc4402c15001a89b10e1e8bbdc4ab6b0a30a4b (patch) | |
tree | cd0b88348acf2ab6de61c4773183b40c58f50bd0 /lib | |
parent | 4cacbe3d45acaed3f7b4edf11b4115df55c84829 (diff) | |
parent | 545af9b1376ed56aa75be709f8d7a7f4c2a5fd5e (diff) |
Merge branch 'development' of github.com:opentox/opentox-ruby into development
Diffstat (limited to 'lib')
-rw-r--r-- | lib/algorithm.rb | 45 | ||||
-rw-r--r-- | lib/dataset.rb | 12 |
2 files changed, 16 insertions, 41 deletions
diff --git a/lib/algorithm.rb b/lib/algorithm.rb index 5093c34..a0ad9a5 100644 --- a/lib/algorithm.rb +++ b/lib/algorithm.rb @@ -383,7 +383,7 @@ module OpenTox gram_matrix = [] # square matrix of similarities between neighbors; implements weighted tanimoto kernel prediction = nil - if acts.to_scale.variance_population == 0 + if Algorithm::zero_variance? acts prediction = acts[0] else # gram matrix @@ -467,7 +467,7 @@ module OpenTox q_prop = props[1] # is an Array. prediction = nil - if acts.to_scale.variance_population == 0 + if Algorithm::zero_variance? acts prediction = acts[0] else #LOGGER.debug gram_matrix.to_yaml @@ -517,11 +517,11 @@ module OpenTox # @return[Float] Confidence def self.get_confidence(params) if params[:conf_stdev] - sim_median = Algorithm.median(params[:sims]) + sim_median = params[:sims].to_scale.median if sim_median.nil? confidence = nil else - standard_deviation = params[:acts].std_dev + standard_deviation = params[:acts].to_scale.standard_deviation_sample confidence = (sim_median*Math.exp(-1*standard_deviation)).abs if confidence.nan? confidence = nil @@ -818,23 +818,6 @@ module OpenTox return (array.to_scale.variance_sample == 0.0) end - # Median of an array - # @param [Array] Array with values - # @return [Float] Median - def self.median(array) - return nil if array.empty? - array.sort! - m_pos = array.size / 2 - return array.size % 2 == 1 ? array[m_pos] : (array[m_pos-1] + array[m_pos])/2 - end - - # Sum of an array for Numeric values - # @param [Array] Array with values - # @return [Integer] Sum of values - def self.sum(array) - array.inject{|s,x| s + x } - end - # Sum of an array for Arrays. # @param [Array] Array with values # @return [Integer] Sum of size of values @@ -860,7 +843,7 @@ module OpenTox max=0 max_value=0 nr_o = self.sum_size(occurrences) - nr_db = self.sum(db_instances) + nr_db = db_instances.to_scale.sum occurrences.each_with_index { |o,i| # fminer outputs occurrences sorted reverse by activity. actual = o.size.to_f/nr_o @@ -888,24 +871,6 @@ module OpenTox p_sum end - # Adds variance, mean and standard deviation calculation to Array class - module Variance - def sum(&blk) - map(&blk).inject { |sum, element| sum + element } - end - def mean - (sum.to_f / size.to_f) - end - def variance - m = mean - sum { |i| ( i - m )**2 } / (size-1).to_f - end - def std_dev - Math.sqrt(variance) - end - end - Array.send :include, Variance - end end diff --git a/lib/dataset.rb b/lib/dataset.rb index 1d4ad55..d7a8e47 100644 --- a/lib/dataset.rb +++ b/lib/dataset.rb @@ -233,8 +233,18 @@ module OpenTox # Get SDF representation of compounds # @return [String] SDF representation def to_sdf + sum="" + @compounds.each{ |c| + sum << OpenTox::Compound.new(c).to_inchi + sum << OpenTox::Compound.new(c).to_sdf + } + sum + end + + def to_urilist @compounds.inject { |sum, c| - sum + OpenTox::Compound.new(c).to_sdf + sum << OpenTox::Compound.new(c).uri + sum + "\n" } end |