summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormguetlein <martin.guetlein@gmail.com>2010-06-07 14:09:43 +0200
committermguetlein <martin.guetlein@gmail.com>2010-06-07 14:09:43 +0200
commitfd6cccaecc235bfe334fd54b79f02e2083dc89a9 (patch)
tree188895a5ba743bfd321d914b399bf90124734057
parentedfa159a81f02f3bfbbd5108ff3494369133e072 (diff)
add regression plot, rescue not found errors, ..
-rw-r--r--application.rb9
-rw-r--r--lib/predictions.rb8
-rw-r--r--lib/validation_db.rb11
-rw-r--r--report/environment.rb2
-rw-r--r--report/plot_factory.rb18
-rw-r--r--report/report_factory.rb35
-rw-r--r--report/report_test.rb6
-rw-r--r--test/test_examples_util.rb1
-rw-r--r--validation/validation_application.rb57
-rw-r--r--validation/validation_format.rb2
-rw-r--r--validation/validation_test.rb9
11 files changed, 124 insertions, 34 deletions
diff --git a/application.rb b/application.rb
index 3b0dc71..236280c 100644
--- a/application.rb
+++ b/application.rb
@@ -4,15 +4,6 @@ gem 'opentox-ruby-api-wrapper', '= 1.4.4.4'
require lib
end
-require 'active_record'
-ActiveRecord::Base.establish_connection(
- :adapter => @@config[:database][:adapter],
- :host => @@config[:database][:host],
- :database => @@config[:database][:database],
- :username => @@config[:database][:username],
- :password => @@config[:database][:password]
-)
-
#unless(defined? LOGGER)
#LOGGER = Logger.new(STDOUT)
#LOGGER.datetime_format = "%Y-%m-%d %H:%M:%S "
diff --git a/lib/predictions.rb b/lib/predictions.rb
index c01dcdc..a183534 100644
--- a/lib/predictions.rb
+++ b/lib/predictions.rb
@@ -456,6 +456,10 @@ module Lib
def num_instances
return @predicted_values.size
end
+
+ def predicted_values
+ @predicted_values
+ end
def predicted_value(instance_index)
if @is_classification
@@ -465,6 +469,10 @@ module Lib
end
end
+ def actual_values
+ @actual_values
+ end
+
def actual_value(instance_index)
if @is_classification
@actual_values[instance_index]==nil ? nil : @prediction_feature_values[@actual_values[instance_index]]
diff --git a/lib/validation_db.rb b/lib/validation_db.rb
index 17e8f74..a3c9593 100644
--- a/lib/validation_db.rb
+++ b/lib/validation_db.rb
@@ -5,6 +5,15 @@ end
require "lib/merge.rb"
+require 'active_record'
+ActiveRecord::Base.establish_connection(
+ :adapter => @@config[:database][:adapter],
+ :host => @@config[:database][:host],
+ :database => @@config[:database][:database],
+ :username => @@config[:database][:username],
+ :password => @@config[:database][:password]
+)
+
module Lib
VAL_PROPS_GENERAL = [ :id, :uri, :model_uri, :algorithm_uri, :training_dataset_uri, :prediction_feature,
@@ -39,7 +48,7 @@ module Lib
VAL_REGR_PROPS = [ :root_mean_squared_error, :mean_absolute_error, :r_square, :target_variance_actual, :target_variance_predicted ]
CROSS_VAL_PROPS = [:dataset_uri, :num_folds, :stratified, :random_seed]
- CROSS_VAL_PROPS_REDUNDANT = [:algorithm_uri] + CROSS_VAL_PROPS
+ CROSS_VAL_PROPS_REDUNDANT = [:algorithm_uri, :created_at] + CROSS_VAL_PROPS
ALL_PROPS = VAL_PROPS + VAL_CV_PROPS + VAL_CLASS_PROPS_EXTENDED + VAL_REGR_PROPS + CROSS_VAL_PROPS
diff --git a/report/environment.rb b/report/environment.rb
index 2cb03a6..c64d40d 100644
--- a/report/environment.rb
+++ b/report/environment.rb
@@ -11,6 +11,8 @@ require 'fileutils'
require 'mime/types'
require 'ruby-plot'
+gem 'ruby-plot', '= 0.0.2'
+
module Reports
end
diff --git a/report/plot_factory.rb b/report/plot_factory.rb
index e1fefeb..daaba52 100644
--- a/report/plot_factory.rb
+++ b/report/plot_factory.rb
@@ -13,7 +13,23 @@ end
module Reports
- module PlotFactory
+ module PlotFactory
+
+ def self.create_regression_plot( out_file, validation_set )
+
+ LOGGER.debug "Creating regression plot, out-file:"+out_file.to_s
+
+ names = []
+ x = []
+ y = []
+ validation_set.validations.each do |v|
+ names << v.algorithm_uri
+ x << v.get_predictions.predicted_values
+ y << v.get_predictions.actual_values
+ end
+
+ RubyPlot::plot_points(out_file, "Regression plot", "Predicted values", "Actual values", names, x, y )
+ end
# creates a roc plot (result is plotted into out_file)
# * if (split_set_attributes == nil?)
diff --git a/report/report_factory.rb b/report/report_factory.rb
index dcc7b13..f62803d 100644
--- a/report/report_factory.rb
+++ b/report/report_factory.rb
@@ -61,6 +61,7 @@ module Reports::ReportFactory
report.add_section_confusion_matrix(val)
else #regression
report.add_section_result(validation_set, VAL_ATTR_TRAIN_TEST + VAL_ATTR_REGR, "Results", "Results")
+ report.add_section_regression_plot(validation_set)
end
report.add_section_result(validation_set, Lib::ALL_PROPS, "All Results", "All Results")
@@ -154,6 +155,7 @@ module Reports::ReportFactory
#regression
report.add_section_result(validation_set,[:algorithm_uri]+VAL_ATTR_REGR,"Results","Results")
report.add_section_bar_plot(validation_set,nil,:algorithm_uri,VAL_ATTR_BAR_PLOT_REGR, "bar-plot.svg")
+ report.add_section_regression_plot(validation_set)
#report.add_section_result(merged, VAL_ATTR_CV+VAL_ATTR_REGR-[:crossvalidation_fold],"Mean Results","Mean Results")
#report.add_section_result(validation_set, VAL_ATTR_CV+VAL_ATTR_REGR-[:num_folds], "Results","Results")
@@ -275,6 +277,39 @@ class Reports::ReportContent
@xml_report.add_table(section_confusion, table_title,
Reports::XMLReportUtil::create_confusion_matrix( validation.confusion_matrix ), false)
end
+
+ def add_section_regression_plot( validation_set,
+ split_set_attribute = nil,
+ plot_file_name="regression-plot.svg",
+ section_title="Regression Plot",
+ section_text=nil,
+ image_title=nil,
+ image_caption=nil)
+
+ section_text = "This section contains the regression plot." unless section_text
+ image_title = "Regression plot" unless image_title
+
+ section_regr = @xml_report.add_section(@xml_report.get_root_element, section_title)
+ prediction_set = validation_set.collect{ |v| v.get_predictions }
+
+ if prediction_set.size>0
+
+ section_text += "\nWARNING: regression plot information not available for all validation results" if prediction_set.size!=validation_set.size
+ @xml_report.add_paragraph(section_regr, section_text) if section_text
+ begin
+ plot_file_path = add_tmp_file(plot_file_name)
+ Reports::PlotFactory.create_regression_plot( plot_file_path, prediction_set )
+ @xml_report.add_imagefigure(section_regr, image_title, plot_file_name, "SVG", image_caption)
+ rescue RuntimeError => ex
+ LOGGER.error("Could not create regression plot: "+ex.message)
+ rm_tmp_file(plot_file_name)
+ @xml_report.add_paragraph(section_regr, "could not create regression plot: "+ex.message)
+ end
+ else
+ @xml_report.add_paragraph(section_regr, "No prediction info for regression available.")
+ end
+
+ end
def add_section_roc_plot( validation_set,
class_value = nil,
diff --git a/report/report_test.rb b/report/report_test.rb
index d580045..872bed0 100644
--- a/report/report_test.rb
+++ b/report/report_test.rb
@@ -38,13 +38,13 @@ class Reports::ApplicationTest < Test::Unit::TestCase
#post 'http://ot.validation.de/report/crossvalidation',:validation_uris=>"http://ot.validation.de/crossvalidation/1"
#uri = last_response.body.to_s
- val_uris = ["http://ot.validation.de/crossvalidation/32"] #,"http://ot.validation.de/crossvalidation/8" ]
+ val_uris = ["http://localhost/validation/64","http://localhost/validation/65" ]
- post 'http://ot.validation.de/report/crossvalidation',:validation_uris=>val_uris.join("\n")
+ post '/report/algorithm_comparison',:validation_uris=>val_uris.join("\n")
uri = wait_for_task(last_response.body.to_s)
puts uri
id = uri.squeeze("/").split("/")[-1]
- get '/report/crossvalidation/'+id,nil,'HTTP_ACCEPT' => "text/html"
+ get '/report/validation/'+id,nil,'HTTP_ACCEPT' => "text/html"
puts uri
#rep = Reports::ReportService.new("http://some.location")
diff --git a/test/test_examples_util.rb b/test/test_examples_util.rb
index 49e0336..7fcb1ec 100644
--- a/test/test_examples_util.rb
+++ b/test/test_examples_util.rb
@@ -114,6 +114,7 @@ module ValidationExamples
@validation_uri = Util.validation_post '/'+validation_type, get_params
rescue => ex
@validation_error = ex.message
+ LOGGER.error ex.message
end
end
diff --git a/validation/validation_application.rb b/validation/validation_application.rb
index 13dc26d..9abf2d4 100644
--- a/validation/validation_application.rb
+++ b/validation/validation_application.rb
@@ -23,7 +23,11 @@ end
get '/crossvalidation/:id' do
LOGGER.info "get crossvalidation with id "+params[:id].to_s
- halt 404, "Crossvalidation #{params[:id]} not found." unless crossvalidation = Validation::Crossvalidation.find(params[:id])
+ begin
+ crossvalidation = Validation::Crossvalidation.find(params[:id])
+ rescue ActiveRecord::RecordNotFound => ex
+ halt 404, "Crossvalidation '#{params[:id]}' not found."
+ end
case request.env['HTTP_ACCEPT'].to_s
when "application/rdf+xml"
@@ -41,28 +45,40 @@ end
delete '/crossvalidation/:id/?' do
LOGGER.info "delete crossvalidation with id "+params[:id].to_s
content_type "text/plain"
- halt 404, "Crossvalidation #{params[:id]} not found." unless crossvalidation = Validation::Crossvalidation.find(params[:id])
- crossvalidation.delete
+ begin
+ crossvalidation = Validation::Crossvalidation.find(params[:id])
+ rescue ActiveRecord::RecordNotFound => ex
+ halt 404, "Crossvalidation '#{params[:id]}' not found."
+ end
+ Validation::Crossvalidation.delete(params[:id])
end
get '/crossvalidation/:id/validations' do
LOGGER.info "get all validations for crossvalidation with id "+params[:id].to_s
- halt 404, "Crossvalidation #{params[:id]} not found." unless crossvalidation = Validation::Crossvalidation.find(params[:id])
+ begin
+ crossvalidation = Validation::Crossvalidation.find(params[:id])
+ rescue ActiveRecord::RecordNotFound => ex
+ halt 404, "Crossvalidation '#{params[:id]}' not found."
+ end
content_type "text/uri-list"
- Validation::Validation.all(:crossvalidation_id => params[:id]).collect{ |v| v.uri.to_s }.join("\n")+"\n"
+ Validation::Validation.find( :all, :conditions => { :crossvalidation_id => params[:id] } ).collect{ |v| v.uri.to_s }.join("\n")+"\n"
end
get '/crossvalidation/:id/statistics' do
LOGGER.info "get merged validation-result for crossvalidation with id "+params[:id].to_s
- halt 404, "Crossvalidation #{params[:id]} not found." unless crossvalidation = Validation::Crossvalidation.find(params[:id])
+ begin
+ crossvalidation = Validation::Crossvalidation.find(params[:id])
+ rescue ActiveRecord::RecordNotFound => ex
+ halt 404, "Crossvalidation '#{params[:id]}' not found."
+ end
Lib::MergeObjects.register_merge_attributes( Validation::Validation,
- Lib::VAL_MERGE_AVG,Lib::VAL_MERGE_SUM,Lib::VAL_MERGE_GENERAL) unless
+ Lib::VAL_MERGE_AVG,Lib::VAL_MERGE_SUM,Lib::VAL_MERGE_GENERAL-[:uri]) unless
Lib::MergeObjects.merge_attributes_registered?(Validation::Validation)
- v = Lib::MergeObjects.merge_array_objects( Validation::Validation.all(:crossvalidation_id => params[:id]) )
- v.uri = nil
+ v = Lib::MergeObjects.merge_array_objects( Validation::Validation.find( :all, :conditions => { :crossvalidation_id => params[:id] } ) )
+ v.validation_uri = nil
v.created_at = nil
v.id = nil
content_type "text/x-yaml"
@@ -104,8 +120,12 @@ end
get '/:id' do
LOGGER.info "get validation with id "+params[:id].to_s+" '"+request.env['HTTP_ACCEPT'].to_s+"'"
- halt 404, "Validation '#{params[:id]}' not found." unless validation = Validation::Validation.find(params[:id])
-
+ begin
+ validation = Validation::Validation.find(params[:id])
+ rescue ActiveRecord::RecordNotFound => ex
+ halt 404, "Validation '#{params[:id]}' not found."
+ end
+
case request.env['HTTP_ACCEPT'].to_s
when "application/rdf+xml"
content_type "application/rdf+xml"
@@ -195,10 +215,13 @@ post '/create_validation' do
halt 202,task_uri
end
-
get '/:id/:attribute' do
LOGGER.info "access validation attribute "+params.inspect
- halt 404, "Validation #{params[:id]} not found." unless validation = Validation::Validation.find(params[:id])
+ begin
+ validation = Validation::Validation.find(params[:id])
+ rescue ActiveRecord::RecordNotFound => ex
+ halt 404, "Validation '#{params[:id]}' not found."
+ end
begin
raise unless validation.attribute_loaded?(params[:attribute])
rescue
@@ -210,7 +233,11 @@ end
delete '/:id' do
LOGGER.info "delete validation with id "+params[:id].to_s
- halt 404, "Validation #{params[:id]} not found." unless validation = Validation::Validation.find(params[:id])
+ begin
+ validation = Validation::Validation.find(params[:id])
+ rescue ActiveRecord::RecordNotFound => ex
+ halt 404, "Validation '#{params[:id]}' not found."
+ end
content_type "text/plain"
- validation.delete
+ Validation::Validation.delete(params[:id])
end \ No newline at end of file
diff --git a/validation/validation_format.rb b/validation/validation_format.rb
index 357d96e..97d9eed 100644
--- a/validation/validation_format.rb
+++ b/validation/validation_format.rb
@@ -37,7 +37,7 @@ module Validation
h[:crossvalidation_info] = cv
end
if classification_statistics
- class_stats = YAML.load(classification_statistics.to_s)
+ class_stats = ((classification_statistics.is_a?(Hash)) ? classification_statistics : YAML.load(classification_statistics.to_s))
clazz = {}
Lib::VAL_CLASS_PROPS_SINGLE.each{ |p| clazz[p] = class_stats[p] }
diff --git a/validation/validation_test.rb b/validation/validation_test.rb
index 1e3908a..3fa3056 100644
--- a/validation/validation_test.rb
+++ b/validation/validation_test.rb
@@ -17,13 +17,13 @@ class ValidationTest < Test::Unit::TestCase
def test_it
$test_case = self
- #get "/1"
- #puts last_response.body
+ # get "/crossvalidation/1/statistics"
+ # puts last_response.body
# post "/test_validation",:select=>"6d" #,:report=>"yes,please"
# puts last_response.body
- run_test("2b")
+ run_test("3a")
#puts Nightly.build_nightly("1", false)
@@ -38,11 +38,12 @@ class ValidationTest < Test::Unit::TestCase
def run_test(select)
validationExamples = ValidationExamples.select(select)
validationExamples.each do |vv|
- vv.each do |v|
+ vv.each do |v|
ex = v.new
ex.upload_files
ex.check_requirements
ex.validate
+ LOGGER.debug "validation done "+ex.validation_uri.to_s
ex.report
end
end