summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Gütlein <martin.guetlein@gmail.com>2010-02-26 15:13:44 +0100
committerMartin Gütlein <martin.guetlein@gmail.com>2010-02-26 15:13:44 +0100
commite2b814301c323bc787ad9d75eceb786e3cb7dde9 (patch)
tree21c668db2a956796302a97d1a41fb59c38783cf0
parentbb3f0d747876b59e6c2eaa24441d5690c2655d3b (diff)
replacing r bar plot with ruby-plot gem
-rw-r--r--example.rb2
-rw-r--r--lib/predictions.rb7
-rw-r--r--report/environment.rb3
-rw-r--r--report/plot_factory.rb31
-rw-r--r--report/r_plot_factory.rb115
-rw-r--r--report/report_factory.rb3
-rw-r--r--validation/validation_test.rb32
7 files changed, 48 insertions, 145 deletions
diff --git a/example.rb b/example.rb
index 985233c..d9a1657 100644
--- a/example.rb
+++ b/example.rb
@@ -156,7 +156,7 @@ class Example
# logs string and and adds to summary
def self.log(log_string)
- LOGGER.info log_string
+ LOGGER.info "EXAMPLE: "+log_string
@@summary += log_string+"\n"
end
diff --git a/lib/predictions.rb b/lib/predictions.rb
index 5a43d24..f673f8c 100644
--- a/lib/predictions.rb
+++ b/lib/predictions.rb
@@ -1,11 +1,4 @@
-if ENV['R_HOME']
- ENV['PATH'] = ENV['R_HOME']+":"+ENV['PATH'] unless ENV['PATH'].split(":").index(ENV['R_HOME'])
-else
- LOGGER.warn "Environment variable R_HOME not set"
-end
-require 'rinruby'
-
module Lib
module Util
diff --git a/report/environment.rb b/report/environment.rb
index a91c226..6d31615 100644
--- a/report/environment.rb
+++ b/report/environment.rb
@@ -9,7 +9,7 @@ require 'yaml'
require 'opentox-ruby-api-wrapper'
require 'fileutils'
require 'mime/types'
-require 'svg_roc_plot'
+require 'ruby-plot'
module Reports
end
@@ -19,7 +19,6 @@ end
#LOGGER.datetime_format = "%Y-%m-%d %H:%M:%S "
#end
-require "report/r_plot_factory.rb"
require "report/plot_factory.rb"
require "report/xml_report.rb"
require "report/xml_report_util.rb"
diff --git a/report/plot_factory.rb b/report/plot_factory.rb
index 3973989..d2884e3 100644
--- a/report/plot_factory.rb
+++ b/report/plot_factory.rb
@@ -39,13 +39,40 @@ module Reports
fp_rates << data[:fp_rate][0]
tp_rates << data[:tp_rate][0]
end
- Svg_Roc_Plot::plot(out_file, "ROC-Plot", "False positive rate", "True Positive Rate", names, fp_rates, tp_rates )
+ RubyPlot::plot_lines(out_file, "ROC-Plot", "False positive rate", "True Positive Rate", names, fp_rates, tp_rates )
else
data = transform_predictions(validation_set, class_value, show_single_curves)
- Svg_Roc_Plot::plot(out_file, "ROC-Plot", "False positive rate", "True Positive Rate", data[:names], data[:fp_rate], data[:tp_rate], data[:faint] )
+ RubyPlot::plot_lines(out_file, "ROC-Plot", "False positive rate", "True Positive Rate", data[:names], data[:fp_rate], data[:tp_rate], data[:faint] )
end
end
+ def self.create_bar_plot( out_file, validation_set, class_value, title_attribute, value_attributes )
+
+ LOGGER.debug "creating bar plot, out-file:"+out_file.to_s
+
+ data = []
+ validation_set.validations.each do |v|
+ values = []
+ value_attributes.collect do |a|
+ value = v.send(a)
+ if value.is_a?(Hash)
+ raise "bar plot value is hash, but no entry for class-value ("+class_value.to_s+")" unless value.key?(class_value)
+ value = value[class_value]
+ end
+ values.push(value)
+ end
+ data << [v.send(title_attribute).to_s] + values
+ end
+
+ labels = value_attributes.collect{|a| a.to_s.gsub("_","-")}
+
+ LOGGER.debug "bar plot labels: "+labels.inspect
+ LOGGER.debug "bar plot data: "+data.inspect
+
+ RubyPlot::plot_bars('Bar plot', labels, data, out_file)
+
+ end
+
def self.create_ranking_plot( svg_out_file, validation_set, compare_attribute, equal_attribute, rank_attribute )
diff --git a/report/r_plot_factory.rb b/report/r_plot_factory.rb
deleted file mode 100644
index 0c3a492..0000000
--- a/report/r_plot_factory.rb
+++ /dev/null
@@ -1,115 +0,0 @@
-
-# the r-path has to be added for the rinruby plugin
-if ENV['R_HOME']
- ENV['PATH'] = ENV['R_HOME']+":"+ENV['PATH'] unless ENV['PATH'].split(":").index(ENV['R_HOME'])
-else
- LOGGER.warn "Environment variable R_HOME not set"
-end
-require "rinruby"
-
-# colors for r-plots
-R_PLOT_COLORS = ["red", "blue", "green", "yellow"]
-
-# = Reports::RPlotFactory
-#
-# creates plots from validation-sets using rinruby
-#
-module Reports::RPlotFactory
-
- # creates a bar plot (result is plotted into out_file),
- # one category for each attribute in value_attributes, title_attribute is used for the legend
- #
- def self.create_bar_plot( out_file, validation_set, class_value, title_attribute, value_attributes )
-
- LOGGER.debug "creating bar plot, out-file:"+out_file.to_s
- b = Reports::BarPlot.new( out_file )
- validation_set.validations.each do |v|
- values = []
- value_attributes.collect do |a|
- value = v.send(a)
- if value.is_a?(Hash)
- raise "bar plat value is hash, but no entry for class-value ("+class_value.to_s+")" unless value.key?(class_value)
- value = value[class_value]
- end
- values.push(value)
- end
- b.add_data(v.send(title_attribute), values)
- end
- b.build_plot(value_attributes.collect{|a| a.to_s})
- end
-
- def self.demo_bar_plot(file = nil)
- r = Reports::BarPlot.new(file)
- r.add_data("Alg1",[0.9, 0.3, 0.2, 0.75, 0.5])
- r.add_data("Alg2",[0.8, 0.4, 0.2, 0.77, 0.6])
- r.add_data("Alg3",[0.4, 0.2, 0.1, 0.9, 0.55])
- r.add_data("Alg4",[0.9, 0.3, 0.2, 0.75, 0.5])
- r.build_plot(["val1", "val2", "val3", "val4", "high-val"])
- unless(file)
- puts "press ENTER to end program"
- gets
- puts "program ended"
- end
- end
-
- private
- def self.transform_predictions(validation_set, class_value)
-
- predict_array = Array.new
- actual_array = Array.new
- if (validation_set.size > 1)
- (0..validation_set.size-1).each do |i|
- predict_array.push(validation_set.get(i).get_predictions.roc_confidence_values(class_value))
- actual_array.push(validation_set.get(i).get_predictions.roc_actual_values(class_value))
- end
- else
- predict_array = validation_set.first.get_predictions.roc_confidence_values(class_value)
- actual_array = validation_set.first.get_predictions.roc_actual_values(class_value)
- end
- return [ predict_array, actual_array ]
- end
-
-end
-
-
-class Reports::RPlot
-
- def initialize( out_file = nil )
- if out_file
- raise "non-svg files not supported yet" unless out_file.to_s.upcase =~ /.*\.SVG.*/
- R.eval 'library("RSVGTipsDevice")'
- R.eval 'devSVGTips(file = "'+out_file+'")'
- end
- end
-
-end
-
-class Reports::BarPlot < Reports::RPlot
-
- def initialize( out_file = nil )
- super(out_file)
- @titles = Array.new
- @rows = Array.new
- end
-
- def add_data(title, values)
-
- row = "row"+(@rows.size+1).to_s
- R.assign row, values
- @rows.push(row)
- @titles.push(title)
- end
-
- def build_plot(value_names, y_axis_scale=[0,1])
-
- raise "not enough colors defined" if @titles.size > R_PLOT_COLORS.size
- @cols = R_PLOT_COLORS[0, @titles.size]
- R.assign "titles", @titles
- R.assign "cols", @cols
- R.eval "m <-rbind("+@rows.join(",")+")"
- R.assign "my_names", value_names
- R.assign "my_ylim", y_axis_scale
- R.eval 'barplot(m, beside = TRUE, col = cols, names=my_names, legend=titles, ylim = my_ylim)'
- end
-end
-
diff --git a/report/report_factory.rb b/report/report_factory.rb
index 4331660..e577d70 100644
--- a/report/report_factory.rb
+++ b/report/report_factory.rb
@@ -244,7 +244,6 @@ class Reports::ReportContent
@xml_report.add_imagefigure(section_roc, image_title, plot_file_name, "SVG", image_caption)
rescue RuntimeError => ex
LOGGER.error("could not create roc plot: "+ex.message)
- LOGGER.debug("if R cannot find your libs, try adding R_LIBS='<lib>' to your ~/.Renviron file")
rm_tmp_file(plot_file_name)
@xml_report.add_paragraph(section_roc, "could not create roc plot: "+ex.message)
end
@@ -297,7 +296,7 @@ class Reports::ReportContent
@xml_report.add_paragraph(section_bar, section_text) if section_text
plot_file_path = add_tmp_file(plot_file_name)
- Reports::RPlotFactory.create_bar_plot(plot_file_path, validation_set, class_value, title_attribute, value_attributes )
+ Reports::PlotFactory.create_bar_plot(plot_file_path, validation_set, class_value, title_attribute, value_attributes )
@xml_report.add_imagefigure(section_bar, image_title, plot_file_name, "SVG", image_caption)
end
diff --git a/validation/validation_test.rb b/validation/validation_test.rb
index 3fe1832..5cfd319 100644
--- a/validation/validation_test.rb
+++ b/validation/validation_test.rb
@@ -166,22 +166,22 @@ class ValidationTest < Test::Unit::TestCase
# end
# end
- def test_split
- begin
- 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
-
- #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
- #verify_validation
- ensure
- #delete_resources
- end
- end
+# def test_split
+# begin
+# 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
+#
+# #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
+# #verify_validation
+# ensure
+# #delete_resources
+# end
+# end
def test_nothing