/usr/share/doc/ruby-gsl/examples/histogram/power.rb is in ruby-gsl 2.1.0.3+dfsg1-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #!/usr/bin/env ruby
require("gsl")
include Math
def ran_power_law(slope, range, rng)
x = rng.uniform
xmin = GSL::pow(10.0, range*(1.0 + slope));
x2 = (1 - xmin)*x + xmin;
return GSL::pow(x2, 1.0/(1+slope));
end
h = GSL::Histogram.alloc(19, [1, 20])
rng = GSL::Rng.alloc
for i in 0..5000
x = ran_power_law(-3.2, 1000, rng)
h.increment(x)
end
result = h.fit_power
x = GSL::Vector.logspace2(1, 20, 19)
y = result[0]*GSL::pow(x, result[1])
GSL::graph(h, [x, y], "-l x -l y -x 1 20 -y 1 10000 -C -g 3")
puts("Expected power index: -3.2")
printf("Estimated power index: %5.4f +/- %5.4f\n", result[1], result[3])
|