chiark / gitweb /
Revert "simplex wip: compiles"
[moebius3.git] / findcurve.c
index 65c5672eb7753c5a117d741c2723fda43c2f7a5b..055018f3bfb6abf87e5dba0aabbcf8dcb59dc906 100644 (file)
@@ -2,6 +2,7 @@
  */
 
 #include <math.h>
+#include <string.h>
 
 #include <gsl/gsl_errno.h>
 #include <gsl/gsl_sf.h>
@@ -21,35 +22,55 @@ static inline double sinc(double x) {
   return gsl_sf_sinc(x / M_PI);
 }
 
+static int NP;
 static double *INPUT; /* dyanmic array, on main's stack */
 static double PREP[NPREP];
 
+static void printcore(const double *X) {
+  int i, j;
+  DECLARE_F_G;
+  CALCULATE_F_G;
+  printf("[");
+  for (i=0; i<NP; i++)
+    for (j=0; j<3; j++)
+      printf(" %25.18g,", POINT(i)[j]);
+  printf(" ]\n");
+}
+
 static void prepare(double X[] /* startpoint */) {
   /* fills in PREP and startpoint */
   PREPARE;
 }
 
+//#define DEBUG
+
 static double cb_Efunc(void *xp) {
   const double *X = xp;
-  double F[3], G[3];
-
+  int P;
+  DECLARE_F_G;
   CALCULATE_F_G;
 
-  double e = 0;
-  for (P=0; P<NP-3; P++) {
-    double P_cost;
-    CALCULATE_COST;
-    e += P_cost;
+#ifdef DEBUG
+  int i,j;
+  printf(" Efunc\n");
+  for (j=0; j<3; j++) {
+    for (P=0; P<NP; P++)
+      printf(" %7.4f", POINT(P)[j]);
+    printf("\n");
   }
-  return e;
+  printf("             ");
+#endif
+
+  CALCULATE_COST;
+  return cost;
 }
 
 static void cb_step(const gsl_rng *rng, void *xp, double step_size) {
   double *x = xp;
   int i;
   double step[NX];
-  gsl_ran_dir_nd(rng, N,step);
-  for (i=0; i<N; i++)
+  gsl_ran_dir_nd(rng, NX, step);
+  for (i=0; i<NX; i++)
     x[i] += step_size * step[i];
   //printf("\n cb_step %p %10.7f [", xp, step_size);
   //for (i=0; i<N; i++) printf(" %10.7f,", step[i]);
@@ -60,24 +81,13 @@ static double cb_metric(void *xp, void *yp) {
   const double *x=xp, *y=yp;
   int i;
   double s;
-  for (i=0, s=0; i<N; i++) {
+  for (i=0, s=0; i<NX; i++) {
     double d = x[i] - y[i];
     s += d*d;
   }
   return sqrt(s);
 }
 
-static void printcore(const double *x) {
-  int i;
-  double F[N];
-  X_EXTRACT;
-  F_POPULATE;
-  printf("[");
-  for (i=0; i<6; i++) printf(" %.18g,", x[i]);
-  for (i=0; i<6; i++) printf(" %.18g,", F[i]);
-  printf(" ]\n");
-}
-
 static void __attribute__((unused)) cb_print(void *xp) {
   const double *x = xp;
   printf("\n");
@@ -95,11 +105,12 @@ static double scan1double(void) {
   return v;
 }
 
-int main(int argc, const char *const argv) {
+int main(int argc, const char *const *argv) {
   double epsilon;
   int i;
 
   NP = atoi(argv[1]);
+  epsilon = atof(argv[2]);
 
   gsl_rng *rng = gsl_rng_alloc(gsl_rng_ranlxd2);
 
@@ -110,7 +121,6 @@ int main(int argc, const char *const argv) {
     /* NINPUT + 1 doubles: startpoint, epsilon for residual */
     for (i=0; i<NINPUT; i++)
       INPUT[i] = scan1double();
-    epsilon = scan1double();
 
     gsl_rng_set(rng,0);