gsl 1.12.108
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +29 -0
- data/Rakefile +54 -0
- data/VERSION +2 -0
- data/ext/MANIFEST +119 -0
- data/ext/alf.c +206 -0
- data/ext/array.c +666 -0
- data/ext/array_complex.c +247 -0
- data/ext/blas.c +29 -0
- data/ext/blas1.c +731 -0
- data/ext/blas2.c +1093 -0
- data/ext/blas3.c +881 -0
- data/ext/block.c +44 -0
- data/ext/block_source.c +886 -0
- data/ext/bspline.c +130 -0
- data/ext/bundle.c +3 -0
- data/ext/cdf.c +754 -0
- data/ext/cheb.c +542 -0
- data/ext/combination.c +283 -0
- data/ext/common.c +325 -0
- data/ext/complex.c +1004 -0
- data/ext/const.c +673 -0
- data/ext/const_additional.c +120 -0
- data/ext/cqp.c +283 -0
- data/ext/deriv.c +195 -0
- data/ext/dht.c +361 -0
- data/ext/diff.c +166 -0
- data/ext/dirac.c +395 -0
- data/ext/eigen.c +2373 -0
- data/ext/error.c +194 -0
- data/ext/extconf.rb +281 -0
- data/ext/fcmp.c +66 -0
- data/ext/fft.c +1092 -0
- data/ext/fit.c +205 -0
- data/ext/fresnel.c +312 -0
- data/ext/function.c +524 -0
- data/ext/geometry.c +139 -0
- data/ext/graph.c +1638 -0
- data/ext/gsl.c +271 -0
- data/ext/gsl_narray.c +653 -0
- data/ext/histogram.c +1995 -0
- data/ext/histogram2d.c +1068 -0
- data/ext/histogram3d.c +884 -0
- data/ext/histogram3d_source.c +750 -0
- data/ext/histogram_find.c +101 -0
- data/ext/histogram_oper.c +159 -0
- data/ext/ieee.c +98 -0
- data/ext/integration.c +1138 -0
- data/ext/interp.c +512 -0
- data/ext/jacobi.c +739 -0
- data/ext/linalg.c +4047 -0
- data/ext/linalg_complex.c +741 -0
- data/ext/math.c +725 -0
- data/ext/matrix.c +39 -0
- data/ext/matrix_complex.c +1732 -0
- data/ext/matrix_double.c +560 -0
- data/ext/matrix_int.c +256 -0
- data/ext/matrix_source.c +2733 -0
- data/ext/min.c +250 -0
- data/ext/monte.c +992 -0
- data/ext/multifit.c +1879 -0
- data/ext/multimin.c +808 -0
- data/ext/multimin_fsdf.c +156 -0
- data/ext/multiroots.c +955 -0
- data/ext/ndlinear.c +321 -0
- data/ext/nmf.c +167 -0
- data/ext/nmf_wrap.c +72 -0
- data/ext/ntuple.c +469 -0
- data/ext/odeiv.c +959 -0
- data/ext/ool.c +879 -0
- data/ext/oper_complex_source.c +253 -0
- data/ext/permutation.c +596 -0
- data/ext/poly.c +42 -0
- data/ext/poly2.c +265 -0
- data/ext/poly_source.c +1885 -0
- data/ext/qrng.c +171 -0
- data/ext/randist.c +1873 -0
- data/ext/rational.c +480 -0
- data/ext/rng.c +612 -0
- data/ext/root.c +408 -0
- data/ext/sf.c +1494 -0
- data/ext/sf_airy.c +200 -0
- data/ext/sf_bessel.c +867 -0
- data/ext/sf_clausen.c +28 -0
- data/ext/sf_coulomb.c +206 -0
- data/ext/sf_coupling.c +118 -0
- data/ext/sf_dawson.c +29 -0
- data/ext/sf_debye.c +157 -0
- data/ext/sf_dilog.c +42 -0
- data/ext/sf_elementary.c +44 -0
- data/ext/sf_ellint.c +206 -0
- data/ext/sf_elljac.c +29 -0
- data/ext/sf_erfc.c +93 -0
- data/ext/sf_exp.c +164 -0
- data/ext/sf_expint.c +211 -0
- data/ext/sf_fermi_dirac.c +148 -0
- data/ext/sf_gamma.c +344 -0
- data/ext/sf_gegenbauer.c +96 -0
- data/ext/sf_hyperg.c +197 -0
- data/ext/sf_laguerre.c +112 -0
- data/ext/sf_lambert.c +47 -0
- data/ext/sf_legendre.c +367 -0
- data/ext/sf_log.c +104 -0
- data/ext/sf_mathieu.c +238 -0
- data/ext/sf_power.c +46 -0
- data/ext/sf_psi.c +98 -0
- data/ext/sf_synchrotron.c +48 -0
- data/ext/sf_transport.c +76 -0
- data/ext/sf_trigonometric.c +207 -0
- data/ext/sf_zeta.c +119 -0
- data/ext/signal.c +310 -0
- data/ext/siman.c +718 -0
- data/ext/sort.c +208 -0
- data/ext/spline.c +395 -0
- data/ext/stats.c +799 -0
- data/ext/sum.c +168 -0
- data/ext/tamu_anova.c +56 -0
- data/ext/tensor.c +38 -0
- data/ext/tensor_source.c +1123 -0
- data/ext/vector.c +38 -0
- data/ext/vector_complex.c +2236 -0
- data/ext/vector_double.c +1433 -0
- data/ext/vector_int.c +204 -0
- data/ext/vector_source.c +3329 -0
- data/ext/wavelet.c +937 -0
- data/include/rb_gsl.h +151 -0
- data/include/rb_gsl_array.h +238 -0
- data/include/rb_gsl_cheb.h +21 -0
- data/include/rb_gsl_common.h +343 -0
- data/include/rb_gsl_complex.h +25 -0
- data/include/rb_gsl_const.h +29 -0
- data/include/rb_gsl_dirac.h +13 -0
- data/include/rb_gsl_eigen.h +17 -0
- data/include/rb_gsl_fft.h +62 -0
- data/include/rb_gsl_fit.h +25 -0
- data/include/rb_gsl_function.h +27 -0
- data/include/rb_gsl_graph.h +70 -0
- data/include/rb_gsl_histogram.h +63 -0
- data/include/rb_gsl_histogram3d.h +97 -0
- data/include/rb_gsl_integration.h +17 -0
- data/include/rb_gsl_interp.h +46 -0
- data/include/rb_gsl_linalg.h +25 -0
- data/include/rb_gsl_math.h +26 -0
- data/include/rb_gsl_odeiv.h +21 -0
- data/include/rb_gsl_poly.h +71 -0
- data/include/rb_gsl_rational.h +37 -0
- data/include/rb_gsl_rng.h +21 -0
- data/include/rb_gsl_root.h +22 -0
- data/include/rb_gsl_sf.h +119 -0
- data/include/rb_gsl_statistics.h +17 -0
- data/include/rb_gsl_tensor.h +45 -0
- data/include/rb_gsl_with_narray.h +22 -0
- data/include/templates_off.h +87 -0
- data/include/templates_on.h +241 -0
- data/lib/gsl/gnuplot.rb +41 -0
- data/lib/gsl/oper.rb +68 -0
- data/lib/ool.rb +22 -0
- data/lib/ool/conmin.rb +30 -0
- metadata +224 -0
data/ext/multimin.c
ADDED
@@ -0,0 +1,808 @@
|
|
1
|
+
/*
|
2
|
+
multimin.c
|
3
|
+
Ruby/GSL: Ruby extension library for GSL (GNU Scientific Library)
|
4
|
+
(C) Copyright 2004 by Yoshiki Tsunesada
|
5
|
+
|
6
|
+
Ruby/GSL is free software: you can redistribute it and/or modify it
|
7
|
+
under the terms of the GNU General Public License.
|
8
|
+
This library is distributed in the hope that it will be useful, but
|
9
|
+
WITHOUT ANY WARRANTY.
|
10
|
+
*/
|
11
|
+
|
12
|
+
#include "rb_gsl.h"
|
13
|
+
#include "rb_gsl_array.h"
|
14
|
+
#include "rb_gsl_function.h"
|
15
|
+
#include <gsl/gsl_multimin.h>
|
16
|
+
|
17
|
+
#ifndef CHECK_MULTIMIN_FUNCTION
|
18
|
+
#define CHECK_MULTIMIN_FUNCTION(x) if(CLASS_OF(x)!=cgsl_multimin_function)\
|
19
|
+
rb_raise(rb_eTypeError,\
|
20
|
+
"wrong argument type %s (GSL::MultiMin::Function expected)",\
|
21
|
+
rb_class2name(CLASS_OF(x)));
|
22
|
+
#endif
|
23
|
+
|
24
|
+
#ifndef CHECK_MULTIMIN_FUNCTION_FDF
|
25
|
+
#define CHECK_MULTIMIN_FUNCTION_FDF(x) if(CLASS_OF(x)!=cgsl_multimin_function_fdf)\
|
26
|
+
rb_raise(rb_eTypeError,\
|
27
|
+
"wrong argument type %s (GSL::MultiMin::Function_fdf expected)",\
|
28
|
+
rb_class2name(CLASS_OF(x)));
|
29
|
+
#endif
|
30
|
+
|
31
|
+
VALUE cgsl_multimin_function_fdf; /* Used also in multimin_fsdf.c */
|
32
|
+
static VALUE cgsl_multimin_function;
|
33
|
+
|
34
|
+
enum {
|
35
|
+
GSL_FDFMINIMIZER_CONJUGATE_FR,
|
36
|
+
GSL_FDFMINIMIZER_CONJUGATE_PR,
|
37
|
+
GSL_FDFMINIMIZER_VECTOR_BFGS,
|
38
|
+
GSL_FDFMINIMIZER_STEEPEST_DESCENT,
|
39
|
+
GSL_FMINIMIZER_NMSIMPLEX,
|
40
|
+
#ifdef GSL_1_9_LATER
|
41
|
+
GSL_FDFMINIMIZER_VECTOR_BFGS2,
|
42
|
+
#endif
|
43
|
+
#ifdef GSL_1_13_LATER
|
44
|
+
GSL_FMINIMIZER_NMSIMPLEX2RAND,
|
45
|
+
#endif
|
46
|
+
};
|
47
|
+
|
48
|
+
static const gsl_multimin_fdfminimizer_type* get_fdfminimizer_type(VALUE t);
|
49
|
+
#ifdef GSL_1_3_LATER
|
50
|
+
static const gsl_multimin_fminimizer_type* get_fminimizer_type(VALUE t);
|
51
|
+
#endif
|
52
|
+
static void define_const();
|
53
|
+
|
54
|
+
static void gsl_multimin_function_free(gsl_multimin_function *f);
|
55
|
+
static double rb_gsl_multimin_function_f(const gsl_vector *x, void *p);
|
56
|
+
static void set_function(int i, VALUE *argv, gsl_multimin_function *F);
|
57
|
+
|
58
|
+
static void gsl_multimin_function_fdf_free(gsl_multimin_function_fdf *f);
|
59
|
+
|
60
|
+
double rb_gsl_multimin_function_fdf_f(const gsl_vector *x, void *p);
|
61
|
+
void rb_gsl_multimin_function_fdf_df(const gsl_vector *x, void *p,
|
62
|
+
gsl_vector *g);
|
63
|
+
void rb_gsl_multimin_function_fdf_fdf(const gsl_vector *x, void *p,
|
64
|
+
double *f, gsl_vector *g);
|
65
|
+
static void set_function_fdf(int i, VALUE *argv, gsl_multimin_function_fdf *F);
|
66
|
+
|
67
|
+
/*** multimin_funcion ***/
|
68
|
+
static void gsl_multimin_function_mark(gsl_multimin_function *F);
|
69
|
+
static void gsl_multimin_function_fdf_mark(gsl_multimin_function_fdf *F);
|
70
|
+
|
71
|
+
static void gsl_multimin_function_mark(gsl_multimin_function *F)
|
72
|
+
{
|
73
|
+
rb_gc_mark((VALUE) F->params);
|
74
|
+
}
|
75
|
+
|
76
|
+
static void gsl_multimin_function_fdf_mark(gsl_multimin_function_fdf *F)
|
77
|
+
{
|
78
|
+
rb_gc_mark((VALUE) F->params);
|
79
|
+
}
|
80
|
+
|
81
|
+
static VALUE rb_gsl_multimin_function_new(int argc, VALUE *argv, VALUE klass)
|
82
|
+
{
|
83
|
+
gsl_multimin_function *F = NULL;
|
84
|
+
VALUE ary;
|
85
|
+
size_t i;
|
86
|
+
F = ALLOC(gsl_multimin_function);
|
87
|
+
F->f = &rb_gsl_multimin_function_f;
|
88
|
+
ary = rb_ary_new2(2);
|
89
|
+
/* (VALUE) F->params = ary;*/
|
90
|
+
F->params = (void *) ary;
|
91
|
+
if (rb_block_given_p()) rb_ary_store(ary, 0, RB_GSL_MAKE_PROC);
|
92
|
+
else rb_ary_store(ary, 0, Qnil);
|
93
|
+
rb_ary_store(ary, 1, Qnil);
|
94
|
+
switch (argc) {
|
95
|
+
case 0:
|
96
|
+
break;
|
97
|
+
case 1:
|
98
|
+
set_function(0, argv, F);
|
99
|
+
break;
|
100
|
+
case 2:
|
101
|
+
case 3:
|
102
|
+
for (i = 0; i < argc; i++) set_function(i, argv, F);
|
103
|
+
break;
|
104
|
+
default:
|
105
|
+
rb_raise(rb_eArgError, "wrong number of arguments");
|
106
|
+
}
|
107
|
+
return Data_Wrap_Struct(klass, gsl_multimin_function_mark, gsl_multimin_function_free, F);
|
108
|
+
}
|
109
|
+
|
110
|
+
static void gsl_multimin_function_free(gsl_multimin_function *f)
|
111
|
+
{
|
112
|
+
free((gsl_multimin_function *) f);
|
113
|
+
}
|
114
|
+
|
115
|
+
static VALUE rb_gsl_multimin_function_n(VALUE obj)
|
116
|
+
{
|
117
|
+
gsl_multimin_function *F = NULL;
|
118
|
+
Data_Get_Struct(obj, gsl_multimin_function, F);
|
119
|
+
return INT2FIX(F->n);
|
120
|
+
}
|
121
|
+
|
122
|
+
static double rb_gsl_multimin_function_f(const gsl_vector *x, void *p)
|
123
|
+
{
|
124
|
+
VALUE vx, vp, proc, result;
|
125
|
+
vx = Data_Wrap_Struct(cgsl_vector, 0, NULL, (gsl_vector *) x);
|
126
|
+
proc = rb_ary_entry((VALUE) p, 0);
|
127
|
+
vp = rb_ary_entry((VALUE) p, 1);
|
128
|
+
if (NIL_P(vp)) result = rb_funcall(proc, RBGSL_ID_call, 1, vx);
|
129
|
+
else result = rb_funcall(proc, RBGSL_ID_call, 2, vx, vp);
|
130
|
+
return NUM2DBL(result);
|
131
|
+
}
|
132
|
+
|
133
|
+
static VALUE rb_gsl_multimin_function_eval(VALUE obj, VALUE vx)
|
134
|
+
{
|
135
|
+
gsl_multimin_function *F = NULL;
|
136
|
+
VALUE vp, proc, ary, result;
|
137
|
+
Data_Get_Struct(obj, gsl_multimin_function, F);
|
138
|
+
ary = (VALUE) F->params;
|
139
|
+
proc = rb_ary_entry(ary, 0);
|
140
|
+
vp = rb_ary_entry(ary, 1);
|
141
|
+
if (NIL_P(vp)) result = rb_funcall(proc, RBGSL_ID_call, 1, vx);
|
142
|
+
else result = rb_funcall(proc, RBGSL_ID_call, 2, vx, vp);
|
143
|
+
return result;
|
144
|
+
}
|
145
|
+
|
146
|
+
static void set_function(int i, VALUE *argv, gsl_multimin_function *F)
|
147
|
+
{
|
148
|
+
VALUE ary;
|
149
|
+
ary = (VALUE) F->params;
|
150
|
+
if (TYPE(argv[i]) == T_FIXNUM) F->n = FIX2INT(argv[i]);
|
151
|
+
else if (rb_obj_is_kind_of(argv[i], rb_cProc))
|
152
|
+
rb_ary_store(ary, 0, argv[i]);
|
153
|
+
else if (TYPE(argv[i]) == T_ARRAY || rb_obj_is_kind_of(argv[i], cgsl_vector)
|
154
|
+
|| TYPE(argv[i]) == T_FIXNUM || TYPE(argv[i]) == T_FLOAT) {
|
155
|
+
rb_ary_store(ary, 1, argv[i]);
|
156
|
+
} else {
|
157
|
+
rb_raise(rb_eTypeError, "wrong type of argument %d (Fixnum or Proc)", i);
|
158
|
+
}
|
159
|
+
}
|
160
|
+
|
161
|
+
static VALUE rb_gsl_multimin_function_set_f(int argc, VALUE *argv, VALUE obj)
|
162
|
+
{
|
163
|
+
gsl_multimin_function *F = NULL;
|
164
|
+
VALUE ary;
|
165
|
+
size_t i;
|
166
|
+
Data_Get_Struct(obj, gsl_multimin_function, F);
|
167
|
+
ary = (VALUE) F->params;
|
168
|
+
if (rb_block_given_p()) rb_ary_store(ary, 0, RB_GSL_MAKE_PROC);
|
169
|
+
switch (argc) {
|
170
|
+
case 1:
|
171
|
+
set_function(0, argv, F);
|
172
|
+
break;
|
173
|
+
case 2:
|
174
|
+
case 3:
|
175
|
+
for (i = 0; i < argc; i++) set_function(i, argv, F);
|
176
|
+
break;
|
177
|
+
default:
|
178
|
+
rb_raise(rb_eArgError, "wrong number of arguments");
|
179
|
+
}
|
180
|
+
return obj;
|
181
|
+
}
|
182
|
+
|
183
|
+
static VALUE rb_gsl_multimin_function_set_params(int argc, VALUE *argv, VALUE obj)
|
184
|
+
{
|
185
|
+
gsl_multimin_function *F = NULL;
|
186
|
+
VALUE ary, ary2;
|
187
|
+
size_t i;
|
188
|
+
if (argc == 0) return obj;
|
189
|
+
Data_Get_Struct(obj, gsl_multimin_function, F);
|
190
|
+
if (F->params == NULL) {
|
191
|
+
ary = rb_ary_new2(4);
|
192
|
+
/* (VALUE) F->params = ary;*/
|
193
|
+
F->params = (void *) ary;
|
194
|
+
} else {
|
195
|
+
ary = (VALUE) F->params;
|
196
|
+
}
|
197
|
+
if (argc == 1) rb_ary_store(ary, 1, argv[0]);
|
198
|
+
else {
|
199
|
+
ary2 = rb_ary_new2(argc);
|
200
|
+
for (i = 0; i < argc; i++) rb_ary_store(ary2, i, argv[i]);
|
201
|
+
rb_ary_store(ary, 1, ary2);
|
202
|
+
}
|
203
|
+
return obj;
|
204
|
+
}
|
205
|
+
|
206
|
+
static VALUE rb_gsl_multimin_function_params(VALUE obj)
|
207
|
+
{
|
208
|
+
gsl_multimin_function *F = NULL;
|
209
|
+
Data_Get_Struct(obj, gsl_multimin_function, F);
|
210
|
+
return rb_ary_entry((VALUE) F->params, 1);
|
211
|
+
}
|
212
|
+
|
213
|
+
/*** multimin_function_fdf ***/
|
214
|
+
static void set_function_fdf(int argc, VALUE *argv, gsl_multimin_function_fdf *F);
|
215
|
+
static VALUE rb_gsl_multimin_function_fdf_new(int argc, VALUE *argv, VALUE klass)
|
216
|
+
{
|
217
|
+
gsl_multimin_function_fdf *F = NULL;
|
218
|
+
VALUE ary;
|
219
|
+
F = ALLOC(gsl_multimin_function_fdf);
|
220
|
+
F->f = &rb_gsl_multimin_function_fdf_f;
|
221
|
+
F->df = &rb_gsl_multimin_function_fdf_df;
|
222
|
+
F->fdf = &rb_gsl_multimin_function_fdf_fdf;
|
223
|
+
ary = rb_ary_new2(4);
|
224
|
+
/* (VALUE) F->params = ary;*/
|
225
|
+
F->params = (void *) ary;
|
226
|
+
rb_ary_store(ary, 2, Qnil);
|
227
|
+
rb_ary_store(ary, 3, Qnil);
|
228
|
+
set_function_fdf(argc, argv, F);
|
229
|
+
return Data_Wrap_Struct(klass, gsl_multimin_function_fdf_mark, gsl_multimin_function_fdf_free, F);
|
230
|
+
}
|
231
|
+
|
232
|
+
static void gsl_multimin_function_fdf_free(gsl_multimin_function_fdf *f)
|
233
|
+
{
|
234
|
+
free((gsl_multimin_function_fdf *) f);
|
235
|
+
}
|
236
|
+
|
237
|
+
static VALUE rb_gsl_multimin_function_fdf_n(VALUE obj)
|
238
|
+
{
|
239
|
+
gsl_multimin_function_fdf *F = NULL;
|
240
|
+
Data_Get_Struct(obj, gsl_multimin_function_fdf, F);
|
241
|
+
return INT2FIX(F->n);
|
242
|
+
}
|
243
|
+
|
244
|
+
static void set_function_fdf(int argc, VALUE *argv, gsl_multimin_function_fdf *F)
|
245
|
+
{
|
246
|
+
VALUE ary;
|
247
|
+
if (F->params == NULL) {
|
248
|
+
ary = rb_ary_new2(4);
|
249
|
+
/* (VALUE) F->params = ary;*/
|
250
|
+
F->params = (void *) ary;
|
251
|
+
} else {
|
252
|
+
ary = (VALUE) F->params;
|
253
|
+
}
|
254
|
+
switch (argc) {
|
255
|
+
case 1:
|
256
|
+
if (TYPE(argv[0]) != T_FIXNUM) rb_raise(rb_eTypeError, "Fixnum expected");
|
257
|
+
F->n = FIX2INT(argv[0]);
|
258
|
+
break;
|
259
|
+
case 2:
|
260
|
+
rb_ary_store(ary, 0, argv[0]);
|
261
|
+
rb_ary_store(ary, 1, argv[1]);
|
262
|
+
rb_ary_store(ary, 2, Qnil);
|
263
|
+
break;
|
264
|
+
case 3:
|
265
|
+
rb_ary_store(ary, 0, argv[0]);
|
266
|
+
rb_ary_store(ary, 1, argv[1]);
|
267
|
+
if (TYPE(argv[2]) == T_FIXNUM) {
|
268
|
+
F->n = FIX2INT(argv[2]);
|
269
|
+
rb_ary_store(ary, 2, Qnil);
|
270
|
+
} else {
|
271
|
+
rb_ary_store(ary, 2, argv[2]);
|
272
|
+
}
|
273
|
+
break;
|
274
|
+
case 4:
|
275
|
+
case 5:
|
276
|
+
if (TYPE(argv[0]) == T_FIXNUM) {
|
277
|
+
F->n = FIX2INT(argv[0]);
|
278
|
+
rb_ary_store(ary, 0, argv[1]);
|
279
|
+
rb_ary_store(ary, 1, argv[2]);
|
280
|
+
rb_ary_store(ary, 2, argv[3]);
|
281
|
+
} else {
|
282
|
+
rb_ary_store(ary, 0, argv[0]);
|
283
|
+
rb_ary_store(ary, 1, argv[1]);
|
284
|
+
rb_ary_store(ary, 2, argv[2]);
|
285
|
+
F->n = FIX2INT(argv[3]);
|
286
|
+
}
|
287
|
+
if (argc == 5) rb_ary_store(ary, 3, argv[4]);
|
288
|
+
break;
|
289
|
+
default:
|
290
|
+
rb_raise(rb_eArgError, "wrong number of arguments (1, 3, or 4)");
|
291
|
+
}
|
292
|
+
}
|
293
|
+
|
294
|
+
static VALUE rb_gsl_multimin_function_fdf_set_procs(int argc, VALUE *argv, VALUE obj)
|
295
|
+
{
|
296
|
+
VALUE ary;
|
297
|
+
gsl_multimin_function_fdf *F = NULL;
|
298
|
+
Data_Get_Struct(obj, gsl_multimin_function_fdf, F);
|
299
|
+
if (F->params == NULL) {
|
300
|
+
ary = rb_ary_new2(4);
|
301
|
+
/* (VALUE) F->params = ary;*/
|
302
|
+
F->params = (void *) ary;
|
303
|
+
} else {
|
304
|
+
ary = (VALUE) F->params;
|
305
|
+
}
|
306
|
+
switch (argc) {
|
307
|
+
case 2:
|
308
|
+
rb_ary_store(ary, 0, argv[0]);
|
309
|
+
rb_ary_store(ary, 1, argv[1]);
|
310
|
+
rb_ary_store(ary, 2, Qnil);
|
311
|
+
break;
|
312
|
+
case 3:
|
313
|
+
rb_ary_store(ary, 0, argv[0]);
|
314
|
+
rb_ary_store(ary, 1, argv[1]);
|
315
|
+
if (TYPE(argv[2]) == T_FIXNUM) {
|
316
|
+
F->n = FIX2INT(argv[2]);
|
317
|
+
rb_ary_store(ary, 2, Qnil);
|
318
|
+
} else {
|
319
|
+
rb_ary_store(ary, 2, argv[2]);
|
320
|
+
}
|
321
|
+
break;
|
322
|
+
case 4:
|
323
|
+
case 5:
|
324
|
+
if (TYPE(argv[0]) == T_FIXNUM) {
|
325
|
+
F->n = FIX2INT(argv[0]);
|
326
|
+
rb_ary_store(ary, 0, argv[1]);
|
327
|
+
rb_ary_store(ary, 1, argv[2]);
|
328
|
+
rb_ary_store(ary, 2, argv[3]);
|
329
|
+
} else {
|
330
|
+
rb_ary_store(ary, 0, argv[0]);
|
331
|
+
rb_ary_store(ary, 1, argv[1]);
|
332
|
+
rb_ary_store(ary, 2, argv[2]);
|
333
|
+
F->n = FIX2INT(argv[3]);
|
334
|
+
}
|
335
|
+
if (argc == 5) rb_ary_store(ary, 3, argv[4]);
|
336
|
+
break;
|
337
|
+
default:
|
338
|
+
rb_raise(rb_eArgError, "wrong number of arguments (2, 3, or 4)");
|
339
|
+
}
|
340
|
+
return obj;
|
341
|
+
}
|
342
|
+
|
343
|
+
static VALUE rb_gsl_multimin_function_fdf_set_params(int argc, VALUE *argv, VALUE obj)
|
344
|
+
{
|
345
|
+
gsl_multimin_function_fdf *F = NULL;
|
346
|
+
VALUE ary, ary2;
|
347
|
+
size_t i;
|
348
|
+
if (argc == 0) return obj;
|
349
|
+
Data_Get_Struct(obj, gsl_multimin_function_fdf, F);
|
350
|
+
if (F->params == NULL) {
|
351
|
+
ary = rb_ary_new2(4);
|
352
|
+
/* (VALUE) F->params = ary;*/
|
353
|
+
F->params = (void *) ary;
|
354
|
+
} else {
|
355
|
+
ary = (VALUE) F->params;
|
356
|
+
}
|
357
|
+
if (argc == 1) {
|
358
|
+
rb_ary_store(ary, 3, argv[0]);
|
359
|
+
} else {
|
360
|
+
ary2 = rb_ary_new2(argc);
|
361
|
+
for (i = 0; i < argc; i++) rb_ary_store(ary2, i, argv[i]);
|
362
|
+
rb_ary_store(ary, 3, ary2);
|
363
|
+
}
|
364
|
+
return obj;
|
365
|
+
}
|
366
|
+
|
367
|
+
static VALUE rb_gsl_multimin_function_fdf_set(int argc, VALUE *argv, VALUE obj)
|
368
|
+
{
|
369
|
+
gsl_multimin_function_fdf *F = NULL;
|
370
|
+
Data_Get_Struct(obj, gsl_multimin_function_fdf, F);
|
371
|
+
set_function_fdf(argc, argv, F);
|
372
|
+
return obj;
|
373
|
+
}
|
374
|
+
|
375
|
+
double rb_gsl_multimin_function_fdf_f(const gsl_vector *x, void *p)
|
376
|
+
{
|
377
|
+
VALUE vx, proc, vp, result, ary;
|
378
|
+
vx = Data_Wrap_Struct(cgsl_vector, 0, NULL, (gsl_vector *) x);
|
379
|
+
ary = (VALUE) p;
|
380
|
+
proc = rb_ary_entry(ary, 0);
|
381
|
+
vp = rb_ary_entry(ary, RARRAY_LEN(ary)-1);
|
382
|
+
if (NIL_P(vp)) result = rb_funcall(proc, RBGSL_ID_call, 1, vx);
|
383
|
+
else result = rb_funcall(proc, RBGSL_ID_call, 2, vx, vp);
|
384
|
+
return NUM2DBL(result);
|
385
|
+
}
|
386
|
+
|
387
|
+
void rb_gsl_multimin_function_fdf_df(const gsl_vector *x, void *p,
|
388
|
+
gsl_vector *g)
|
389
|
+
{
|
390
|
+
VALUE vx, vg, proc, vp, ary;
|
391
|
+
vx = Data_Wrap_Struct(cgsl_vector, 0, NULL, (gsl_vector *) x);
|
392
|
+
vg = Data_Wrap_Struct(cgsl_vector, 0, NULL, g);
|
393
|
+
ary = (VALUE) p;
|
394
|
+
proc = rb_ary_entry(ary, 1);
|
395
|
+
vp = rb_ary_entry(ary, RARRAY_LEN(ary)-1);
|
396
|
+
if (NIL_P(vp)) {
|
397
|
+
rb_funcall(proc, RBGSL_ID_call, 2, vx, vg);
|
398
|
+
} else {
|
399
|
+
rb_funcall(proc, RBGSL_ID_call, 3, vx, vp, vg);
|
400
|
+
}
|
401
|
+
}
|
402
|
+
|
403
|
+
void rb_gsl_multimin_function_fdf_fdf(const gsl_vector *x, void *p,
|
404
|
+
double *f, gsl_vector *g)
|
405
|
+
{
|
406
|
+
VALUE vx, vf, vg, proc_fdf, proc_f, proc_df, vp, ary, result;
|
407
|
+
vx = Data_Wrap_Struct(cgsl_vector, 0, NULL, (gsl_vector *) x);
|
408
|
+
vg = Data_Wrap_Struct(cgsl_vector, 0, NULL, g);
|
409
|
+
vf = rb_float_new(*f);
|
410
|
+
ary = (VALUE) p;
|
411
|
+
proc_f = rb_ary_entry(ary, 0);
|
412
|
+
proc_df = rb_ary_entry(ary, 1);
|
413
|
+
proc_fdf = rb_ary_entry(ary, 2);
|
414
|
+
vp = rb_ary_entry(ary, RARRAY_LEN(ary)-1);
|
415
|
+
if (NIL_P(vp)) {
|
416
|
+
result = rb_funcall(proc_f, RBGSL_ID_call, 1, vx);
|
417
|
+
rb_funcall(proc_df, RBGSL_ID_call, 2, vx, vg);
|
418
|
+
} else {
|
419
|
+
result = rb_funcall(proc_f, RBGSL_ID_call, 2, vx, vp);
|
420
|
+
rb_funcall(proc_df, RBGSL_ID_call, 3, vx, vp, vg);
|
421
|
+
}
|
422
|
+
*f = NUM2DBL(result);
|
423
|
+
}
|
424
|
+
|
425
|
+
static VALUE rb_gsl_multimin_function_fdf_params(VALUE obj)
|
426
|
+
{
|
427
|
+
gsl_multimin_function_fdf *F = NULL;
|
428
|
+
Data_Get_Struct(obj, gsl_multimin_function_fdf, F);
|
429
|
+
return rb_ary_entry((VALUE) F->params, 3);
|
430
|
+
}
|
431
|
+
|
432
|
+
/****************/
|
433
|
+
|
434
|
+
static void define_const(VALUE klass1, VALUE klass2)
|
435
|
+
{
|
436
|
+
rb_define_const(klass1,
|
437
|
+
"CONJUGATE_FR", INT2FIX(GSL_FDFMINIMIZER_CONJUGATE_FR));
|
438
|
+
rb_define_const(klass1,
|
439
|
+
"CONJUGATE_PR", INT2FIX(GSL_FDFMINIMIZER_CONJUGATE_PR));
|
440
|
+
rb_define_const(klass1,
|
441
|
+
"VECTOR_BFGS", INT2FIX(GSL_FDFMINIMIZER_VECTOR_BFGS));
|
442
|
+
rb_define_const(klass1,
|
443
|
+
"STEEPEST_DESCENT", INT2FIX(GSL_FDFMINIMIZER_STEEPEST_DESCENT));
|
444
|
+
#ifdef GSL_1_3_LATER
|
445
|
+
rb_define_const(klass2,
|
446
|
+
"NMSIMPLEX", INT2FIX(GSL_FMINIMIZER_NMSIMPLEX));
|
447
|
+
#endif
|
448
|
+
#ifdef GSL_1_9_LATER
|
449
|
+
rb_define_const(klass1,
|
450
|
+
"VECTOR_BFGS2", INT2FIX(GSL_FDFMINIMIZER_VECTOR_BFGS2));
|
451
|
+
#endif
|
452
|
+
#ifdef GSL_1_13_LATER
|
453
|
+
rb_define_const(klass2,
|
454
|
+
"NMSIMPLEX2RAND", INT2FIX(GSL_FMINIMIZER_NMSIMPLEX2RAND));
|
455
|
+
#endif
|
456
|
+
}
|
457
|
+
|
458
|
+
static const gsl_multimin_fdfminimizer_type* get_fdfminimizer_type(VALUE t)
|
459
|
+
{
|
460
|
+
char name[64];
|
461
|
+
switch (TYPE(t)) {
|
462
|
+
case T_STRING:
|
463
|
+
strcpy(name, STR2CSTR(t));
|
464
|
+
if (str_tail_grep(name, "conjugate_fr") == 0)
|
465
|
+
return gsl_multimin_fdfminimizer_conjugate_fr;
|
466
|
+
else if (str_tail_grep(name, "conjugate_pr") == 0)
|
467
|
+
return gsl_multimin_fdfminimizer_conjugate_pr;
|
468
|
+
else if (str_tail_grep(name, "vector_bfgs") == 0)
|
469
|
+
return gsl_multimin_fdfminimizer_vector_bfgs;
|
470
|
+
else if (str_tail_grep(name, "steepest_descent") == 0)
|
471
|
+
return gsl_multimin_fdfminimizer_steepest_descent;
|
472
|
+
#ifdef GSL_1_9_LATER
|
473
|
+
else if (str_tail_grep(name, "vector_bfgs2") == 0)
|
474
|
+
return gsl_multimin_fdfminimizer_vector_bfgs2;
|
475
|
+
#endif
|
476
|
+
else
|
477
|
+
rb_raise(rb_eTypeError, "%s: unknown minimizer type", name);
|
478
|
+
break;
|
479
|
+
case T_FIXNUM:
|
480
|
+
switch (FIX2INT(t)) {
|
481
|
+
case GSL_FDFMINIMIZER_CONJUGATE_FR:
|
482
|
+
return gsl_multimin_fdfminimizer_conjugate_fr; break;
|
483
|
+
case GSL_FDFMINIMIZER_CONJUGATE_PR:
|
484
|
+
return gsl_multimin_fdfminimizer_conjugate_pr; break;
|
485
|
+
case GSL_FDFMINIMIZER_VECTOR_BFGS:
|
486
|
+
return gsl_multimin_fdfminimizer_vector_bfgs; break;
|
487
|
+
case GSL_FDFMINIMIZER_STEEPEST_DESCENT:
|
488
|
+
return gsl_multimin_fdfminimizer_steepest_descent; break;
|
489
|
+
#ifdef GSL_1_9_LATER
|
490
|
+
case GSL_FDFMINIMIZER_VECTOR_BFGS2:
|
491
|
+
return gsl_multimin_fdfminimizer_vector_bfgs2; break;
|
492
|
+
#endif
|
493
|
+
default:
|
494
|
+
rb_raise(rb_eTypeError, "%d: unknown type", FIX2INT(t));
|
495
|
+
break;
|
496
|
+
}
|
497
|
+
break;
|
498
|
+
default:
|
499
|
+
rb_raise(rb_eTypeError, "type is given by a String or a Fixnum");
|
500
|
+
break;
|
501
|
+
}
|
502
|
+
}
|
503
|
+
|
504
|
+
static VALUE rb_gsl_fdfminimizer_new(VALUE klass, VALUE t, VALUE n)
|
505
|
+
{
|
506
|
+
gsl_multimin_fdfminimizer *gmf = NULL;
|
507
|
+
const gsl_multimin_fdfminimizer_type *T;
|
508
|
+
T = get_fdfminimizer_type(t);
|
509
|
+
gmf = gsl_multimin_fdfminimizer_alloc(T, FIX2INT(n));
|
510
|
+
return Data_Wrap_Struct(klass, 0, gsl_multimin_fdfminimizer_free, gmf);
|
511
|
+
}
|
512
|
+
|
513
|
+
static VALUE rb_gsl_fdfminimizer_set(VALUE obj, VALUE ff, VALUE xx, VALUE ss,
|
514
|
+
VALUE tt)
|
515
|
+
{
|
516
|
+
gsl_multimin_fdfminimizer *gmf = NULL;
|
517
|
+
gsl_multimin_function_fdf *F = NULL;
|
518
|
+
gsl_vector *x;
|
519
|
+
double stepsize, tol;
|
520
|
+
int status;
|
521
|
+
CHECK_MULTIMIN_FUNCTION_FDF(ff);
|
522
|
+
Need_Float(ss); Need_Float(tt);
|
523
|
+
Data_Get_Struct(obj, gsl_multimin_fdfminimizer, gmf);
|
524
|
+
Data_Get_Struct(ff, gsl_multimin_function_fdf, F);
|
525
|
+
Data_Get_Vector(xx, x);
|
526
|
+
stepsize = NUM2DBL(ss);
|
527
|
+
tol = NUM2DBL(tt);
|
528
|
+
status = gsl_multimin_fdfminimizer_set(gmf, F, x, stepsize, tol);
|
529
|
+
return INT2FIX(status);
|
530
|
+
}
|
531
|
+
|
532
|
+
static VALUE rb_gsl_fdfminimizer_name(VALUE obj)
|
533
|
+
{
|
534
|
+
gsl_multimin_fdfminimizer *gmf = NULL;
|
535
|
+
Data_Get_Struct(obj, gsl_multimin_fdfminimizer, gmf);
|
536
|
+
return rb_str_new2(gsl_multimin_fdfminimizer_name(gmf));
|
537
|
+
}
|
538
|
+
|
539
|
+
static VALUE rb_gsl_fdfminimizer_iterate(VALUE obj)
|
540
|
+
{
|
541
|
+
gsl_multimin_fdfminimizer *gmf = NULL;
|
542
|
+
Data_Get_Struct(obj, gsl_multimin_fdfminimizer, gmf);
|
543
|
+
return INT2FIX(gsl_multimin_fdfminimizer_iterate(gmf));
|
544
|
+
}
|
545
|
+
|
546
|
+
static VALUE rb_gsl_fdfminimizer_x(VALUE obj)
|
547
|
+
{
|
548
|
+
gsl_multimin_fdfminimizer *gmf = NULL;
|
549
|
+
gsl_vector *x = NULL;
|
550
|
+
Data_Get_Struct(obj, gsl_multimin_fdfminimizer, gmf);
|
551
|
+
x = gsl_multimin_fdfminimizer_x(gmf);
|
552
|
+
return Data_Wrap_Struct(cgsl_vector_view_ro, 0, NULL, x);
|
553
|
+
}
|
554
|
+
|
555
|
+
static VALUE rb_gsl_fdfminimizer_gradient(VALUE obj)
|
556
|
+
{
|
557
|
+
gsl_multimin_fdfminimizer *gmf = NULL;
|
558
|
+
gsl_vector *gradient = NULL;
|
559
|
+
Data_Get_Struct(obj, gsl_multimin_fdfminimizer, gmf);
|
560
|
+
gradient = gsl_multimin_fdfminimizer_gradient(gmf);
|
561
|
+
return Data_Wrap_Struct(cgsl_vector_view_ro, 0, NULL, gradient);
|
562
|
+
}
|
563
|
+
|
564
|
+
static VALUE rb_gsl_fdfminimizer_minimum(VALUE obj)
|
565
|
+
{
|
566
|
+
gsl_multimin_fdfminimizer *gmf = NULL;
|
567
|
+
double min;
|
568
|
+
Data_Get_Struct(obj, gsl_multimin_fdfminimizer, gmf);
|
569
|
+
min = gsl_multimin_fdfminimizer_minimum(gmf);
|
570
|
+
return rb_float_new(min);
|
571
|
+
}
|
572
|
+
|
573
|
+
static VALUE rb_gsl_fdfminimizer_f(VALUE obj)
|
574
|
+
{
|
575
|
+
gsl_multimin_fdfminimizer *gmf = NULL;
|
576
|
+
Data_Get_Struct(obj, gsl_multimin_fdfminimizer, gmf);
|
577
|
+
return rb_float_new(gmf->f);
|
578
|
+
}
|
579
|
+
|
580
|
+
static VALUE rb_gsl_fdfminimizer_restart(VALUE obj)
|
581
|
+
{
|
582
|
+
gsl_multimin_fdfminimizer *gmf = NULL;
|
583
|
+
Data_Get_Struct(obj, gsl_multimin_fdfminimizer, gmf);
|
584
|
+
return INT2FIX(gsl_multimin_fdfminimizer_restart(gmf));
|
585
|
+
}
|
586
|
+
|
587
|
+
static VALUE rb_gsl_fdfminimizer_test_gradient(VALUE obj, VALUE ea)
|
588
|
+
{
|
589
|
+
gsl_multimin_fdfminimizer *gmf = NULL;
|
590
|
+
gsl_vector *g = NULL;
|
591
|
+
Need_Float(ea);
|
592
|
+
Data_Get_Struct(obj, gsl_multimin_fdfminimizer, gmf);
|
593
|
+
g = gsl_multimin_fdfminimizer_gradient(gmf);
|
594
|
+
return INT2FIX(gsl_multimin_test_gradient(g, NUM2DBL(ea)));
|
595
|
+
}
|
596
|
+
|
597
|
+
static VALUE rb_gsl_multimin_test_gradient(VALUE obj, VALUE gg, VALUE ea)
|
598
|
+
{
|
599
|
+
gsl_vector *g = NULL;
|
600
|
+
Need_Float(ea);
|
601
|
+
Data_Get_Vector(gg, g);
|
602
|
+
return INT2FIX(gsl_multimin_test_gradient(g, NUM2DBL(ea)));
|
603
|
+
}
|
604
|
+
|
605
|
+
/*****/
|
606
|
+
#ifdef GSL_1_3_LATER
|
607
|
+
static const gsl_multimin_fminimizer_type* get_fminimizer_type(VALUE t)
|
608
|
+
{
|
609
|
+
char name[64];
|
610
|
+
|
611
|
+
switch (TYPE(t)) {
|
612
|
+
case T_STRING:
|
613
|
+
strcpy(name, STR2CSTR(t));
|
614
|
+
if (str_tail_grep(name, "nmsimplex") == 0)
|
615
|
+
return gsl_multimin_fminimizer_nmsimplex;
|
616
|
+
#ifdef GSL_1_13_LATER
|
617
|
+
if (str_tail_grep(name, "nmsimplex2rand") == 0)
|
618
|
+
return gsl_multimin_fminimizer_nmsimplex2rand;
|
619
|
+
#endif
|
620
|
+
else
|
621
|
+
rb_raise(rb_eTypeError, "unknown type %s (nmsimplex and nmsimplex2rand supported)", name);
|
622
|
+
break;
|
623
|
+
case T_FIXNUM:
|
624
|
+
switch (FIX2INT(t)) {
|
625
|
+
case GSL_FMINIMIZER_NMSIMPLEX:
|
626
|
+
return gsl_multimin_fminimizer_nmsimplex; break;
|
627
|
+
#ifdef GSL_1_13_LATER
|
628
|
+
case GSL_FMINIMIZER_NMSIMPLEX2RAND:
|
629
|
+
return gsl_multimin_fminimizer_nmsimplex2rand; break;
|
630
|
+
#endif
|
631
|
+
default:
|
632
|
+
rb_raise(rb_eTypeError, "%d: unknown type (not supported)", FIX2INT(t));
|
633
|
+
break;
|
634
|
+
}
|
635
|
+
break;
|
636
|
+
default:
|
637
|
+
rb_raise(rb_eTypeError, "wrong argument type %s (String or Fixnum expected)",
|
638
|
+
rb_class2name(CLASS_OF(t)));
|
639
|
+
break;
|
640
|
+
}
|
641
|
+
}
|
642
|
+
|
643
|
+
static VALUE rb_gsl_fminimizer_new(VALUE klass, VALUE t, VALUE n)
|
644
|
+
{
|
645
|
+
gsl_multimin_fminimizer *gmf = NULL;
|
646
|
+
const gsl_multimin_fminimizer_type *T;
|
647
|
+
CHECK_FIXNUM(n);
|
648
|
+
T = get_fminimizer_type(t);
|
649
|
+
gmf = gsl_multimin_fminimizer_alloc(T, FIX2INT(n));
|
650
|
+
return Data_Wrap_Struct(klass, 0, gsl_multimin_fminimizer_free, gmf);
|
651
|
+
}
|
652
|
+
|
653
|
+
static VALUE rb_gsl_fminimizer_set(VALUE obj, VALUE ff, VALUE xx, VALUE ss)
|
654
|
+
{
|
655
|
+
gsl_multimin_fminimizer *gmf = NULL;
|
656
|
+
gsl_multimin_function *F = NULL;
|
657
|
+
gsl_vector *x = NULL, *s = NULL;
|
658
|
+
CHECK_MULTIMIN_FUNCTION(ff);
|
659
|
+
Data_Get_Struct(obj, gsl_multimin_fminimizer, gmf);
|
660
|
+
Data_Get_Struct(ff, gsl_multimin_function, F);
|
661
|
+
Data_Get_Vector(xx, x);
|
662
|
+
Data_Get_Vector(ss, s);
|
663
|
+
return INT2FIX(gsl_multimin_fminimizer_set(gmf, F, x, s));
|
664
|
+
}
|
665
|
+
|
666
|
+
static VALUE rb_gsl_fminimizer_name(VALUE obj)
|
667
|
+
{
|
668
|
+
gsl_multimin_fminimizer *gmf = NULL;
|
669
|
+
Data_Get_Struct(obj, gsl_multimin_fminimizer, gmf);
|
670
|
+
return rb_str_new2(gsl_multimin_fminimizer_name(gmf));
|
671
|
+
}
|
672
|
+
|
673
|
+
static VALUE rb_gsl_fminimizer_iterate(VALUE obj)
|
674
|
+
{
|
675
|
+
gsl_multimin_fminimizer *gmf = NULL;
|
676
|
+
Data_Get_Struct(obj, gsl_multimin_fminimizer, gmf);
|
677
|
+
return INT2FIX(gsl_multimin_fminimizer_iterate(gmf));
|
678
|
+
}
|
679
|
+
|
680
|
+
static VALUE rb_gsl_fminimizer_x(VALUE obj)
|
681
|
+
{
|
682
|
+
gsl_multimin_fminimizer *gmf = NULL;
|
683
|
+
gsl_vector *x = NULL;
|
684
|
+
Data_Get_Struct(obj, gsl_multimin_fminimizer, gmf);
|
685
|
+
x = gsl_multimin_fminimizer_x(gmf);
|
686
|
+
return Data_Wrap_Struct(cgsl_vector_view_ro, 0, NULL, x);
|
687
|
+
}
|
688
|
+
|
689
|
+
static VALUE rb_gsl_fminimizer_minimum(VALUE obj)
|
690
|
+
{
|
691
|
+
gsl_multimin_fminimizer *gmf = NULL;
|
692
|
+
double min;
|
693
|
+
Data_Get_Struct(obj, gsl_multimin_fminimizer, gmf);
|
694
|
+
min = gsl_multimin_fminimizer_minimum(gmf);
|
695
|
+
return rb_float_new(min);
|
696
|
+
}
|
697
|
+
|
698
|
+
static VALUE rb_gsl_fminimizer_size(VALUE obj)
|
699
|
+
{
|
700
|
+
gsl_multimin_fminimizer *gmf = NULL;
|
701
|
+
Data_Get_Struct(obj, gsl_multimin_fminimizer, gmf);
|
702
|
+
return rb_float_new(gsl_multimin_fminimizer_size(gmf));
|
703
|
+
}
|
704
|
+
|
705
|
+
static VALUE rb_gsl_fminimizer_fval(VALUE obj)
|
706
|
+
{
|
707
|
+
gsl_multimin_fminimizer *gmf = NULL;
|
708
|
+
Data_Get_Struct(obj, gsl_multimin_fminimizer, gmf);
|
709
|
+
return rb_float_new(gmf->fval);
|
710
|
+
}
|
711
|
+
|
712
|
+
static VALUE rb_gsl_fminimizer_test_size(VALUE obj, VALUE ea)
|
713
|
+
{
|
714
|
+
gsl_multimin_fminimizer *gmf = NULL;
|
715
|
+
Need_Float(ea);
|
716
|
+
Data_Get_Struct(obj, gsl_multimin_fminimizer, gmf);
|
717
|
+
return INT2FIX(gsl_multimin_test_size(gmf->size, NUM2DBL(ea)));
|
718
|
+
}
|
719
|
+
static VALUE rb_gsl_multimin_test_size(VALUE obj, VALUE ss, VALUE ea)
|
720
|
+
{
|
721
|
+
Need_Float(ss); Need_Float(ea);
|
722
|
+
return INT2FIX(gsl_multimin_test_size(NUM2DBL(ss), NUM2DBL(ea)));
|
723
|
+
}
|
724
|
+
|
725
|
+
#endif
|
726
|
+
|
727
|
+
#ifdef HAVE_GSL_GSL_MULTIMIN_FSDF_H
|
728
|
+
void Init_multimin_fsdf(VALUE module);
|
729
|
+
#endif
|
730
|
+
|
731
|
+
/*****/
|
732
|
+
void Init_gsl_multimin(VALUE module)
|
733
|
+
{
|
734
|
+
VALUE mgsl_multimin;
|
735
|
+
VALUE cgsl_multimin_fdfminimizer;
|
736
|
+
VALUE cgsl_multimin_fminimizer;
|
737
|
+
|
738
|
+
mgsl_multimin = rb_define_module_under(module, "MultiMin");
|
739
|
+
rb_define_singleton_method(mgsl_multimin, "test_gradient", rb_gsl_multimin_test_gradient, 2);
|
740
|
+
#ifdef GSL_1_3_LATER
|
741
|
+
rb_define_singleton_method(mgsl_multimin, "test_size", rb_gsl_multimin_test_size, 2);
|
742
|
+
#endif
|
743
|
+
|
744
|
+
cgsl_multimin_fdfminimizer = rb_define_class_under(mgsl_multimin, "FdfMinimizer", cGSL_Object);
|
745
|
+
cgsl_multimin_fminimizer = rb_define_class_under(mgsl_multimin, "FMinimizer", cGSL_Object);
|
746
|
+
define_const(cgsl_multimin_fdfminimizer, cgsl_multimin_fminimizer);
|
747
|
+
|
748
|
+
cgsl_multimin_function = rb_define_class_under(mgsl_multimin, "Function",
|
749
|
+
cgsl_function);
|
750
|
+
rb_define_singleton_method(cgsl_multimin_function, "alloc",
|
751
|
+
rb_gsl_multimin_function_new, -1);
|
752
|
+
rb_define_method(cgsl_multimin_function, "eval", rb_gsl_multimin_function_eval, 1);
|
753
|
+
rb_define_alias(cgsl_multimin_function, "call", "eval");
|
754
|
+
rb_define_method(cgsl_multimin_function, "set_proc", rb_gsl_multimin_function_set_f, -1);
|
755
|
+
rb_define_alias(cgsl_multimin_function, "set_f", "set_proc");
|
756
|
+
rb_define_method(cgsl_multimin_function, "set_params", rb_gsl_multimin_function_set_params, -1);
|
757
|
+
rb_define_method(cgsl_multimin_function, "params", rb_gsl_multimin_function_params, 0);
|
758
|
+
rb_define_method(cgsl_multimin_function, "n", rb_gsl_multimin_function_n, 0);
|
759
|
+
|
760
|
+
cgsl_multimin_function_fdf = rb_define_class_under(mgsl_multimin, "Function_fdf",
|
761
|
+
cGSL_Object);
|
762
|
+
rb_define_singleton_method(cgsl_multimin_function_fdf, "alloc",
|
763
|
+
rb_gsl_multimin_function_fdf_new, -1);
|
764
|
+
|
765
|
+
rb_define_method(cgsl_multimin_function_fdf, "set", rb_gsl_multimin_function_fdf_set, -1);
|
766
|
+
rb_define_method(cgsl_multimin_function_fdf, "set_params", rb_gsl_multimin_function_fdf_set_params, -1);
|
767
|
+
rb_define_method(cgsl_multimin_function_fdf, "set_procs", rb_gsl_multimin_function_fdf_set_procs, -1);
|
768
|
+
rb_define_method(cgsl_multimin_function_fdf, "params", rb_gsl_multimin_function_fdf_params, 0);
|
769
|
+
rb_define_method(cgsl_multimin_function_fdf, "n", rb_gsl_multimin_function_fdf_n, 0);
|
770
|
+
|
771
|
+
rb_define_singleton_method(cgsl_multimin_fdfminimizer, "alloc", rb_gsl_fdfminimizer_new, 2);
|
772
|
+
|
773
|
+
rb_define_method(cgsl_multimin_fdfminimizer, "set", rb_gsl_fdfminimizer_set, 4);
|
774
|
+
rb_define_method(cgsl_multimin_fdfminimizer, "name", rb_gsl_fdfminimizer_name, 0);
|
775
|
+
rb_define_method(cgsl_multimin_fdfminimizer, "iterate", rb_gsl_fdfminimizer_iterate, 0);
|
776
|
+
rb_define_method(cgsl_multimin_fdfminimizer, "x", rb_gsl_fdfminimizer_x, 0);
|
777
|
+
rb_define_method(cgsl_multimin_fdfminimizer, "f", rb_gsl_fdfminimizer_f, 0);
|
778
|
+
rb_define_method(cgsl_multimin_fdfminimizer, "gradient", rb_gsl_fdfminimizer_gradient, 0);
|
779
|
+
rb_define_method(cgsl_multimin_fdfminimizer, "minimum", rb_gsl_fdfminimizer_minimum, 0);
|
780
|
+
rb_define_method(cgsl_multimin_fdfminimizer, "restart", rb_gsl_fdfminimizer_restart, 0);
|
781
|
+
rb_define_method(cgsl_multimin_fdfminimizer, "test_gradient", rb_gsl_fdfminimizer_test_gradient, 1);
|
782
|
+
|
783
|
+
/*****/
|
784
|
+
#ifdef GSL_1_3_LATER
|
785
|
+
rb_define_singleton_method(cgsl_multimin_fminimizer, "alloc", rb_gsl_fminimizer_new, 2);
|
786
|
+
|
787
|
+
rb_define_method(cgsl_multimin_fminimizer, "set", rb_gsl_fminimizer_set, 3);
|
788
|
+
rb_define_method(cgsl_multimin_fminimizer, "name", rb_gsl_fminimizer_name, 0);
|
789
|
+
rb_define_method(cgsl_multimin_fminimizer, "iterate", rb_gsl_fminimizer_iterate, 0);
|
790
|
+
rb_define_method(cgsl_multimin_fminimizer, "x", rb_gsl_fminimizer_x, 0);
|
791
|
+
rb_define_method(cgsl_multimin_fminimizer, "fval", rb_gsl_fminimizer_fval, 0);
|
792
|
+
rb_define_method(cgsl_multimin_fminimizer, "minimum", rb_gsl_fminimizer_minimum, 0);
|
793
|
+
rb_define_method(cgsl_multimin_fminimizer, "size", rb_gsl_fminimizer_size, 0);
|
794
|
+
rb_define_method(cgsl_multimin_fminimizer, "test_size", rb_gsl_fminimizer_test_size, 1);
|
795
|
+
#endif
|
796
|
+
|
797
|
+
|
798
|
+
#ifdef HAVE_GSL_GSL_MULTIMIN_FSDF_H
|
799
|
+
Init_multimin_fsdf(mgsl_multimin);
|
800
|
+
#endif
|
801
|
+
}
|
802
|
+
#ifdef CHECK_MULTIMIN_FUNCTION
|
803
|
+
#undef CHECK_MULTIMIN_FUNCTION
|
804
|
+
#endif
|
805
|
+
#ifdef CHECK_MULTIMIN_FUNCTION_FDF
|
806
|
+
#undef CHECK_MULTIMIN_FUNCTION_FDF
|
807
|
+
#endif
|
808
|
+
|