summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavor <vorgrimmlerdavid@gmx.de>2011-12-28 15:18:33 +0100
committerdavor <vorgrimmlerdavid@gmx.de>2011-12-28 15:18:33 +0100
commit3139a8865f7dfcaab974d43c877eee63f5a8a4a6 (patch)
tree7b6431a70af86220d92645f04044d6e49c211cf1
parent1a8b70dcd4aab3173c524b5cc4a14d976cf99d7a (diff)
Cleaned Weighted Majority Vote
-rw-r--r--lib/algorithm.rb19
-rw-r--r--lib/model.rb9
2 files changed, 18 insertions, 10 deletions
diff --git a/lib/algorithm.rb b/lib/algorithm.rb
index 529cffb..a355647 100644
--- a/lib/algorithm.rb
+++ b/lib/algorithm.rb
@@ -622,12 +622,13 @@ module OpenTox
confidence = 0.0
prediction = nil
- params[:neighbors].each do |neighbor|
- neighbor_weight = neighbor[:similarity].to_f
- neighbor_contribution += neighbor[:activity].to_f * neighbor_weight
+ LOGGER.debug "Weighted Majority Vote Classification."
+ params[:acts].each_index do |idx|
+ neighbor_weight = params[:sims][1][idx]
+ neighbor_contribution += params[:acts][idx] * neighbor_weight
if params[:value_map].size == 2 # AM: provide compat to binary classification: 1=>false 2=>true
- case neighbor[:activity]
+ case params[:acts][idx]
when 1
confidence_sum -= neighbor_weight
when 2
@@ -640,19 +641,21 @@ module OpenTox
if params[:value_map].size == 2
if confidence_sum >= 0.0
- prediction = 2 unless params[:neighbors].size==0
+ prediction = 2 unless params[:acts].size==0
elsif confidence_sum < 0.0
- prediction = 1 unless params[:neighbors].size==0
+ prediction = 1 unless params[:acts].size==0
end
else
- prediction = (neighbor_contribution/confidence_sum).round unless params[:neighbors].size==0 # AM: new multinomial prediction
+ prediction = (neighbor_contribution/confidence_sum).round unless params[:acts].size==0 # AM: new multinomial prediction
end
LOGGER.debug "Prediction is: '" + prediction.to_s + "'." unless prediction.nil?
- confidence = confidence_sum/params[:neighbors].size if params[:neighbors].size > 0
+ confidence = confidence_sum/params[:acts].size if params[:acts].size > 0
LOGGER.debug "Confidence is: '" + confidence.to_s + "'." unless prediction.nil?
return {:prediction => prediction, :confidence => confidence.abs}
end
+
+
# Local support vector regression from neighbors
# @param [Hash] params Keys `:neighbors,:compound,:features,:p_values,:similarity_algorithm,:prop_kernel,:value_map` are required
# @return [Numeric] A prediction value.
diff --git a/lib/model.rb b/lib/model.rb
index 191f732..1aa9cf7 100644
--- a/lib/model.rb
+++ b/lib/model.rb
@@ -266,9 +266,14 @@ module OpenTox
neighbors
prediction_fingerprints = @fingerprints.merge({@compound.uri => @compound_fingerprints})
+
+ # props
props = OpenTox::Algorithm::Neighbors.get_props_fingerprints({:neighbors => @neighbors, :features => @features, :fingerprints => prediction_fingerprints, :compound => @compound})
+
+ # acts
acts = @neighbors.collect { |n| n[:activity] }
+ # sims
gram_matrix = []
@neighbors.each_index do |i|
gram_matrix[i] = [] unless gram_matrix[i]
@@ -287,12 +292,12 @@ module OpenTox
end
sims = [ gram_matrix, @neighbors.collect { |n| n[:similarity] } ]
+ # prediction
prediction = eval("#{@prediction_algorithm} ( { :props => props,
:acts => acts,
:sims => sims,
- :p_values => @p_values,
- :similarity_algorithm => @similarity_algorithm,
:prop_kernel => @prop_kernel,
+ :value_map => @value_map,
:conf_stdev => @conf_stdev
} ) ")