summaryrefslogtreecommitdiff
path: root/lib/ot_predictions.rb
diff options
context:
space:
mode:
authorMartin Gütlein <martin.guetlein@gmail.com>2010-03-25 20:04:39 +0100
committerMartin Gütlein <martin.guetlein@gmail.com>2010-03-25 20:04:39 +0100
commit675980f769955698209ac723eaa4d34eba9c3204 (patch)
treea0cf1ef3b5b1adbe5b54a5cfb4f5798f18bf5a0c /lib/ot_predictions.rb
parent14d2a68564061d63166cd409bf4fd30dc841d2b8 (diff)
adjust to new ruby api wrapper version
Diffstat (limited to 'lib/ot_predictions.rb')
-rw-r--r--lib/ot_predictions.rb88
1 files changed, 35 insertions, 53 deletions
diff --git a/lib/ot_predictions.rb b/lib/ot_predictions.rb
index 2098ab1..d81bd29 100644
--- a/lib/ot_predictions.rb
+++ b/lib/ot_predictions.rb
@@ -5,6 +5,8 @@ module Lib
class OTPredictions < Predictions
+ CHECK_VALUES = ENV['RACK_ENV']=="test"
+
def identifier(instance_index)
return compound(instance_index)
end
@@ -26,26 +28,31 @@ module Lib
prediction_dataset = OpenTox::Dataset.find prediction_dataset_uri
raise "test dataset not found: '"+test_dataset_uri.to_s+"'" unless test_dataset
raise "prediction dataset not found: '"+prediction_dataset_uri.to_s+"'" unless prediction_dataset
+ raise "test dataset feature not found: '"+prediction_feature+"', available features: "+test_dataset.features.inspect if test_dataset.features.index(prediction_feature)==nil
+ raise "prediction dataset feature not found: '"+predicted_variable+"', available features: "+prediction_dataset.features.inspect if prediction_dataset.features.index(predicted_variable)==nil
+
+ class_values = OpenTox::Feature.domain(prediction_feature)
+
+ @compounds = test_dataset.compounds
+ raise "test dataset is empty" unless @compounds.size>0
+ raise "more predicted than test compounds test:"+@compounds.size.to_s+" < prediction:"+
+ prediction_dataset.compounds.size.to_s if @compounds.size < prediction_dataset.compounds.size
- class_values = OpenTox::Feature.range(prediction_feature)
+ if CHECK_VALUES
+ prediction_dataset.compounds.each do |c|
+ raise "predicted compound not found in test dataset" if @compounds.index(c)==nil
+ end
+ end
actual_values = []
- @compounds = []
- test_dataset.data.each do |compound,featuresValues|
+ @compounds.each do |c|
- @compounds.push compound
- #@compounds << (OpenTox::Compound.new :uri=>compound.to_s).smiles
-
- value = nil
- LOGGER.warn "value is hash, but no feature value '"+prediction_feature.to_s+
- "', hash: '"+featuresValues.inspect+"'" if featuresValues.is_a?(Hash) and !featuresValues.has_key?(prediction_feature)
- value = featuresValues[prediction_feature] if featuresValues.is_a?(Hash)
- value = value[0] if value.is_a?(Array) and value.length == 1
- value = nil if value.to_s.size==0 # PENDING: hack to avoid illegal boolean values
+ value = test_dataset.get_value(c, prediction_feature)
if is_classification
value = value.to_s unless value==nil
- raise "illegal class_value of actual value "+value.to_s+" class: "+value.class.to_s unless value==nil or class_values.index(value)!=nil
+ raise "illegal class_value of actual value "+value.to_s+" class: "+
+ value.class.to_s unless value==nil or class_values.index(value)!=nil
actual_values.push class_values.index(value)
else
begin
@@ -58,50 +65,25 @@ module Lib
end
end
- raise "test dataset is empty" unless @compounds.size>0
-
- predicted_values = Array.new(actual_values.size)
- confidence_values = Array.new(actual_values.size)
-
- prediction_dataset.data.each do |compound,featuresValues|
-
- index = @compounds.index(compound)
- raise "compound "+compound.to_s+" not found in\n"+@compounds.inspect if index==nil
-
- value = nil
- LOGGER.warn "value is hash, but no feature value '"+predicted_variable.to_s+
- "', hash: '"+featuresValues.inspect+"'" if featuresValues.is_a?(Hash) and !featuresValues.has_key?(predicted_variable)
- value = featuresValues[predicted_variable] if featuresValues.is_a?(Hash)
- value = value[0] if value.is_a?(Array) and value.length == 1
- value = nil if value.to_s.size==0
-
- if is_classification
-
- ### PENDING ####
- confidence = nil
- if value.is_a?(Hash)
- confidence = value["confidence"].to_f.abs if value.has_key?("confidence")
- value = value["classification"].to_s if value.has_key?("classification")
- else
- value = value.to_s unless value==nil # PENDING: hack to avoid illegal boolean values
- end
- ################
-
- raise "illegal class_value of predicted value "+value.to_s+" class: "+value.class.to_s unless value==nil or class_values.index(value)!=nil
- predicted_values[index] = class_values.index(value)
- confidence_values[index] = confidence if confidence!=nil
+ predicted_values = []
+ confidence_values = []
+ @compounds.each do |c|
+ if prediction_dataset.compounds.index(c)==nil
+ predicted_values << nil
+ confidence_values << nil
else
- begin
- value = value.to_f unless value==nil or value.is_a?(Numeric)
- rescue
- LOGGER.warn "no numeric value for regression: '"+value.to_s+"'"
- value = nil
+ if is_classification
+ value = prediction_dataset.get_predicted_class(c, predicted_variable)
+ value = value.to_s unless value==nil
+ raise "illegal class_value of predicted value "+value.to_s+" class: "+value.class.to_s unless value==nil or class_values.index(value)!=nil
+ predicted_values << class_values.index(value)
+ confidence_values << prediction_dataset.get_prediction_confidence(c, predicted_variable)
+ else
+ raise "TODO regression"
end
- predicted_values[index] = value
end
- index += 1
end
-
+
super(predicted_values, actual_values, confidence_values, is_classification, class_values)
raise "illegal num compounds "+num_info if @compounds.size != @predicted_values.size
end