#!/usr/local/bin/ruby require "GSL" include GSL include GSL::Histogram # Test 2D histogramms STDERR.puts "Running tests for 2D histograms..." h = Hist2D.new(10, 10) h.set_ranges_uniform(0.0, 1.0, 0.0, 1.0) h.accumulate(0.3, 0.3, 1) h.accumulate(0.8, 0.1, 5) h.accumulate(0.7, 0.9, 0.5) #puts "\nA simple 2D Histogram:" #h.fprintf(STDOUT, "%g", "%g") #h2 = Hist2D.new(10, 10) #Hist2D::memcpy(h2, h) #puts "\nDeep copy:" #h2.fprintf(STDOUT, "%g", "%g") r = Random::RNG.new p = Hist2D_PDF.new(h) i = 0 while (i < 1000) i += 1 u = r.uniform v = r.uniform x, y = p.sample(u, v) printf "%g %g\n", x, y end STDERR.printf "\n xmean: %f\n", h.xmean STDERR.printf " ymean: %f\n", h.ymean STDERR.printf " xsigma: %f\n", h.xsigma STDERR.printf " ysigma: %f\n", h.ysigma STDERR.printf " cov: %f\n", h.cov STDERR.printf " sum: %f\n", h.sum # h.fprintf(STDOUT, "%g", "%g") STDERR.puts "\ndone."