Class: OpenTox::Algorithm::Similarity

Inherits:
Object
  • Object
show all
Defined in:
lib/algorithm.rb

Class Method Summary collapse

Class Method Details

.euclidean(prop_a, prop_b) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/algorithm.rb', line 67

def self.euclidean(prop_a,prop_b)
  common_properties = prop_a.keys & prop_b.keys
  if common_properties.size > 1
    dist_sum = 0
    common_properties.each do |p|
      dist_sum += (prop_a[p] - prop_b[p])**2
    end
    1/(1+Math.sqrt(dist_sum))
  else
    nil
  end
end

.weighted_tanimoto(fp_a, fp_b, p) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/algorithm.rb', line 54

def self.weighted_tanimoto(fp_a,fp_b,p)
  common_features = fp_a & fp_b
  all_features = (fp_a + fp_b).uniq
  common_p_sum = 0.0
  if common_features.size > 0
    common_features.each{|f| common_p_sum += OpenTox::Utils.gauss(p[f])}
    all_p_sum = 0.0
    all_features.each{|f| all_p_sum += OpenTox::Utils.gauss(p[f])}
    common_p_sum/all_p_sum
  else
    0.0
  end
end