Numerical Ruby - Segmentation faults, GSL trouble

Dear all,

I have to determine the minima of a multiparameter mathematical
function
numerically.
I try to use the simplex method, as implemented in Ruby-Gsl, to do
this.

Below is some code from an example as given in the documentation of
Ruby/Gsl.
However, when I run this on Cygwin (Windows XP), I get a segmentation
fault
from the line where the parameters are set, whereas in Fedora, I am not
allowed
to allocate even the function to minimize.

Has anybody had this problem before ? Has anybody some self-written
code
for multidimensional minimization (preferably simplex method)?

Thank you very much in advance,

Best regards

Axel



#!/usr/bin/env ruby

require(“gsl”)

include GSL::MultiMin

np = 2

my_f = Proc.new { |v, params|

x = v[0]; y = v[1]

p0 = params[0]; p1 = params[1]

10.0*(x - p0)(x - p0) + 20.0(y - p1)*(y - p1) + 30.0

}

my_func = Function.alloc(my_f, np) # ERROR in Fedora: undefined
method
`alloc’ for GSL::MultiMin::FMinimizer:Class (NoMethodError)

my_func.set_params([1.0, 2.0]) # parameters: SEGMENTATION fault in
Fedora.

x = Vector.alloc([5, 7])

ss = Vector.alloc(np)

ss.set_all(1.0)

minimizer = FMinimizer.alloc(“nmsimplex”, np)

minimizer.set(my_func, x, ss)

iter = 0

begin

iter += 1

status = minimizer.iterate()

status = minimizer.test_size(1e-2)

if status == GSL::SUCCESS

puts("converged to minimum at")

end

x = minimizer.x

printf("%5d ", iter);

for i in 0…np do

printf("%10.3e ", x[i])

end

printf(“f() = %7.3f size = %.3f\n”, minimizer.fval, minimizer.size);

end while status == GSL::CONTINUE and iter < 100

On Sun, 7 May 2006 [email protected] wrote:

to allocate even the function to minimize.

Has anybody had this problem before ? Has anybody some self-written code
for multidimensional minimization (preferably simplex method)?

Thank you very much in advance,

Best regards

Axel

as to your first question, here are the results of running your code on
my
machine:

jib:~ > ruby a.rb
1 6.500e+00 5.000e+00 f() = 512.500 size = 1.082
2 5.250e+00 4.000e+00 f() = 290.625 size = 1.372
3 5.250e+00 4.000e+00 f() = 290.625 size = 1.372
4 5.500e+00 1.000e+00 f() = 252.500 size = 1.372
5 2.625e+00 3.500e+00 f() = 101.406 size = 1.823
6 2.625e+00 3.500e+00 f() = 101.406 size = 1.823
7 0.000e+00 3.000e+00 f() = 60.000 size = 1.823
8 2.094e+00 1.875e+00 f() = 42.275 size = 1.303
9 2.094e+00 1.875e+00 f() = 42.275 size = 1.303
10 2.578e-01 1.906e+00 f() = 35.684 size = 1.026
11 5.879e-01 2.445e+00 f() = 35.664 size = 0.804
12 1.258e+00 2.025e+00 f() = 30.680 size = 0.467
13 1.258e+00 2.025e+00 f() = 30.680 size = 0.356
14 1.093e+00 1.849e+00 f() = 30.539 size = 0.285
15 8.830e-01 2.004e+00 f() = 30.137 size = 0.168
16 8.830e-01 2.004e+00 f() = 30.137 size = 0.123
17 9.582e-01 2.060e+00 f() = 30.090 size = 0.100
18 1.022e+00 2.004e+00 f() = 30.005 size = 0.061
19 1.022e+00 2.004e+00 f() = 30.005 size = 0.042
20 1.022e+00 2.004e+00 f() = 30.005 size = 0.042
21 1.022e+00 2.004e+00 f() = 30.005 size = 0.027
22 1.022e+00 2.004e+00 f() = 30.005 size = 0.021
23 9.920e-01 1.997e+00 f() = 30.001 size = 0.015
24 9.920e-01 1.997e+00 f() = 30.001 size = 0.013
converged to minimum at
25 9.920e-01 1.997e+00 f() = 30.001 size = 0.008

your code was 100% un-modified. so i think your install isn’t good. i
just
installed the latest gsl, plotutils, and rb-gsl using

export prefix=/dmsp/reference/
export LD_RUN_PATH=$prefix/lib
export LD_LIBRARY_PATH=$prefix/lib

for gsl : ./configure --prefix=$prefix && make && make install
for plotutils : ./configure --prefix=$prefix && make && make install
for rb-gsl : for w in config setup install;do ruby setup.rb
$w;done

eg. nothing special at all.

so, sorry to say, it looks like you install is fubar. btw. my platform
is

jib:~ > uname -srm && cat /etc/redhat-release && ruby -v
Linux 2.4.21-40.ELsmp i686
Red Hat Enterprise Linux WS release 3 (Taroon Update 7)
ruby 1.8.1 (2003-12-25) [i686-linux]

so, while it’s not fedora, i’d be very suprised if it didn’t work there
too.

regards.

-a