From baffedfc7543cfc8a90fc185fc91f2748ce94528 Mon Sep 17 00:00:00 2001 From: Andreas Maunz Date: Wed, 25 May 2011 10:24:13 +0200 Subject: Fixed add_neighbor --- lib/model.rb | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'lib/model.rb') diff --git a/lib/model.rb b/lib/model.rb index f5e0410..3d27706 100644 --- a/lib/model.rb +++ b/lib/model.rb @@ -338,28 +338,45 @@ module OpenTox @prediction_dataset end + # Calculate the propositionalization matrix aka instantiation matrix (0/1 entries for features) +# def get_prop_matrix +# matrix = Array.new +# begin +# @neighbors.each do |n| +# row = [] +# @features.each do |f| +# row << @fingerprints[n].include?(f) ? 0.0 : @p_values[f] +# end +# matrix << row +# end +# rescue Exception => e +# LOGGER.debug "get_prop_matrix failed with '" + $! + "'" +# end +# matrix +# end + # Find neighbors and store them as object variable, access only a subset of compounds for that. def neighbors_balanced(s, l, start, offset) @compound_features = eval("#{@feature_calculation_algorithm}(@compound,@features)") if @feature_calculation_algorithm @neighbors = [] [ l[start, offset ] , s ].flatten.each do |training_compound| # AM: access only a balanced subset training_features = @fingerprints[training_compound] - add_neighbor training_features + add_neighbor training_features, training_compound end end - # Find neighbors and store them as object variable. + # Find neighbors and store them as object variable, access all compounds for that. def neighbors @compound_features = eval("#{@feature_calculation_algorithm}(@compound,@features)") if @feature_calculation_algorithm @neighbors = [] @fingerprints.each do |training_compound,training_features| # AM: access all compounds - add_neighbor training_features + add_neighbor training_features, training_compound end end # Adds a neighbor to @neighbors if it passes the similarity threshold. - def add_neighbor(training_features) + def add_neighbor(training_features, training_compound) sim = eval("#{@similarity_algorithm}(@compound_features,training_features,@p_values)") if sim > @min_sim @activities[training_compound].each do |act| -- cgit v1.2.3