summaryrefslogtreecommitdiff
path: root/lib/algorithm.rb
diff options
context:
space:
mode:
authorAndreas Maunz <andreas@maunz.de>2011-05-19 13:08:28 +0200
committerAndreas Maunz <andreas@maunz.de>2011-05-19 13:08:28 +0200
commite34c80eadcd40482a765cda861b92ab5c1250049 (patch)
tree446665797769c8a06fa8f9445b8a45df0131c1dc /lib/algorithm.rb
parentafefbdf05549c298387821c3a441d1de701291e0 (diff)
Added Exception handling
Diffstat (limited to 'lib/algorithm.rb')
-rw-r--r--lib/algorithm.rb17
1 files changed, 9 insertions, 8 deletions
diff --git a/lib/algorithm.rb b/lib/algorithm.rb
index 9402eab..5b41cbf 100644
--- a/lib/algorithm.rb
+++ b/lib/algorithm.rb
@@ -177,9 +177,13 @@ module OpenTox
end # activities of neighbors for supervised learning
sims = neighbors.collect{ |n| Algorithm.gauss(n[:similarity]) } # similarity values btwn q and nbors
- prediction = local_svm(neighbors, acts, sims, "nu-svr", params)
- prediction = (take_logs ? 10**(prediction.to_f) : prediction.to_f)
- LOGGER.debug "Prediction is: '" + prediction.to_s + "'."
+ begin
+ prediction = local_svm(neighbors, acts, sims, "nu-svr", params)
+ prediction = (take_logs ? 10**(prediction.to_f) : prediction.to_f)
+ LOGGER.debug "Prediction is: '" + prediction.to_s + "'."
+ rescue Exception => e
+ LOGGER.debug "#{e.class}: #{e.message} #{e.backtrace}"
+ end
conf = sims.inject{|sum,x| sum + x }
confidence = conf/neighbors.size if neighbors.size > 0
@@ -195,16 +199,13 @@ module OpenTox
acts = neighbors.collect do |n|
act = n[:activity]
end # activities of neighbors for supervised learning
-
- sims = neighbors.collect{ |n| Algorithm.gauss(n[:similarity]) } # similarity values btwn q and nbors
-
-
acts_f = acts.collect {|v| v == true ? 1.0 : 0.0}
+ sims = neighbors.collect{ |n| Algorithm.gauss(n[:similarity]) } # similarity values btwn q and nbors
begin
prediction = local_svm (neighbors, acts_f, sims, "C-bsvc", params)
LOGGER.debug "Prediction is: '" + prediction.to_s + "'."
rescue Exception => e
- LOGGER.debug "Prediction failed."
+ LOGGER.debug "#{e.class}: #{e.message} #{e.backtrace}"
end
conf = sims.inject{|sum,x| sum + x }