summaryrefslogtreecommitdiff
path: root/lib/model.rb
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.ch>2016-05-24 15:41:24 +0200
committerChristoph Helma <helma@in-silico.ch>2016-05-24 15:41:24 +0200
commitcc08e6beda7f7d70ebf6c6929a22d1a0cd7c1a20 (patch)
treecc1c37d5623a72787e0d74b000692ff380bd45f5 /lib/model.rb
parentb2d80ad2e470fcb41af4b747142e5693f2fa4615 (diff)
tests fixed. DescriptorTest#test_compound_all may fail within all.rb
Diffstat (limited to 'lib/model.rb')
-rw-r--r--lib/model.rb9
1 files changed, 5 insertions, 4 deletions
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('.')