diff options
author | Christoph Helma <helma@in-silico.ch> | 2016-05-24 15:41:24 +0200 |
---|---|---|
committer | Christoph Helma <helma@in-silico.ch> | 2016-05-24 15:41:24 +0200 |
commit | cc08e6beda7f7d70ebf6c6929a22d1a0cd7c1a20 (patch) | |
tree | cc1c37d5623a72787e0d74b000692ff380bd45f5 /lib | |
parent | b2d80ad2e470fcb41af4b747142e5693f2fa4615 (diff) |
tests fixed. DescriptorTest#test_compound_all may fail within all.rb
Diffstat (limited to 'lib')
-rw-r--r-- | lib/dataset.rb | 5 | ||||
-rw-r--r-- | lib/model.rb | 9 | ||||
-rw-r--r-- | lib/validation-statistics.rb | 9 |
3 files changed, 15 insertions, 8 deletions
diff --git a/lib/dataset.rb b/lib/dataset.rb index 38a55a8..9138452 100644 --- a/lib/dataset.rb +++ b/lib/dataset.rb @@ -229,6 +229,11 @@ module OpenTox save end + def delete + compounds.each{|c| c.dataset_ids.delete id.to_s} + super + end + end # Dataset for lazar predictions diff --git a/lib/model.rb b/lib/model.rb index 8baed41..3a178a1 100644 --- a/lib/model.rb +++ b/lib/model.rb @@ -69,6 +69,7 @@ module OpenTox end def predict_substance substance + neighbor_algorithm_parameters = Hash[self.neighbor_algorithm_parameters.map{ |k, v| [k.to_sym, v] }] # convert string keys to symbols neighbors = substance.send(neighbor_algorithm, neighbor_algorithm_parameters) database_activities = nil prediction = {} @@ -82,22 +83,22 @@ module OpenTox neighbors.delete_if{|n| n["_id"] == substance.id} # remove query substance for an unbiased prediction (also useful for loo validation) end if neighbors.empty? - prediction.merge!({:value => nil,:confidence => nil,:warning => "Could not find similar substances with experimental data in the training dataset.",:neighbors => []}) + prediction.merge!({:value => nil,:probabilities => nil,:warning => "Could not find similar substances with experimental data in the training dataset.",:neighbors => []}) elsif neighbors.size == 1 value = nil tox = neighbors.first["toxicities"] if tox.size == 1 # single measurement - value = tox + value = tox.first else # multiple measurement if tox.collect{|t| t.numeric?}.uniq == [true] # numeric value = tox.median elsif tox.uniq.size == 1 # single value value = tox.first else # contradictory results - # TODO add majority vote + # TODO add majority vote?? end end - prediction.merge!({:value => value, :confidence => nil, :warning => "Only one similar compound in the training set. Predicting median of its experimental values."}) if value + prediction.merge!({:value => value, :probabilities => nil, :warning => "Only one similar compound in the training set. Predicting median of its experimental values.", :neighbors => neighbors}) if value else # call prediction algorithm klass,method = prediction_algorithm.split('.') diff --git a/lib/validation-statistics.rb b/lib/validation-statistics.rb index 3c52b15..156353a 100644 --- a/lib/validation-statistics.rb +++ b/lib/validation-statistics.rb @@ -8,10 +8,11 @@ module OpenTox predictivity = {} nr_instances = 0 predictions.each do |cid,pred| - # TODO use measured majority class - if pred[:measured].uniq.size == 1 + # TODO + # use predictions without probabilities (single neighbor)?? + # use measured majority class?? + if pred[:measured].uniq.size == 1 and pred[:probabilities] m = pred[:measured].first - #pred[:measured].each do |m| if pred[:value] == m if pred[:value] == accept_values[0] confusion_matrix[0][0] += 1 @@ -63,12 +64,12 @@ module OpenTox end def self.regression predictions + # TODO: predictions within prediction_interval rmse = 0 mae = 0 x = [] y = [] predictions.each do |cid,pred| - p pred if pred[:value] and pred[:measured] x << pred[:measured].median y << pred[:value] |