diff options
author | Christoph Helma <helma@in-silico.ch> | 2016-03-14 15:25:50 +0100 |
---|---|---|
committer | Christoph Helma <helma@in-silico.ch> | 2016-03-14 15:25:50 +0100 |
commit | 0c5d2e678908a2d4aea43efbedbedc2c0439be30 (patch) | |
tree | 2a056c6edc088a37b7e489de435706af79f324e7 /lib/similarity.rb | |
parent | 989f20ae58c3ecb0ce62bc4468c3dab2599637b3 (diff) |
descriptor tests
Diffstat (limited to 'lib/similarity.rb')
-rw-r--r-- | lib/similarity.rb | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/lib/similarity.rb b/lib/similarity.rb deleted file mode 100644 index 91e18db..0000000 --- a/lib/similarity.rb +++ /dev/null @@ -1,58 +0,0 @@ -=begin -* Name: similarity.rb -* Description: Similarity algorithms -* Author: Andreas Maunz <andreas@maunz.de -* Date: 10/2012 -=end - -module OpenTox - module Algorithm - - class Similarity - - #TODO weighted tanimoto - - # Tanimoto similarity - # @param [Array] a fingerprints of first compound - # @param [Array] b fingerprints of second compound - # @return [Float] Tanimoto similarity - def self.tanimoto(a,b) - bad_request_error "fingerprints #{a} and #{b} don't have equal size" unless a.size == b.size - #common = 0.0 - #a.each_with_index do |n,i| - #common += 1 if n == b[i] - #end - #common/a.size - # TODO check if calculation speed can be improved - common_p_sum = 0.0 - all_p_sum = 0.0 - (0...a.size).each { |idx| - common_p_sum += [ a[idx], b[idx] ].min - all_p_sum += [ a[idx], b[idx] ].max - } - common_p_sum/all_p_sum - end - - - # Cosine similarity - # @param [Array] a fingerprints of first compound - # @param [Array] b fingerprints of second compound - # @return [Float] Cosine similarity, the cosine of angle enclosed between vectors a and b - def self.cosine(a, b) - val = 0.0 - if a.size>0 and b.size>0 - if a.size>12 && b.size>12 - a = a[0..11] - b = b[0..11] - end - a_vec = a.to_gv - b_vec = b.to_gv - val = a_vec.dot(b_vec) / (a_vec.norm * b_vec.norm) - end - val - end - - end - - end -end |