Class: Evoasm::Population::Plotter
- Inherits:
-
Object
- Object
- Evoasm::Population::Plotter
- Defined in:
- lib/evoasm/population/plotter.rb
Overview
Visualizes the population loss functions using Gnuplot
Constant Summary
- MAX_SAMPLE_COUNT =
16
Instance Method Summary collapse
-
#initialize(population, filename = nil) ⇒ Plotter
constructor
A new instance of Plotter.
-
#plot ⇒ void
Plots (or replots) the current data points.
-
#update ⇒ nil
Updates data points.
Constructor Details
#initialize(population, filename = nil) ⇒ Plotter
Returns a new instance of Plotter
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/evoasm/population/plotter.rb', line 18 def initialize(population, filename = nil) @population = population @pipe = self.class.__open__ if filename case filename when /\.gif$/ @pipe.puts 'set term gif animate delay 20 size 1280, 1024 crop' @pipe.puts %Q{set output "#{filename}"} else raise ArgumentError, "unknown output filetype" end end @pipe.puts 'set xtics' @pipe.puts 'set ytics' @pipe.puts 'set grid' @pipe.puts 'set style fill transparent solid 0.2 noborder' @pipe.puts 'set datafile missing "Infinity"' @pipe.puts 'set lmargin 0.5' @pipe.puts 'set rmargin 0.5' @pipe.puts 'set tmargin 0.5' @pipe.puts 'set bmargin 0.5' @deme_count = @population.parameters.deme_count @sample_tail = 0 @sample_count = 0 @data = Array.new(@deme_count) { Array.new MAX_SAMPLE_COUNT } end |
Instance Method Details
#plot ⇒ void
This method returns an undefined value.
Plots (or replots) the current data points
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/evoasm/population/plotter.rb', line 65 def plot @pipe.puts "set multiplot layout 1, #{@deme_count}" key = true @deme_count.times do |deme_index| deme_summary = @data[deme_index] @pipe.puts "set key #{key ? 'on' : 'off'}" key = false @pipe.write %Q{plot '-' using 1:2:3 with filledcurves title 'IQR'} @pipe.write %Q{ ,'-' using 1:2 with lp title 'Min'} @pipe.write %Q{ ,'-' using 1:2:(sprintf("%.2f", $2)) with labels center offset 2,0.6 notitle} @pipe.write %Q{ ,'-' using 1:2 with lp lt 1 pt 5 ps 1.5 lw 2 title 'Median'} @pipe.write %Q{ ,'-' using 1:2:(sprintf("%.2f", $2)) with labels center offset 2,1 notitle} @pipe.puts write_samples deme_summary, 0, 2, 4 write_samples deme_summary, 0, 1 write_samples deme_summary, 0, 1 write_samples deme_summary, 0, 3 write_samples deme_summary, 0, 3 end @pipe.puts "unset multiplot" @pipe.flush end |
#update ⇒ nil
Updates data points
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/evoasm/population/plotter.rb', line 51 def update summary = @population.summary summary.each_with_index do |deme_summary, deme_index| deme_samples = @data[deme_index] deme_samples[@sample_tail] = [@population.generation] + deme_summary end @sample_count = [@sample_count + 1, MAX_SAMPLE_COUNT].min @sample_tail = (@sample_tail + 1) % MAX_SAMPLE_COUNT end |