7 #include <gsl/gsl_errno.h>
8 #include <gsl/gsl_sf.h>
9 #include <gsl/gsl_siman.h>
10 #include <gsl/gsl_randist.h>
14 #define J_END_COL(i) \
15 for (j=0; j<PN; j++) gsl_matrix_set(J,i,j,J_COL[j]);
17 static inline _Bool IS_SMALL(double v) {
21 static inline double sinc(double x) {
22 return gsl_sf_sinc(x / M_PI);
26 static double *INPUT; /* dyanmic array, on main's stack */
27 static double PREP[NPREP];
29 static void printcore(const double *X) {
36 printf(" %25.18g,", POINT(i)[j]);
40 static void prepare(double X[] /* startpoint */) {
41 /* fills in PREP and startpoint */
47 static double cb_Efunc(void *xp) {
57 printf(" %7.4f", POINT(i)[j]);
65 for (P=0; P<NP-3; P++) {
69 printf(" %7.4f", P_cost);
79 static void cb_step(const gsl_rng *rng, void *xp, double step_size) {
83 gsl_ran_dir_nd(rng, NX, step);
85 x[i] += step_size * step[i];
86 //printf("\n cb_step %p %10.7f [", xp, step_size);
87 //for (i=0; i<N; i++) printf(" %10.7f,", step[i]);
91 static double cb_metric(void *xp, void *yp) {
92 const double *x=xp, *y=yp;
95 for (i=0, s=0; i<NX; i++) {
96 double d = x[i] - y[i];
102 static void __attribute__((unused)) cb_print(void *xp) {
103 const double *x = xp;
108 static double scan1double(void) {
113 if (ferror(stdin)) { perror("stdin"); exit(-1); }
114 if (feof(stdin)) exit(0);
115 if (r!=1) { fputs("bad input\n",stderr); exit(-1); }
119 int main(int argc, const char *const *argv) {
124 epsilon = atof(argv[2]);
126 gsl_rng *rng = gsl_rng_alloc(gsl_rng_ranlxd2);
128 double input[NINPUT]; INPUT = input;
129 double startpoint[NX];
132 /* NINPUT + 1 doubles: startpoint, epsilon for residual */
133 for (i=0; i<NINPUT; i++)
134 INPUT[i] = scan1double();
138 gsl_siman_params_t siman_params = {
142 .t_min = epsilon * 1E-3,
143 .iters_fixed_T = 100,
152 cb_Efunc, cb_step, cb_metric,
154 0,0,0, sizeof(startpoint), siman_params);
156 printcore(startpoint);