summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormguetlein <martin.guetlein@gmail.com>2011-05-23 10:51:29 +0200
committermguetlein <martin.guetlein@gmail.com>2011-05-23 10:51:29 +0200
commit86a1d1e5fda994bc318100963b5fe7af3da24a53 (patch)
treeee7f9864b7af78b12b069a83c4633f7b6f6dda91
parent452f119ae9e15ac51c4ed09367b6eab9f4392beb (diff)
new feature: zoom into plots; (png-)plots in reports link to identical svg-plots
-rw-r--r--report/plot_factory.rb47
-rwxr-xr-xreport/report_content.rb44
-rwxr-xr-xreport/xml_report.rb25
3 files changed, 64 insertions, 52 deletions
diff --git a/report/plot_factory.rb b/report/plot_factory.rb
index 7535eb4..2a621f4 100644
--- a/report/plot_factory.rb
+++ b/report/plot_factory.rb
@@ -52,9 +52,10 @@ module Reports
module PlotFactory
- def self.create_regression_plot( out_file, validation_set, name_attribute )
+ def self.create_regression_plot( out_files, validation_set, name_attribute )
- LOGGER.debug "Creating regression plot, out-file:"+out_file.to_s
+ out_files = [out_files] unless out_files.is_a?(Array)
+ LOGGER.debug "Creating regression plot, out-file:"+out_files.to_s
names = []
x = []
@@ -79,7 +80,9 @@ module Reports
end
raise "no predictions performed" if x.size==0 || x[0].size==0
- RubyPlot::regression_point_plot(out_file, "Regression plot", "Predicted values", "Actual values", names, x, y )
+ out_files.each do |out_file|
+ RubyPlot::regression_point_plot(out_file, "Regression plot", "Predicted values", "Actual values", names, x, y )
+ end
end
@@ -91,10 +94,11 @@ module Reports
# * the validation set is splitted into sets of validation_sets with equal attribute values
# * each of theses validation sets is plotted as a roc-curve
#
- def self.create_roc_plot( out_file, validation_set, class_value, split_set_attribute=nil,
+ def self.create_roc_plot( out_files, validation_set, class_value, split_set_attribute=nil,
x_label="False positive rate", y_label="True Positive Rate", show_single_curves=false )
- LOGGER.debug "creating roc plot for '"+validation_set.size.to_s+"' validations, out-file:"+out_file.to_s
+ out_files = [out_files] unless out_files.is_a?(Array)
+ LOGGER.debug "creating roc plot for '"+validation_set.size.to_s+"' validations, out-files:"+out_files.inspect
if split_set_attribute
attribute_values = validation_set.get_values(split_set_attribute)
@@ -120,14 +124,17 @@ module Reports
labels << ["confidence: "+confidence.to_nice_s, point[0], point[1]]
end
end
- RubyPlot::plot_lines(out_file, "ROC-Plot", x_label, y_label, data[:names], data[:fp_rate], data[:tp_rate], data[:faint], labels )
+ out_files.each do |out_file|
+ RubyPlot::plot_lines(out_file, "ROC-Plot", x_label, y_label, data[:names], data[:fp_rate], data[:tp_rate], data[:faint], labels )
+ end
end
end
- def self.create_confidence_plot( out_file, validation_set, class_value, split_set_attribute=nil, show_single_curves=false )
+ def self.create_confidence_plot( out_files, validation_set, class_value, split_set_attribute=nil, show_single_curves=false )
- LOGGER.debug "creating confidence plot for '"+validation_set.size.to_s+"' validations, out-file:"+out_file.to_s
+ out_files = [out_files] unless out_files.is_a?(Array)
+ LOGGER.debug "creating confidence plot for '"+validation_set.size.to_s+"' validations, out-file:"+out_files.inspect
if split_set_attribute
attribute_values = validation_set.get_values(split_set_attribute)
@@ -145,19 +152,23 @@ module Reports
end
end
#RubyPlot::plot_lines(out_file, "Percent Correct vs Confidence Plot", "Confidence", "Percent Correct", names, fp_rates, tp_rates )
- case validation_set.unique_feature_type
- when "classification"
- RubyPlot::accuracy_confidence_plot(out_file, "Percent Correct vs Confidence Plot", "Confidence", "Percent Correct", names, confidence, performance)
- when "regression"
- RubyPlot::accuracy_confidence_plot(out_file, "RMSE vs Confidence Plot", "Confidence", "RMSE", names, confidence, performance, true)
+ out_files.each do |out_file|
+ case validation_set.unique_feature_type
+ when "classification"
+ RubyPlot::accuracy_confidence_plot(out_file, "Percent Correct vs Confidence Plot", "Confidence", "Percent Correct", names, confidence, performance)
+ when "regression"
+ RubyPlot::accuracy_confidence_plot(out_file, "RMSE vs Confidence Plot", "Confidence", "RMSE", names, confidence, performance, true)
+ end
end
else
data = transform_confidence_predictions(validation_set, class_value, show_single_curves)
- case validation_set.unique_feature_type
- when "classification"
- RubyPlot::accuracy_confidence_plot(out_file, "Percent Correct vs Confidence Plot", "Confidence", "Percent Correct", data[:names], data[:confidence], data[:performance])
- when "regression"
- RubyPlot::accuracy_confidence_plot(out_file, "RMSE vs Confidence Plot", "Confidence", "RMSE", data[:names], data[:confidence], data[:performance], true)
+ out_files.each do |out_file|
+ case validation_set.unique_feature_type
+ when "classification"
+ RubyPlot::accuracy_confidence_plot(out_file, "Percent Correct vs Confidence Plot", "Confidence", "Percent Correct", data[:names], data[:confidence], data[:performance])
+ when "regression"
+ RubyPlot::accuracy_confidence_plot(out_file, "RMSE vs Confidence Plot", "Confidence", "RMSE", data[:names], data[:confidence], data[:performance], true)
+ end
end
end
end
diff --git a/report/report_content.rb b/report/report_content.rb
index 893ac34..a8b700b 100755
--- a/report/report_content.rb
+++ b/report/report_content.rb
@@ -133,8 +133,7 @@ class Reports::ReportContent
name_attribute,
section_title="Regression Plot",
section_text=nil,
- image_title=nil,
- image_caption=nil)
+ image_title=nil)
image_title = "Regression plot" unless image_title
#section_regr = @xml_report.add_section(@current_section, section_title)
@@ -145,12 +144,11 @@ class Reports::ReportContent
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
- plot_file_name = "regr_plot"+@tmp_file_count.to_s+".png"
- @tmp_file_count += 1
begin
- plot_file_path = add_tmp_file(plot_file_name)
- Reports::PlotFactory.create_regression_plot( plot_file_path, prediction_set, name_attribute )
- @xml_report.add_imagefigure(section_regr, image_title, plot_file_name, "PNG", 100, image_caption)
+ plot_png = add_tmp_file("regr_plot", "png")
+ plot_svg = add_tmp_file("regr_plot", "svg")
+ Reports::PlotFactory.create_regression_plot( [plot_png[:path], plot_svg[:path]], prediction_set, name_attribute )
+ @xml_report.add_imagefigure(section_regr, image_title, plot_png[:name], "PNG", 100, plot_svg[:name])
rescue Exception => ex
LOGGER.error("Could not create regression plot: "+ex.message)
rm_tmp_file(plot_file_name)
@@ -179,15 +177,14 @@ class Reports::ReportContent
"validation set size: "+validation_set.size.to_s+", prediction set size: "+prediction_set.size.to_s
end
@xml_report.add_paragraph(section_roc, section_text) if section_text
- plot_file_name = "roc_plot"+@tmp_file_count.to_s+".png"
- @tmp_file_count += 1
begin
- plot_file_path = add_tmp_file(plot_file_name)
- Reports::PlotFactory.create_roc_plot( plot_file_path, prediction_set, accept_value, split_set_attribute )#prediction_set.size>1 )
- @xml_report.add_imagefigure(section_roc, image_title, plot_file_name, "PNG", 100, image_caption)
+ plot_png = add_tmp_file("roc_plot", "png")
+ plot_svg = add_tmp_file("roc_plot", "svg")
+ Reports::PlotFactory.create_roc_plot( [plot_png[:path], plot_svg[:path]], prediction_set, accept_value, split_set_attribute )#prediction_set.size>1 )
+ @xml_report.add_imagefigure(section_roc, image_title, plot_png[:name], "PNG", 100, plot_svg[:name])
rescue Exception => ex
msg = "WARNING could not create roc plot for class value '"+accept_value.to_s+"': "+ex.message
- LOGGER.error(msg)
+ #LOGGER.error(msg)
rm_tmp_file(plot_file_name)
@xml_report.add_paragraph(section_roc, msg)
end
@@ -201,8 +198,7 @@ class Reports::ReportContent
accept_value = nil,
split_set_attribute = nil,
image_title = "Percent Correct vs Confidence Plot",
- section_text=nil,
- image_caption=nil)
+ section_text="")
#section_conf = @xml_report.add_section(@current_section, section_title)
section_conf = @current_section
@@ -214,14 +210,13 @@ class Reports::ReportContent
LOGGER.error "WARNING: plot information not available for all validation results:\n"+
"validation set size: "+validation_set.size.to_s+", prediction set size: "+prediction_set.size.to_s
end
- @xml_report.add_paragraph(section_conf, section_text) if section_text
+ @xml_report.add_paragraph(section_conf, section_text) if section_text and section_text.size>0
- plot_file_name = "conf_plot"+@tmp_file_count.to_s+".png"
- @tmp_file_count += 1
begin
- plot_file_path = add_tmp_file(plot_file_name)
- Reports::PlotFactory.create_confidence_plot( plot_file_path, prediction_set, accept_value, split_set_attribute, false )
- @xml_report.add_imagefigure(section_conf, image_title, plot_file_name, "PNG", 100, image_caption)
+ plot_png = add_tmp_file("conf_plot", "png")
+ plot_svg = add_tmp_file("conf_plot", "svg")
+ Reports::PlotFactory.create_confidence_plot( [plot_png[:path], plot_svg[:path]], prediction_set, accept_value, split_set_attribute, false )
+ @xml_report.add_imagefigure(section_conf, image_title, plot_png[:name], "PNG", 100, plot_svg[:name])
rescue Exception => ex
msg = "WARNING could not create confidence plot: "+ex.message
LOGGER.error(msg)
@@ -298,13 +293,14 @@ class Reports::ReportContent
end
private
- def add_tmp_file(tmp_file_name)
-
+ def add_tmp_file(name, extension)
+ tmp_file_name = name.to_s+@tmp_file_count.to_s+"."+extension.to_s
+ @tmp_file_count += 1
@tmp_files = {} unless @tmp_files
raise "file name already exits" if @tmp_files[tmp_file_name] || (@text_files && @text_files[tmp_file_name])
tmp_file_path = Reports::Util.create_tmp_file(tmp_file_name)
@tmp_files[tmp_file_name] = tmp_file_path
- return tmp_file_path
+ return {:name => tmp_file_name, :path => tmp_file_path}
end
def rm_tmp_file(tmp_file_name)
diff --git a/report/xml_report.rb b/report/xml_report.rb
index cf30e3b..855a65e 100755
--- a/report/xml_report.rb
+++ b/report/xml_report.rb
@@ -93,10 +93,12 @@ module Reports
end
end
- def imagefigure( title, path, filetype, size_pct=100, caption = nil )
+ def imagefigure( title, path, filetype, size_pct=100, altPath = nil )
figure = Reports::XMLReportUtil.attribute_element("figure", {"float" => 0})
figure << Reports::XMLReportUtil.text_element("title", title)
- media = Element.new("mediaobject")
+
+ #media = Element.new("mediaobject")
+ media = Element.new("inlinemediaobject")
image = Element.new("imageobject")
imagedata = Reports::XMLReportUtil.attribute_element("imagedata",
{"fileref" => path, "format"=>filetype, "contentwidth" => size_pct.to_s+"%",
@@ -106,12 +108,15 @@ module Reports
@resource_path_elements[imagedata] = "fileref"
image << imagedata
media << image
-# ulink = Element.new("ulink")
-# ulink.add_attributes({"url" => "http://google.de"})
-# ulink << image
-# media << ulink
- media << Reports::XMLReportUtil.text_element("caption", caption) if caption
- figure << media
+ #media << Reports::XMLReportUtil.text_element("caption", caption) if caption
+ #figure << media
+
+ ulink = Element.new("ulink")
+ ulink.add_attributes({"url" => altPath ? altPath : path })
+ @resource_path_elements[ulink] = "url"
+ ulink << media
+
+ figure << ulink
figure
end
@@ -122,8 +127,8 @@ module Reports
# call-seq:
# add_imagefigure( element, title, path, filetype, caption = nil ) => REXML::Element
#
- def add_imagefigure( element, title, path, filetype, size_pct=100, caption = nil )
- figure = imagefigure( title, path, filetype, size_pct, caption)
+ def add_imagefigure( element, title, path, filetype, size_pct=100, altPath = nil )
+ figure = imagefigure( title, path, filetype, size_pct, altPath)
element << figure
return figure
end