summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Maunz <andreas@maunz.de>2011-06-21 14:42:07 +0200
committerAndreas Maunz <andreas@maunz.de>2011-06-21 14:42:07 +0200
commit8f938837b503db179bcb03beb12421975501420c (patch)
treecca9abfd99ed3eef38f60c6ea14e4282aa7ceb32
parentff5aa4a57aa3fa0a77609933f5c23d8bdcaf6430 (diff)
WMV turned multinomial
-rw-r--r--lib/algorithm.rb30
-rw-r--r--lib/model.rb15
2 files changed, 25 insertions, 20 deletions
diff --git a/lib/algorithm.rb b/lib/algorithm.rb
index 7c1c7a2..bc17087 100644
--- a/lib/algorithm.rb
+++ b/lib/algorithm.rb
@@ -143,21 +143,25 @@ module OpenTox
conf = 0.0
confidence = 0.0
neighbors.each do |neighbor|
- case neighbor[:activity].to_s
- when 'true'
- conf += Algorithm.gauss(neighbor[:similarity])
- when 'false'
- conf -= Algorithm.gauss(neighbor[:similarity])
- end
- end
- if conf > 0.0
- prediction = true
- elsif conf < 0.0
- prediction = false
- else
- prediction = nil
+ conf += neighbor[:activity].to_f * Algorithm.gauss(neighbor[:similarity]).to_f
+ #case neighbor[:activity].to_s
+ #when 'true'
+ # conf += Algorithm.gauss(neighbor[:similarity])
+ #when 'false'
+ # conf -= Algorithm.gauss(neighbor[:similarity])
+ #end
end
confidence = conf/neighbors.size if neighbors.size > 0
+ prediction = confidence.round
+ {:prediction => prediction, :confidence => confidence}
+ #if conf > 0.0
+ # prediction = true
+ #elsif conf < 0.0
+ # prediction = false
+ #else
+ # prediction = nil
+ #end
+ #confidence = conf/neighbors.size if neighbors.size > 0
{:prediction => prediction, :confidence => confidence.abs}
end
diff --git a/lib/model.rb b/lib/model.rb
index 02fabfa..41d9335 100644
--- a/lib/model.rb
+++ b/lib/model.rb
@@ -91,7 +91,7 @@ module OpenTox
include Model
include Algorithm
- attr_accessor :compound, :prediction_dataset, :features, :effects, :activities, :p_values, :fingerprints, :feature_calculation_algorithm, :similarity_algorithm, :prediction_algorithm, :min_sim, :subjectid, :prop_kernel, :value_map
+ attr_accessor :compound, :prediction_dataset, :features, :effects, :activities, :p_values, :fingerprints, :feature_calculation_algorithm, :similarity_algorithm, :prediction_algorithm, :min_sim, :subjectid, :prop_kernel, :value_map, :balanced
def initialize(uri=nil)
@@ -116,6 +116,7 @@ module OpenTox
@min_sim = 0.3
@prop_kernel = false
+ @balanced = false
end
@@ -200,8 +201,8 @@ module OpenTox
return @prediction_dataset if database_activity(subjectid)
load_metadata(subjectid)
- case OpenTox::Feature.find(metadata[OT.dependentVariables]).feature_type
- when "classification"
+ if @balanced && OpenTox::Feature.find(metadata[OT.dependentVariables]).feature_type == "classification"
+
# AM: Balancing, see http://www.maunz.de/wordpress/opentox/2011/balanced-lazar
l = Array.new # larger
s = Array.new # smaller fraction
@@ -211,12 +212,12 @@ module OpenTox
@fingerprints.each do |training_compound,training_features|
@activities[training_compound].each do |act|
case act.to_s
- when "false"
+ when "0"
l << training_compound
- when "true"
+ when "1"
s << training_compound
else
- LOGGER.warn "BLAZAR: Activity #{act.to_s} should not be reached."
+ LOGGER.warn "BLAZAR: Activity #{act.to_s} should not be reached (supports only two classes)."
end
end
end
@@ -262,7 +263,7 @@ module OpenTox
@neighbors=neighbors_best
### END AM balanced predictions
- else # AM: no balancing
+ else # AM: no balancing or regression
LOGGER.info "LAZAR: Unbalanced."
neighbors
if @prop_kernel && @prediction_algorithm.include?("svm")