summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Gütlein <martin.guetlein@gmail.com>2010-03-30 16:49:46 +0200
committerMartin Gütlein <martin.guetlein@gmail.com>2010-03-30 16:49:46 +0200
commit1a9419d158ede2535ae10b84d044da6a2cf89cfa (patch)
tree885b03c9018e78d61bf497bda8addc925d2857ae
parentae0b071c42c37ea974aa234f30a3a8cb77aa7eb3 (diff)
mostly munich changes
-rwxr-xr-xbin/redirect.sh17
-rw-r--r--example.rb5
-rw-r--r--lib/ot_predictions.rb35
-rw-r--r--lib/validation_db.rb7
-rw-r--r--report/plot_factory.rb11
-rw-r--r--report/report_application.rb2
-rw-r--r--report/report_factory.rb20
-rw-r--r--report/report_service.rb2
-rw-r--r--report/report_test.rb16
-rw-r--r--report/util.rb18
-rw-r--r--report/xml_report.rb367
-rw-r--r--report/xml_report_util.rb7
-rw-r--r--validation/validation_application.rb31
-rw-r--r--validation/validation_format.rb2
-rw-r--r--validation/validation_service.rb41
-rw-r--r--validation/validation_test.rb207
16 files changed, 506 insertions, 282 deletions
diff --git a/bin/redirect.sh b/bin/redirect.sh
index d309f1a..405a84d 100755
--- a/bin/redirect.sh
+++ b/bin/redirect.sh
@@ -1,18 +1,27 @@
#!/bin/bash
-OUTFILE="/tmp/tmp_redirect_out"
+OUTFILE="/tmp/tmp_redirect_out.txt"
cmd="curl -v $1"
`$cmd &> $OUTFILE`
-RES=`grep "< HTTP.*303" $OUTFILE`
+ERR=`grep -a "< HTTP.*5[0-9][0-9]" $OUTFILE`
+ERR=${ERR// /} # remove emtpy spaces
+
+if [ -z $ERR ]; then
+ ERR="no error"
+else
+ echo "ERROR" 1>&2
+ exit 1
+fi
+
+RES=`grep -a "< HTTP.*30[0-9]" $OUTFILE`
RES=${RES// /} # remove emtpy spaces
#echo $RES
if [ -z $RES ]; then
- #echo "no"
- echo ""
+ exit 0
else
#cat $OUTFILE
RES=`grep "< Location: " $OUTFILE`
diff --git a/example.rb b/example.rb
index 7e78db4..a9eb1e6 100644
--- a/example.rb
+++ b/example.rb
@@ -66,8 +66,9 @@ class Example
split_params = Validation::Util.train_test_dataset_split(data_uri, 0.9, 1)
v = Validation::Validation.new :training_dataset_uri => split_params[:training_dataset_uri],
:test_dataset_uri => split_params[:test_dataset_uri],
- :prediction_feature => URI.decode(@@feature)
- v.validate_algorithm( @@alg, @@alg_params )
+ :prediction_feature => URI.decode(@@feature),
+ :algorithm_uri => @@alg
+ v.validate_algorithm( @@alg_params )
log "crossvalidation"
Lib::Crossvalidation.auto_migrate!
diff --git a/lib/ot_predictions.rb b/lib/ot_predictions.rb
index 6e9c7a2..9e6f5c9 100644
--- a/lib/ot_predictions.rb
+++ b/lib/ot_predictions.rb
@@ -22,29 +22,21 @@ module Lib
"', prediction_feature: '"+prediction_feature.to_s+"' "+
"', predicted_variable: '"+predicted_variable.to_s+"'")
+ if prediction_feature =~ /ambit.uni-plovdiv.bg.*feature.*264185/
+ LOGGER.warn "HACK for report example"
+ prediction_feature = "http://ambit.uni-plovdiv.bg:8080/ambit2/feature/264187"
+ end
+
predicted_variable=prediction_feature if predicted_variable==nil
test_dataset = OpenTox::Dataset.find test_dataset_uri
- 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)
+ raise "test dataset feature not found: '"+prediction_feature.to_s+"', available features: "+test_dataset.features.inspect if test_dataset.features.index(prediction_feature)==nil
@compounds = test_dataset.compounds
LOGGER.debug "test dataset size: "+@compounds.size.to_s
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
-
- if CHECK_VALUES
- prediction_dataset.compounds.each do |c|
- raise "predicted compound not found in test dataset:\n"+c+"\ntest-compounds:\n"+
- @compounds.collect{|c| c.to_s}.join("\n") if @compounds.index(c)==nil
- end
- end
+ class_values = OpenTox::Feature.domain(prediction_feature)
actual_values = []
@compounds.each do |c|
@@ -67,6 +59,19 @@ module Lib
end
end
+ prediction_dataset = OpenTox::Dataset.find prediction_dataset_uri
+ raise "prediction dataset not found: '"+prediction_dataset_uri.to_s+"'" unless prediction_dataset
+ raise "prediction dataset feature not found: '"+predicted_variable+"', available features: "+prediction_dataset.features.inspect if prediction_dataset.features.index(predicted_variable)==nil
+
+ 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
+ if CHECK_VALUES
+ prediction_dataset.compounds.each do |c|
+ raise "predicted compound not found in test dataset:\n"+c+"\ntest-compounds:\n"+
+ @compounds.collect{|c| c.to_s}.join("\n") if @compounds.index(c)==nil
+ end
+ end
+
predicted_values = []
confidence_values = []
@compounds.each do |c|
diff --git a/lib/validation_db.rb b/lib/validation_db.rb
index e99c11e..cb6708c 100644
--- a/lib/validation_db.rb
+++ b/lib/validation_db.rb
@@ -7,7 +7,7 @@ require "lib/merge.rb"
module Lib
- VAL_PROPS_GENERAL = [ :id, :uri, :model_uri, :training_dataset_uri, :prediction_feature,
+ VAL_PROPS_GENERAL = [ :id, :uri, :model_uri, :algorithm_uri, :training_dataset_uri, :prediction_feature,
:test_dataset_uri, :prediction_dataset_uri, :created_at ]
VAL_PROPS_SUM = [ :num_instances, :num_without_class, :num_unpredicted ]
VAL_PROPS_AVG = [:real_runtime, :percent_without_class, :percent_unpredicted ]
@@ -37,7 +37,9 @@ module Lib
# :regression_statistics
VAL_REGR_PROPS = [ :root_mean_squared_error, :mean_absolute_error, :r_square, :target_variance_actual, :target_variance_predicted ]
- CROSS_VAL_PROPS = [:algorithm_uri, :dataset_uri, :num_folds, :stratified, :random_seed]
+
+ CROSS_VAL_PROPS = [:dataset_uri, :num_folds, :stratified, :random_seed]
+ CROSS_VAL_PROPS_REDUNDANT = [:algorithm_uri] + CROSS_VAL_PROPS
ALL_PROPS = VAL_PROPS + VAL_CV_PROPS + VAL_CLASS_PROPS_EXTENDED + VAL_REGR_PROPS + CROSS_VAL_PROPS
@@ -51,6 +53,7 @@ module Lib
property :id, Serial
property :uri, String, :length => 255
property :model_uri, String, :length => 255
+ property :algorithm_uri, String, :length => 255
property :training_dataset_uri, String, :length => 255
property :test_dataset_uri, String, :length => 255
property :prediction_dataset_uri, String, :length => 255
diff --git a/report/plot_factory.rb b/report/plot_factory.rb
index 4226b02..e248540 100644
--- a/report/plot_factory.rb
+++ b/report/plot_factory.rb
@@ -51,6 +51,8 @@ module Reports
LOGGER.debug "creating bar plot, out-file:"+out_file.to_s
data = []
+ titles = []
+
validation_set.validations.each do |v|
values = []
value_attributes.each do |a|
@@ -68,7 +70,13 @@ module Reports
values.push(value)
end
- data << [v.send(title_attribute).to_s] + values
+ titles << v.send(title_attribute).to_s
+ data << values
+ end
+
+ titles = titles.remove_common_prefix
+ (0..titles.size-1).each do |i|
+ data[i] = [titles[i]] + data[i]
end
labels = value_attributes.collect{|a| a.to_s.gsub("_","-")}
@@ -77,7 +85,6 @@ module Reports
LOGGER.debug "bar plot data: "+data.inspect
RubyPlot::plot_bars('Bar plot', labels, data, out_file)
-
end
diff --git a/report/report_application.rb b/report/report_application.rb
index 629b411..8c66acc 100644
--- a/report/report_application.rb
+++ b/report/report_application.rb
@@ -83,6 +83,6 @@ end
post '/report/:type' do
perform do |rs|
content_type "text/uri-list"
- rs.create_report(params[:type],params[:validation_uris]?params[:validation_uris].split("\n"):nil)
+ rs.create_report(params[:type],params[:validation_uris]?params[:validation_uris].split(/\n|,/):nil)
end
end
diff --git a/report/report_factory.rb b/report/report_factory.rb
index 52c0642..3cc4dfe 100644
--- a/report/report_factory.rb
+++ b/report/report_factory.rb
@@ -5,9 +5,10 @@ VAL_ATTR_TRAIN_TEST = [ :model_uri, :training_dataset_uri, :test_dataset_uri, :p
VAL_ATTR_CV = [ :algorithm_uri, :dataset_uri, :num_folds, :crossvalidation_fold ]
# selected attributes of interest when performing classification
VAL_ATTR_CLASS = [ :percent_correct, :weighted_area_under_roc, :area_under_roc, :f_measure, :true_positive_rate, :true_negative_rate ]
-VAL_ATTR_BAR_PLOT_CLASS = [ :accuracy, :weighted_area_under_roc, :area_under_roc, :f_measure, :true_positive_rate, :true_negative_rate ]
VAL_ATTR_REGR = [ :root_mean_squared_error, :mean_absolute_error, :r_square ]
+VAL_ATTR_BAR_PLOT_CLASS = [ :accuracy, :weighted_area_under_roc, :area_under_roc, :f_measure, :true_positive_rate, :true_negative_rate ]
+VAL_ATTR_BAR_PLOT_REGR = [ :root_mean_squared_error, :mean_absolute_error, :r_square ]
# = Reports::ReportFactory
#
@@ -105,11 +106,12 @@ module Reports::ReportFactory
def self.create_report_compare_algorithms(validation_set)
- #validation_set.to_array([:fold, :test_dataset_uri, :model_uri]).each{|a| puts a.inspect}
+ #validation_set.to_array([:test_dataset_uri, :model_uri, :algorithm_uri], false).each{|a| puts a.inspect}
raise Reports::BadRequest.new("num validations is not >1") unless validation_set.size>1
raise Reports::BadRequest.new("validations must be either all regression, "+
+"or all classification validations") unless validation_set.all_classification? or validation_set.all_regression?
- raise Reports::BadRequest.new("number of different algorithms <2") if validation_set.num_different_values(:algorithm_uri)<2
+ raise Reports::BadRequest.new("number of different algorithms <2: "+
+ validation_set.get_values(:algorithm_uri).inspect) if validation_set.num_different_values(:algorithm_uri)<2
if validation_set.has_nil_values?(:crossvalidation_id)
if validation_set.num_different_values(:test_dataset_uri)>1
@@ -146,10 +148,15 @@ module Reports::ReportFactory
#report.add_section_roc_plot(validation_set, class_value, :algorithm_uri, "roc-plot-"+class_value+".svg")
#end
report.add_section_result(validation_set,[:algorithm_uri]+VAL_ATTR_CLASS,"Results","Results")
- else #regression
+ else
+ #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_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")
end
+ report.add_section_result(validation_set, Lib::ALL_PROPS, "All Results", "All Results")
return report
end
else
@@ -250,9 +257,8 @@ class Reports::ReportContent
section_table = @xml_report.add_section(xml_report.get_root_element, section_title)
@xml_report.add_paragraph(section_table, section_text) if section_text
- vals = validation_set.to_array(validation_attributes,false,validation_set.get_true_prediction_feature_value)
- #PENDING rexml strings in tables not working when >66
- vals = vals.collect{|a| a.collect{|v| v.to_s[0,66] }}
+ vals = validation_set.to_array(validation_attributes,true,validation_set.get_true_prediction_feature_value)
+ vals = vals.collect{|a| a.collect{|v| v.to_s }}
#PENDING transpose values if there more than 4 columns, and there are more than columns than rows
transpose = vals[0].size>4 && vals[0].size>vals.size
@xml_report.add_table(section_table, table_title, vals, !transpose, transpose)
diff --git a/report/report_service.rb b/report/report_service.rb
index 6517a94..854f5f1 100644
--- a/report/report_service.rb
+++ b/report/report_service.rb
@@ -48,7 +48,7 @@ module Reports
# step1: load validations
raise Reports::BadRequest.new("validation_uris missing") unless validation_uris
- LOGGER.debug "validation_uris: '"+validation_uris.inspect+"'"
+ LOGGER.debug "validation_uri(s): '"+validation_uris.inspect+"'"
validation_set = Reports::ValidationSet.new(validation_uris)
raise Reports::BadRequest.new("cannot get validations from validation_uris '"+validation_uris.inspect+"'") unless validation_set and validation_set.size > 0
LOGGER.debug "loaded "+validation_set.size.to_s+" validation/s"
diff --git a/report/report_test.rb b/report/report_test.rb
index 03abdc3..df18297 100644
--- a/report/report_test.rb
+++ b/report/report_test.rb
@@ -1,12 +1,11 @@
require "fileutils"
ENV['RACK_ENV'] = 'test'
-
require 'report/report_application.rb'
require 'test/unit'
require 'rack/test'
-
require "lib/test_util.rb"
-
+LOGGER = Logger.new(STDOUT)
+LOGGER.datetime_format = "%Y-%m-%d %H:%M:%S "
class Reports::ApplicationTest < Test::Unit::TestCase
include Rack::Test::Methods
@@ -17,6 +16,9 @@ class Reports::ApplicationTest < Test::Unit::TestCase
def test_nothing
+ #Reports::XMLReport.generate_demo_xml_report.write_to
+ #raise "stop"
+
#uri = '/report/css_style_sheet?css_style_sheet='+CGI.escape("http://apps.ideaconsult.net:8180/ToxPredict/style/global.css")
#puts uri
#get uri
@@ -27,12 +29,14 @@ 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
- post 'http://ot.validation.de/report/validation',:validation_uris=>"http://ot.validation.de/validation/19"
+ post 'http://ot.validation.de/report/algorithm_comparison',:validation_uris=>"http://ot.validation.de/validation/15\n"+
+ "http://ot.validation.de/validation/16\n"+
+ "http://ot.validation.de/validation/18\n"
uri = last_response.body.to_s
puts uri
- #post uri.to_s+'/format_html',:css_style_sheet=>"http://apps.ideaconsult.net:8180/ToxPredict/style/global.css"
- #puts last_response.body.to_s.gsub(/\n.*/,"")
+ post uri.to_s+'/format_html',:css_style_sheet=>"http://apps.ideaconsult.net:8180/ToxPredict/style/global.css"
+ puts last_response.body.to_s.gsub(/\n.*/,"")
end
#
diff --git a/report/util.rb b/report/util.rb
index 5934064..ca12963 100644
--- a/report/util.rb
+++ b/report/util.rb
@@ -1,7 +1,23 @@
-
+require 'abbrev'
# graph-files are generated in the tmp-dir before they are stored
ENV['TMP_DIR'] = File.join(FileUtils.pwd,"reports","tmp") unless ENV['TMP_DIR']
+
+class Array
+ def common_prefix()
+ self.abbrev.keys.sort_by{|word| -word.size}.last[0..-2]
+ end
+
+ def remove_common_prefix()
+ if self.size > 2
+ prefix = self.common_prefix
+ if prefix.size>0
+ return self.collect{|word| word[prefix.size..-1]}
+ end
+ end
+ end
+end
+
class Object
# checks weather two objects have the same values for __equal_attributes__
diff --git a/report/xml_report.rb b/report/xml_report.rb
index 6f8a817..0dd93c2 100644
--- a/report/xml_report.rb
+++ b/report/xml_report.rb
@@ -11,185 +11,229 @@ ENV['REPORT_DTD'] = File.expand_path(ENV['REPORT_DTD']) if File.exist?(ENV['REPO
#
# uses Env-Variable _XMLREPORT_DTD_ to specifiy the dtd
#
-class Reports::XMLReport
- include REXML
-
- # create new xmlreport
- def initialize(title, pubdate=nil, author_firstname = nil, author_surname = nil)
-
- @doc = Document.new
- decl = XMLDecl.new
- @doc << decl
- type = DocType.new('article PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "'+ENV['REPORT_DTD']+'"')
- @doc << type
-
- @root = Element.new("article")
- @doc << @root
-
- article_info = Element.new("articleinfo")
- article_info << Reports::XMLReportUtil.text_element("title", title)
- author = Element.new("author")
- author << Reports::XMLReportUtil.text_element("firstname", author_firstname)
- author << Reports::XMLReportUtil.text_element("surname", author_surname)
- article_info << author
- article_info << Reports::XMLReportUtil.text_element("pubdate", pubdate)
- @root << article_info
-
- @resource_path_elements = {}
- end
-
- #
- # returns the root element of the document
- # call-seq:
- # get_root_element => REXML::Element
- #
- def get_root_element
- @root
- end
-
- # adds a new section to a REXML:Element, returns the section as element
- # call-seq:
- # add_section(element, title) => REXML::Element
- #
- def add_section(element, title)
-
- section = Element.new("section")
- section << Reports::XMLReportUtil.text_element("title", title)
- element << section
- return section
- end
-
- # adds a new paragraph to a REXML:Element, returns the paragraph as element
- # call-seq:
- # add_paragraph( element, text ) => REXML::Element
- #
- def add_paragraph( element, text )
+module Reports
+ class XMLReport
+ include REXML
- para = Reports::XMLReportUtil.text_element("para", text)
- element << para
- return para
- end
+ # create new xmlreport
+ def initialize(title, pubdate=nil, author_firstname = nil, author_surname = nil)
+
+ @doc = Document.new
+ decl = XMLDecl.new
+ @doc << decl
+ type = DocType.new('article PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "'+ENV['REPORT_DTD']+'"')
+ @doc << type
- # adds a new image to a REXML:Element, returns the figure as element
- #
- # example: <tt>add_imagefigure( section2, "Nice graph", "/images/graph1.svg", "SVG", "This graph shows..." )</tt>
- #
- # call-seq:
- # add_imagefigure( element, title, path, filetype, caption = nil ) => REXML::Element
- #
- def add_imagefigure( element, title, path, filetype, caption = nil )
-
- figure = Reports::XMLReportUtil.attribute_element("figure", {"float" => 0})
- figure << Reports::XMLReportUtil.text_element("title", title)
- media = Element.new("mediaobject")
- image = Element.new("imageobject")
- imagedata = Reports::XMLReportUtil.attribute_element("imagedata",{"contentwidth" => "100%", "fileref" => path, "format"=>filetype})
- #imagedata = Reports::XMLReportUtil.attribute_element("imagedata",{"width" => "6in", "fileref" => path, "format"=>filetype})
- @resource_path_elements[imagedata] = "fileref"
- image << imagedata
- media << image
- media << Reports::XMLReportUtil.text_element("caption", caption) if caption
- figure << media
- element << figure
- return figure
- end
+ @root = Element.new("article")
+ @doc << @root
- # adds a table to a REXML:Element, _table_values_ should be a multi-dimensional-array, returns the table as element
- #
- # call-seq:
- # add_table( element, title, table_values, first_row_is_table_header=true ) => REXML::Element
- #
- def add_table( element, title, table_values, first_row_is_table_header=true, transpose=false )
-
- raise "table_values is not mulit-dimensional-array" unless table_values && table_values.is_a?(Array) && table_values[0].is_a?(Array)
-
- values = transpose ? table_values.transpose : table_values
-
- table = Reports::XMLReportUtil.attribute_element("table",{"frame" => "top", "colsep" => 0, "rowsep" => 0})
-
- table << Reports::XMLReportUtil.text_element("title", title)
-
- raise "column count 0" if values.at(0).size < 1
-
- tgroup = Reports::XMLReportUtil.attribute_element("tgroup",{"cols" => values.at(0).size})
-
- table_body_values = values
+ article_info = Element.new("articleinfo")
+ article_info << Reports::XMLReportUtil.text_element("title", title)
+ author = Element.new("author")
+ author << Reports::XMLReportUtil.text_element("firstname", author_firstname)
+ author << Reports::XMLReportUtil.text_element("surname", author_surname)
+ article_info << author
+ article_info << Reports::XMLReportUtil.text_element("pubdate", pubdate)
+ @root << article_info
+
+ @resource_path_elements = {}
+ end
- if first_row_is_table_header
- table_head_values = values[0];
- table_body_values = values[1..-1];
-
- thead = Element.new("thead")
- row = Element.new("row")
- table_head_values.each{ |v| row << Reports::XMLReportUtil.text_element("entry", v.to_s) }
- thead << row
- tgroup << thead
+ #
+ # returns the root element of the document
+ # call-seq:
+ # get_root_element => REXML::Element
+ #
+ def get_root_element
+ @root
end
- tbody = Element.new("tbody")
- table_body_values.each do |r|
- row = Element.new("row")
- r.each { |v| row << Reports::XMLReportUtil.text_element("entry", v.to_s) }
- tbody << row
+ # adds a new section to a REXML:Element, returns the section as element
+ # call-seq:
+ # add_section(element, title) => REXML::Element
+ #
+ def add_section(element, title)
+
+ section = Element.new("section")
+ section << Reports::XMLReportUtil.text_element("title", title)
+ element << section
+ return section
end
- tgroup << tbody
- table << tgroup
- element << table
- return table
- end
-
- # adds a list to a REXML:Element, returns the list as element
- #
- # call-seq:
- # add_list( element, list_values ) => REXML::Element
- #
- def add_list( element, list_values )
+ # adds a new paragraph to a REXML:Element, returns the paragraph as element
+ # call-seq:
+ # add_paragraph( element, text ) => REXML::Element
+ #
+ def add_paragraph( element, text )
+
+ para = Reports::XMLReportUtil.text_element("para", text)
+ element << para
+ return para
+ end
- list = Element.new("itemizedlist")
+ # adds a new image to a REXML:Element, returns the figure as element
+ #
+ # example: <tt>add_imagefigure( section2, "Nice graph", "/images/graph1.svg", "SVG", "This graph shows..." )</tt>
+ #
+ # call-seq:
+ # add_imagefigure( element, title, path, filetype, caption = nil ) => REXML::Element
+ #
+ def add_imagefigure( element, title, path, filetype, caption = nil )
+
+ figure = Reports::XMLReportUtil.attribute_element("figure", {"float" => 0})
+ figure << Reports::XMLReportUtil.text_element("title", title)
+ media = Element.new("mediaobject")
+ image = Element.new("imageobject")
+ imagedata = Reports::XMLReportUtil.attribute_element("imagedata",{"contentwidth" => "100%", "fileref" => path, "format"=>filetype})
+ #imagedata = Reports::XMLReportUtil.attribute_element("imagedata",{"width" => "6in", "fileref" => path, "format"=>filetype})
+ @resource_path_elements[imagedata] = "fileref"
+ image << imagedata
+ media << image
+ media << Reports::XMLReportUtil.text_element("caption", caption) if caption
+ figure << media
+ element << figure
+ return figure
+ end
- list_values.each do |l|
- listItem = Element.new("listitem")
- add_paragraph(listItem, l.to_s)
- list << listItem
+ # adds a table to a REXML:Element, _table_values_ should be a multi-dimensional-array, returns the table as element
+ #
+ # call-seq:
+ # add_table( element, title, table_values, first_row_is_table_header=true ) => REXML::Element
+ #
+ def add_table( element, title, table_values, first_row_is_table_header=true, transpose=false, auto_link_urls=true )
+
+ raise "table_values is not mulit-dimensional-array" unless table_values && table_values.is_a?(Array) && table_values[0].is_a?(Array)
+
+ values = transpose ? table_values.transpose : table_values
+
+ table = Reports::XMLReportUtil.attribute_element("table",{"frame" => "top", "colsep" => 0, "rowsep" => 0})
+
+ table << Reports::XMLReportUtil.text_element("title", title)
+
+ raise "column count 0" if values.at(0).size < 1
+
+ tgroup = Reports::XMLReportUtil.attribute_element("tgroup",{"cols" => values.at(0).size})
+
+ table_body_values = values
+
+ if first_row_is_table_header
+ table_head_values = values[0];
+ table_body_values = values[1..-1];
+
+ thead = Element.new("thead")
+ row = Element.new("row")
+ table_head_values.each do |v|
+ entry = Element.new("entry")
+ if auto_link_urls && v.to_s =~ /^http:\/\//
+ add_url(entry, v.to_s)
+ else
+ entry.text = v.to_s
+ end
+ row << entry
+ end
+ thead << row
+ tgroup << thead
+ end
+
+ tbody = Element.new("tbody")
+ table_body_values.each do |r|
+ row = Element.new("row")
+ r.each do |v|
+ entry = Element.new("entry")
+ if auto_link_urls && v.to_s =~ /^http:\/\//
+ add_url(entry, v.to_s, v.to_s)
+ else
+ entry.text = v.to_s
+ end
+ row << entry
+ end
+ tbody << row
+ end
+ tgroup << tbody
+
+ table << tgroup
+ element << table
+ return table
end
- element << list
- return list
- end
-
- # writes xml document
- def write_to( out = $stdout, resource_path=nil )
+ # adds a list to a REXML:Element, returns the list as element
+ #
+ # call-seq:
+ # add_list( element, list_values ) => REXML::Element
+ #
+ def add_list( element, list_values )
+
+ list = Element.new("itemizedlist")
+
+ list_values.each do |l|
+ listItem = Element.new("listitem")
+ add_paragraph(listItem, l.to_s)
+ list << listItem
+ end
+
+ element << list
+ return list
+ end
- #alternativly use base href in html-header
- if (resource_path)
- @resource_path_elements.each do |k,v|
- raise "attribute '"+v+"' not found in element '"+k+"'" unless k.attributes.has_key?(v)
- k.add_attribute( v, resource_path.to_s+"/"+k.attributes[v].to_s )
+ def add_url (element, url, description=url, check_url_length=true )
+
+ if (check_url_length)
+ #HACK nice solution wanted
+ d = description
+ i = d.index("/")
+ while d.size > 60 && i!=nil
+ #puts d+" "+i.to_s
+ d = d[(i+1)..-1]
+ i = d.index("/")
+ end
+ raise "still too long" if d.size > 60
+ d = "..."+d if d!=description
+ else
+ d = description
end
+ ulink = Element.new("ulink")
+ ulink.add_attributes({"url" => url})
+ ulink.text = d
+ element << ulink
+ return ulink
end
- @doc.write(out,2)
- end
-
- # call-seq:
- # self.generate_demo_xml_report => Reports::XMLReport
- #
- def self.generate_demo_xml_report
-
- rep = Reports::XMLReport.new("Demo report", "subtitle" "Fistname", "Surname")
- section1 = rep.add_section(rep.get_root_element, "First Section")
- rep.add_paragraph(section1, "some text")
- rep.add_paragraph(section1, "even more text")
- rep.add_imagefigure(section1, "Figure", "http://upload.wikimedia.org/wikipedia/commons/thumb/e/eb/Siegel_der_Albert-Ludwigs-Universit%C3%A4t_Freiburg.svg/354px-Siegel_der_Albert-Ludwigs-Universit%C3%A4t_Freiburg.svg", "SVG", "this is the logo of freiburg university")
- section2 = rep.add_section(rep.get_root_element,"Second Section")
- rep.add_section(section2,"A Subsection")
- rep.add_section(section2,"Another Subsection")
- rep.add_section(rep.get_root_element,"Third Section")
+ # writes xml document
+ def write_to( out = $stdout, resource_path=nil )
+
+ #alternativly use base href in html-header
+ if (resource_path)
+ @resource_path_elements.each do |k,v|
+ raise "attribute '"+v+"' not found in element '"+k+"'" unless k.attributes.has_key?(v)
+ k.add_attribute( v, resource_path.to_s+"/"+k.attributes[v].to_s )
+ end
+ end
+
+ @doc.write(out,2)
+ end
+
+ # call-seq:
+ # self.generate_demo_xml_report => Reports::XMLReport
+ #
+ def self.generate_demo_xml_report
+
+ rep = Reports::XMLReport.new("Demo report", "subtitle" "Fistname", "Surname")
+ section1 = rep.add_section(rep.get_root_element, "First Section")
+ rep.add_paragraph(section1, "some text")
+ rep.add_paragraph(section1, "even more text")
+ rep.add_imagefigure(section1, "Figure", "http://upload.wikimedia.org/wikipedia/commons/thumb/e/eb/Siegel_der_Albert-Ludwigs-Universit%C3%A4t_Freiburg.svg/354px-Siegel_der_Albert-Ludwigs-Universit%C3%A4t_Freiburg.svg", "SVG", "this is the logo of freiburg university")
+ section2 = rep.add_section(rep.get_root_element,"Second Section")
+ rep.add_section(section2,"A Subsection")
+ rep.add_section(section2,"Another Subsection")
+ rep.add_url(section2,"www.google.de", "link zu google")
+ rep.add_section(rep.get_root_element,"Third Section")
+
+ vals= [["a", "b", "c"],["a2", "b2", "c2"],["1", "2", "http://3"]]
+ rep.add_table(rep.get_root_element, "demo-table", vals)
+ return rep
+ end
- return rep
end
-
end
@@ -204,5 +248,4 @@ end
-
diff --git a/report/xml_report_util.rb b/report/xml_report_util.rb
index d047421..c584ac9 100644
--- a/report/xml_report_util.rb
+++ b/report/xml_report_util.rb
@@ -60,6 +60,13 @@ module Reports::XMLReportUtil
return node
end
+ def self.url_element(url, description=url )
+ ulink = Element.new("ulink")
+ ulink.add_attributes({"url" => url})
+ ulink.text = description
+ return ulink
+ end
+
def self.attribute_element(name, attributes)
node = Element.new(name)
node.add_attributes(attributes)
diff --git a/validation/validation_application.rb b/validation/validation_application.rb
index 526af89..a92bbee 100644
--- a/validation/validation_application.rb
+++ b/validation/validation_application.rb
@@ -130,10 +130,11 @@ post '/?' do
:prediction_feature => params[:prediction_feature]
v.validate_model
elsif params[:algorithm_uri] and params[:training_dataset_uri] and params[:test_dataset_uri] and params[:prediction_feature] and !params[:model_uri]
- v = Validation::Validation.new :training_dataset_uri => params[:training_dataset_uri],
+ v = Validation::Validation.new :algorithm_uri => params[:algorithm_uri],
+ :training_dataset_uri => params[:training_dataset_uri],
:test_dataset_uri => params[:test_dataset_uri],
:prediction_feature => params[:prediction_feature]
- v.validate_algorithm( params[:algorithm_uri], params[:algorithm_params])
+ v.validate_algorithm( params[:algorithm_params])
else
halt 400, "illegal parameter combination for validation, use either\n"+
"* model_uri, test_dataset_uri\n"+
@@ -156,13 +157,37 @@ post '/training_test_split' do
v = Validation::Validation.new :training_dataset_uri => params[:training_dataset_uri],
:test_dataset_uri => params[:test_dataset_uri],
:prediction_feature => params[:prediction_feature]
- content_type "text/uri-list"
v.validate_algorithm( params[:algorithm_uri], params[:algorithm_params])
content_type "text/uri-list"
v.uri
end
end
+
+post '/plain_training_test_split' do
+ LOGGER.info "creating pure training test split "+params.inspect
+ halt 400, "dataset_uri missing" unless params[:dataset_uri]
+
+ result = Validation::Util.train_test_dataset_split(params[:dataset_uri], params[:split_ratio], params[:random_seed])
+ content_type "text/uri-list"
+ result[:training_dataset_uri]+"\n"+result[:test_dataset_uri]+"\n"
+end
+
+post '/create_validation' do
+ OpenTox::Task.as_task do
+ LOGGER.info "creating validation "+params.inspect
+ halt 400, "test_dataset_uri missing" unless params[:test_dataset_uri]
+ halt 400, "prediction_datset_uri missing" unless params[:prediction_dataset_uri]
+ halt 400, "model_uri missing" unless params[:model_uri]
+
+ v = Validation::Validation.new params
+ v.compute_validation_stats()
+ content_type "text/uri-list"
+ v.uri
+ end
+end
+
+
get '/:id/:attribute' do
LOGGER.info "access validation attribute "+params.inspect
halt 404, "Validation #{params[:id]} not found." unless validation = Validation::Validation.get(params[:id])
diff --git a/validation/validation_format.rb b/validation/validation_format.rb
index d03dee4..3f7e7b8 100644
--- a/validation/validation_format.rb
+++ b/validation/validation_format.rb
@@ -132,7 +132,7 @@ module Validation
def get_content_as_hash
h = {}
- Lib::CROSS_VAL_PROPS.each{|p| h[p] = self.send(p)}
+ Lib::CROSS_VAL_PROPS_REDUNDANT.each{|p| h[p] = self.send(p)}
v = []
Validation.all(:crossvalidation_id => self.id).each do |val|
diff --git a/validation/validation_service.rb b/validation/validation_service.rb
index 3791749..3cf1d56 100644
--- a/validation/validation_service.rb
+++ b/validation/validation_service.rb
@@ -62,10 +62,9 @@ module Validation
end
# validates an algorithm by building a model and validating this model
- def validate_algorithm( algorithm_uri, algorithm_params=nil )
+ def validate_algorithm( algorithm_params=nil )
- $sinatra.halt 404, "no algorithm uri: '"+algorithm_uri+"'" if algorithm_uri==nil or algorithm_uri.to_s.size<1
-
+ $sinatra.halt 404, "no algorithm uri: '"+algorithm_uri.to_s+"'" if @algorithm_uri==nil or @algorithm_uri.to_s.size<1
$sinatra.halt 404, "prediction_feature is already encoded: "+@prediction_feature if @prediction_feature=~/%20/
update :prediction_feature => URI.encode(@prediction_feature)
@@ -96,12 +95,17 @@ module Validation
def validate_model
LOGGER.debug "validating model '"+@model_uri+"'"
- test_dataset = OpenTox::Dataset.find @test_dataset_uri
- $sinatra.halt 400, "test dataset no found: "+@test_dataset_uri.to_s unless test_dataset
+
+ #test_dataset = OpenTox::Dataset.find @test_dataset_uri
+ #$sinatra.halt 400, "test dataset no found: "+@test_dataset_uri.to_s unless test_dataset
model = OpenTox::Model::PredictionModel.find(@model_uri)
$sinatra.halt 400, "model not found: "+@model_uri.to_s unless model
+ unless @algorithm_uri
+ update :algorithm_uri => model.algorithm
+ end
+
if @prediction_feature
$sinatra.halt 400, "error validating model: model.dependent_variable != validation.prediciton_feature ("+
model.dependent_variables+" != "+@prediction_feature+")" if @prediction_feature!=model.dependent_variables
@@ -113,18 +117,29 @@ module Validation
benchmark = Benchmark.measure do
prediction_dataset_uri = model.predict_dataset(@test_dataset_uri)
end
+ update :prediction_dataset_uri => prediction_dataset_uri,
+ :real_runtime => benchmark.real
+
+ compute_validation_stats(model)
+ end
+
+ def compute_validation_stats(model = nil)
+
+ model = OpenTox::Model::PredictionModel.find(@model_uri) unless model
+ $sinatra.halt 400, "model not found: "+@model_uri.to_s unless model
+
+ update :prediction_feature => model.dependent_variables unless @prediction_feature
+ update :algorithm_uri => model.algorithm unless @algorithm_uri
LOGGER.debug "computing prediction stats"
- prediction = Lib::OTPredictions.new( model.classification?, @test_dataset_uri, @prediction_feature, prediction_dataset_uri, model.predicted_variables )
+ prediction = Lib::OTPredictions.new( model.classification?, @test_dataset_uri, @prediction_feature, @prediction_dataset_uri, model.predicted_variables )
if prediction.classification?
update :classification_statistics => prediction.compute_stats
else
update :regression_statistics => prediction.compute_stats
end
- update :prediction_dataset_uri => prediction_dataset_uri,
- :real_runtime => benchmark.real,
- :num_instances => prediction.num_instances,
+ update :num_instances => prediction.num_instances,
:num_without_class => prediction.num_without_class,
:percent_without_class => prediction.percent_without_class,
:num_unpredicted => prediction.num_unpredicted,
@@ -165,7 +180,7 @@ module Validation
LOGGER.debug "perform cv validations"
Validation.all( :crossvalidation_id => id ).each do |v|
- v.validate_algorithm( @algorithm_uri, algorithm_params )
+ v.validate_algorithm( algorithm_params )
#break
end
end
@@ -193,7 +208,8 @@ module Validation
validation = Validation.new :crossvalidation_id => @id,
:crossvalidation_fold => v.crossvalidation_fold,
:training_dataset_uri => v.training_dataset_uri,
- :test_dataset_uri => v.test_dataset_uri
+ :test_dataset_uri => v.test_dataset_uri,
+ :algorithm_uri => @algorithm_uri
end
LOGGER.debug "copyied dataset uris from cv "+cv.uri.to_s
return true
@@ -283,7 +299,8 @@ module Validation
validation = Validation.new :training_dataset_uri => train_dataset_uri,
:test_dataset_uri => test_dataset_uri,
:crossvalidation_id => @id, :crossvalidation_fold => n,
- :prediction_feature => prediction_feature
+ :prediction_feature => prediction_feature,
+ :algorithm_uri => @algorithm_uri
end
end
end
diff --git a/validation/validation_test.rb b/validation/validation_test.rb
index 63c8516..3a3d904 100644
--- a/validation/validation_test.rb
+++ b/validation/validation_test.rb
@@ -1,3 +1,6 @@
+require "logger"
+require "uri"
+require "yaml"
ENV['RACK_ENV'] = 'test'
require 'application.rb'
require 'test/unit'
@@ -6,19 +9,8 @@ require 'lib/test_util.rb'
LOGGER = Logger.new(STDOUT)
LOGGER.datetime_format = "%Y-%m-%d %H:%M:%S "
-WS_DATA=@@config[:services]["opentox-dataset"] #"localhost:4002"
-#FILE=File.new("data/hamster_carcinogenicity.owl","r")
-FILE=File.new("data/hamster_carcinogenicity.yaml","r")
-FILE_TRAIN=File.new("data/hamster_carcinogenicity.owl","r")
-FILE_TEST=File.new("data/hamster_carcinogenicity.owl","r")
-#FEATURE_URI="http://localhost/toxmodel/feature#Hamster%20Carcinogenicity%20(DSSTOX/CPDB)"
-FEATURE_URI="http://localhost/toxmodel/feature#Hamster Carcinogenicity (DSSTOX/CPDB)"
-#WS_CLASS_ALG="http://webservices.in-silico.ch/test/algorithm/lazar"
-WS_CLASS_ALG=File.join(@@config[:services]["opentox-algorithm"],"lazar") #"localhost:4003/lazar"
-WS_FEATURE_ALG=File.join(@@config[:services]["opentox-algorithm"],"fminer") #"localhost:4003/fminer"
-
class Example
- attr_accessor :alg, :train_data, :test_data, :model, :pred_data, :act_feat, :pred_feat, :classification, :alg_params
+ attr_accessor :alg, :train_data, :test_data, :model, :pred_data, :act_feat, :pred_feat, :classification, :alg_params, :val, :orig_data
end
class ValidationTest < Test::Unit::TestCase
@@ -26,12 +18,17 @@ class ValidationTest < Test::Unit::TestCase
include Lib::TestUtil
def test_it
-
+
#prepare_examples
- #do_test_examples # USES CURL, DO NOT FORGET TO RESTART
- validate_prediction_dataset(ex_ntua)
- #validate_model(ex_ntua)
- #validate_algorithm(ex_ntua2)
+ do_test_examples # USES CURL, DO NOT FORGET TO RESTART
+
+ #ex = ex_ntua
+ #ex = ex_tum
+
+ #create_validation(ex)
+ #validate_model(ex)
+ #validate_algorithm(ex)
+ #validate_split(ex)
#test_dataset = OpenTox::Dataset.find ex_ntua2.pred_data
#puts ex_ntua2.pred_data.to_s+", "+test_dataset.compounds.size.to_s+" compounds"
@@ -42,6 +39,46 @@ class ValidationTest < Test::Unit::TestCase
Sinatra::Application
end
+ def ex_local
+ ex = Example.new
+ ex.classification = false
+
+ ex.alg = File.join(@@config[:services]["opentox-algorithm"],"lazar")
+ ex.alg_params = "feature_generation_uri="+File.join(@@config[:services]["opentox-algorithm"],"fminer")
+
+ dataset = @@config[:services]["opentox-dataset"]
+
+ ex.orig_data = File.join(dataset,"1")
+ begin
+ orig = OpenTox::Dataset.find(ex.orig_data)
+ raise "not correct, upload" if (orig == nil || orig.compounds.size!=85)
+ rescue
+ upload_uri = upload_data(dataset, File.new("data/hamster_carcinogenicity.yaml","r"))
+ ex.orig_data = upload_uri
+ end
+
+ ex.train_data = File.join(dataset,"2")
+ ex.test_data = File.join(dataset,"3")
+ begin
+ train = OpenTox::Dataset.find(ex.train_data)
+ test = OpenTox::Dataset.find(ex.test_data)
+ raise "not correct, split" if (train == nil || test == nil || train.compounds.size>=85 || test.compounds.size>=test.compounds.size)
+ rescue
+ post '/plain_training_test_split', { :dataset_uri => ex.orig_data, :split_ratio=>0.75, :random_seed=>6}
+ split = last_response.body.split("\n")
+ ex.train_data = split[0]
+ ex.test_data = split[1]
+ end
+
+ ex.act_feat = "http://localhost/toxmodel/feature#Hamster Carcinogenicity (DSSTOX/CPDB)"
+ # example model
+ #ex.model = "http://opentox.ntua.gr:3000/model/29"
+ #ex.pred_feat = "http://ambit.uni-plovdiv.bg:8080/ambit2/feature/261687"
+ # example prediction data
+ #ex.pred_data = "http://ambit.uni-plovdiv.bg:8080/ambit2/dataset/625"
+ return ex
+ end
+
def ex_ntua2
ex = Example.new
ex.classification = false
@@ -50,10 +87,10 @@ class ValidationTest < Test::Unit::TestCase
ex.test_data = "http://apps.ideaconsult.net:8180/ambit2/dataset/55" #53
ex.act_feat = "http://apps.ideaconsult.net:8180/ambit2/feature/22200" #22190"
# example model
- ex.model = "http://opentox.ntua.gr:3000/model/29"
- ex.pred_feat = "http://ambit.uni-plovdiv.bg:8080/ambit2/feature/261687"
+ #ex.model = "http://opentox.ntua.gr:3000/model/29"
+ #ex.pred_feat = "http://ambit.uni-plovdiv.bg:8080/ambit2/feature/261687"
# example prediction data
- ex.pred_data = "http://ambit.uni-plovdiv.bg:8080/ambit2/dataset/625"
+ #ex.pred_data = "http://ambit.uni-plovdiv.bg:8080/ambit2/dataset/625"
return ex
end
@@ -61,14 +98,21 @@ class ValidationTest < Test::Unit::TestCase
ex = Example.new
ex.classification = false
ex.alg = "http://opentox.ntua.gr:3000/algorithm/mlr"
+
+ #ex.orig_data = "http://apps.ideaconsult.net:8180/ambit2/dataset/52"
+
ex.train_data = "http://ambit.uni-plovdiv.bg:8080/ambit2/dataset/342"
ex.test_data = "http://ambit.uni-plovdiv.bg:8080/ambit2/dataset/342"
+
ex.act_feat = "http://ambit.uni-plovdiv.bg:8080/ambit2/feature/103141"
+
# example model
- ex.model = "http://opentox.ntua.gr:3000/model/9"
- ex.pred_feat = "http://ambit.uni-plovdiv.bg:8080/ambit2/feature/227289"
+ ex.model = "http://opentox.ntua.gr:3000/model/36"
+ #ex.pred_feat = "http://ambit.uni-plovdiv.bg:8080/ambit2/feature/264783"
# example prediction data
- ex.pred_data = "http://ambit.uni-plovdiv.bg:8080/ambit2/dataset/407"
+ ex.pred_data = "http://ambit.uni-plovdiv.bg:8080/ambit2/dataset/656"
+ # validation
+ #ex.val = "http://ot.validation.de/21"
return ex
end
@@ -76,14 +120,34 @@ class ValidationTest < Test::Unit::TestCase
ex = Example.new
ex.classification = false
ex.alg = "http://opentox.informatik.tu-muenchen.de:8080/OpenTox-dev/algorithm/kNNregression"
- ex.train_data = "http://ambit.uni-plovdiv.bg:8080/ambit2/dataset/342"
- ex.test_data = "http://ambit.uni-plovdiv.bg:8080/ambit2/dataset/342"
- ex.act_feat = "http://ambit.uni-plovdiv.bg:8080/ambit2/feature/103141"
+ #ex.alg = "http://opentox.informatik.tu-muenchen.de:8080/OpenTox-dev/algorithm/M5P"
+ #ex.alg = "http://opentox.informatik.tu-muenchen.de:8080/OpenTox-dev/algorithm/GaussP"
+
+ #mini
+ #ex.train_data = "http://ambit.uni-plovdiv.bg:8080/ambit2/dataset/342"
+ #ex.test_data = "http://ambit.uni-plovdiv.bg:8080/ambit2/dataset/342"
+ #ex.act_feat = "http://ambit.uni-plovdiv.bg:8080/ambit2/feature/03141"
+
+ #big
+ ex.train_data = "http://ambit.uni-plovdiv.bg:8080/ambit2/dataset/639"
+ ex.test_data = "http://ambit.uni-plovdiv.bg:8080/ambit2/dataset/640"
+ ex.act_feat = "http://ambit.uni-plovdiv.bg:8080/ambit2/feature/264185"
+ #ex.act_feat = "http://ambit.uni-plovdiv.bg:8080/ambit2/feature/264187" #test
+
# example model
- ex.model = "http://opentox.informatik.tu-muenchen.de:8080/OpenTox-dev/model/TUMOpenToxModel_kNN_11"
- ex.pred_feat = "http://ambit.uni-plovdiv.bg:8080/ambit2/feature/261129"
+ ex.model = "http://opentox.informatik.tu-muenchen.de:8080/OpenTox-dev/model/TUMOpenToxModel_kNN_23"
+ #ex.model = "http://opentox.informatik.tu-muenchen.de:8080/OpenTox-dev/model/TUMOpenToxModel_M5P_13"
+ #ex.model = "http://opentox.informatik.tu-muenchen.de:8080/OpenTox-dev/model/TUMOpenToxModel_GaussP_4"
+
+ #ex.pred_feat =
+
# example prediction data
- ex.pred_data = "http://ambit.uni-plovdiv.bg:8080/ambit2/dataset/601"
+ ex.pred_data = "http://ambit.uni-plovdiv.bg:8080/ambit2/dataset/659" #knn
+ #ex.pred_data = http://ambit.uni-plovdiv.bg:8080/ambit2/dataset/658" #m5p
+ #ex.pred_data = "http://ambit.uni-plovdiv.bg:8080/ambit2/dataset/653" #gaus
+
+ # validataion
+ # ex.val = "http://ot.validation.de/34"
return ex
end
@@ -254,7 +318,7 @@ class ValidationTest < Test::Unit::TestCase
end
end
- def validate_prediction_dataset(ex)
+ def create_validation(ex)
# classification = false
# test_dataset_uri = "http://ambit.uni-plovdiv.bg:8080/ambit2/dataset/342"
@@ -279,47 +343,64 @@ class ValidationTest < Test::Unit::TestCase
# assert predicted_feature==URI.encode(FEATURE_URI+"_lazar_classification"), predicted_feature
# #predicted_feature="http://www.epa.gov/NCCT/dsstox/CentralFieldDef.html#ActivityOutcome_CPDBAS_Hamster_lazar_prediction"
-
#puts Lib::OTPredictions.new( classification, test_dataset_uri, actual_feature, prediction_dataset_uri, predicted_feature ).compute_stats.each{|key,value| puts key.to_s+" => "+value.to_s }
- predicted_feature = OpenTox::Model::PredictionModel.find(ex.model).predicted_variables
- assert predicted_feature==ex.pred_feat,"nope: "+predicted_feature.to_s
- puts Lib::OTPredictions.new( ex.classification, ex.test_data, ex.act_feat, ex.pred_data, ex.pred_feat ).compute_stats.each{|key,value| puts key.to_s+" => "+value.to_s }
+
+ #predicted_feature = OpenTox::Model::PredictionModel.find(ex.model).predicted_variables
+ #puts "predicted feature "+predicted_feature.to_s
+
+ assert(predicted_feature==ex.pred_feat,"nope: "+predicted_feature.to_s) if ex.pred_feat
+
+ post '/create_validation', { :test_dataset_uri => ex.test_data, :model_uri => ex.model, :prediction_dataset_uri=> ex.pred_data}
+ puts last_response.body
+
+ task = OpenTox::Task.find(last_response.body)
+ task.wait_for_completion
+ val_uri = task.resource
+ puts val_uri
+
+ get val_uri
+ puts last_response.body
+
+ #puts Lib::OTPredictions.new( ex.classification, ex.test_data, ex.act_feat, ex.pred_data, ex.pred_feat ).compute_stats.each{|key,value| puts key.to_s+" => "+value.to_s }
end
-# def test_split
-# begin
-#
-## model = OpenTox::Model::PredictionModel.find("http://ot.model.de/66")
-## puts model.predicted_variables
-## exit
-#
-# data_uri = upload_data(WS_DATA, FILE)
-# #data_uri = "http://ot.dataset.de/199" #bbrc
-# #data_uri = "http://ot.dataset.de/67" #hamster
-# #puts data_uri
-#
-# #exit
-#
-# #data_uri=WS_DATA+"/"+DATA
+ def validate_split(ex)
+ begin
+
+# model = OpenTox::Model::PredictionModel.find("http://ot.model.de/66")
+# puts model.predicted_variables
+# exit
+
+ #data_uri = upload_data(WS_DATA, FILE)
+ #data_uri = "http://ot.dataset.de/199" #bbrc
+ #data_uri = "http://ot.dataset.de/67" #hamster
+ #puts data_uri
+
+ #exit
+
+ #data_uri=WS_DATA+"/"+DATA
# post '/training_test_split', { :dataset_uri => data_uri, :algorithm_uri => WS_CLASS_ALG, :prediction_feature => FEATURE_URI,
# :algorithm_params => "feature_generation_uri="+WS_FEATURE_ALG, :split_ratio=>0.75, :random_seed=>6}
-# puts last_response.body
-#
-# task = OpenTox::Task.find(last_response.body)
-# task.wait_for_completion
-# val_uri = task.resource
-# puts val_uri
-#
-# get val_uri
-# puts last_response.body
-# #verify_validation
-# ensure
-# #delete_resources
-# end
-# end
+ post '/training_test_split', { :dataset_uri => ex.orig_data, :algorithm_uri => ex.alg, :prediction_feature => ex.pred_feat,
+ :algorithm_params => ex.alg_params, :split_ratio=>0.75, :random_seed=>6}
+
+ puts last_response.body
+
+ task = OpenTox::Task.find(last_response.body)
+ task.wait_for_completion
+ val_uri = task.resource
+ puts val_uri
+
+ get val_uri
+ puts last_response.body
+ #verify_validation
+ ensure
+ #delete_resources
+ end
+ end
def verify_validation(val_yaml)