Xmipp  v3.23.11-Nereus
numerical_recipes.h File Reference
#include <math.h>
#include "xmipp_memory.h"
#include "xmipp_macros.h"
#include <algorithm>
#include <vector>
Include dependency graph for numerical_recipes.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

#define TINY   1.0e-20;
 
void nrerror (const char error_text[])
 
double ran1 (int *idum)
 
double gasdev (int *idum)
 
double tdev (double nu, int *idum)
 
void ksone (double data[], int n, double(*func)(double), double *d, double *prob)
 
double probks (double alam)
 
void four1 (double data[], int nn, int isign)
 
void realft (double data[], int n, int isign)
 
void fourn (double data[], int nn[], int ndim, int isign)
 
void indexx (int n, double arrin[], int indx[])
 
double bessj0 (double x)
 
double bessj3_5 (double x)
 
double bessj1_5 (double x)
 
double bessi0 (double x)
 
double bessi1 (double x)
 
double bessi0_5 (double x)
 
double bessi1_5 (double x)
 
double bessi2 (double x)
 
double bessi3 (double x)
 
double bessi2_5 (double x)
 
double bessi3_5 (double x)
 
double bessi4 (double x)
 
double gammln (double xx)
 
double gammp (double a, double x)
 
double betacf (double a, double b, double x)
 
double betai (double a, double b, double x)
 
double sinc (double x)
 
size_t fact (int num)
 
size_t binom (int n, int k)
 
void svdcmp (double *a, int m, int n, double *w, double *v)
 
void svbksb (double *u, double *w, double *v, int m, int n, double *b, double *x)
 
void convlv (double *data, int n, double *respns, int m, int isign, double *ans)
 
void realft (double *data, int n, int isign)
 
void twofft (double *data1, double *data2, double *fft1, double *fft2, int n)
 
void four1 (double *data, int nn, int isign)
 
void powell (double *p, double *xi, int n, double ftol, int &iter, double &fret, double(*func)(double *, void *), void *prm, bool show)
 
int nnls (double *a, int m, int n, double *b, double *x, double *rnorm, double *w, double *zz, int *index)
 
int nnlsWght (int N, int M, double *A, double *b, double *weight)
 
void grobfd (int, int, double *, double *, void(*)(int, int, double *, double *, void *), void *)
 
void grcnfd (int, int, double *, double *, void(*)(int, int, double *, double *, void *), void *)
 
void cfsqp (int, int, int, int, int, int, int, int, int, int *, int, int, int, int *, double, double, double, double, double *, double *, double *, double *, double *, double *, void(*)(int, int, double *, double *, void *), void(*)(int, int, double *, double *, void *), void(*)(int, int, double *, double *, void(*)(int, int, double *, double *, void *), void *), void(*)(int, int, double *, double *, void(*)(int, int, double *, double *, void *), void *), void *)
 
void wtn (double a[], unsigned long nn[], int ndim, int isign, void(*wtstep)(double [], unsigned long, int))
 
void pwtset (int n)
 
void pwt (double a[], unsigned long n, int isign)
 
template<class T >
void ludcmp (T *a, int n, int *indx, T *d)
 
template<class T >
void lubksb (T *a, int n, int *indx, T b[])
 
template<class T >
void gaussj (T *a, int n, T *b, int m)
 
void choldc (double *a, int n, double *p)
 
void cholsl (double *a, int n, double *p, double *b, double *x)
 
void polint (double *xa, double *ya, int n, double x, double &y, double &dy)
 

Macro Definition Documentation

◆ TINY

#define TINY   1.0e-20;

Definition at line 167 of file numerical_recipes.h.

Function Documentation

◆ bessi0()

double bessi0 ( double  x)

Definition at line 286 of file numerical_recipes.cpp.

287 {
288  double y, ax, ans;
289  if ((ax = fabs(x)) < 3.75)
290  {
291  y = x / 3.75;
292  y *= y;
293  ans = 1.0 + y * (3.5156229 + y * (3.0899424 + y * (1.2067492
294  + y * (0.2659732 + y * (0.360768e-1 + y * 0.45813e-2)))));
295  }
296  else
297  {
298  y = 3.75 / ax;
299  ans = (exp(ax) / sqrt(ax)) * (0.39894228 + y * (0.1328592e-1
300  + y * (0.225319e-2 + y * (-0.157565e-2 + y * (0.916281e-2
301  + y * (-0.2057706e-1 + y * (0.2635537e-1 + y * (-0.1647633e-1
302  + y * 0.392377e-2))))))));
303  }
304  return ans;
305 }
void sqrt(Image< double > &op)
static double * y
doublereal * x

◆ bessi0_5()

double bessi0_5 ( double  x)

Definition at line 547 of file numerical_recipes.cpp.

548 {
549  return (x == 0) ? 0 : sqrt(2 / (PI*x))*sinh(x);
550 }
void sqrt(Image< double > &op)
doublereal * x
#define PI
Definition: tools.h:43

◆ bessi1()

double bessi1 ( double  x)

Definition at line 308 of file numerical_recipes.cpp.

309 {
310  double ax, ans;
311  double y;
312  if ((ax = fabs(x)) < 3.75)
313  {
314  y = x / 3.75;
315  y *= y;
316  ans = ax * (0.5 + y * (0.87890594 + y * (0.51498869 + y * (0.15084934
317  + y * (0.2658733e-1 + y * (0.301532e-2 + y * 0.32411e-3))))));
318  }
319  else
320  {
321  y = 3.75 / ax;
322  ans = 0.2282967e-1 + y * (-0.2895312e-1 + y * (0.1787654e-1
323  - y * 0.420059e-2));
324  ans = 0.39894228 + y * (-0.3988024e-1 + y * (-0.362018e-2
325  + y * (0.163801e-2 + y * (-0.1031555e-1 + y * ans))));
326  ans *= (exp(ax) / sqrt(ax));
327  }
328  return x < 0.0 ? -ans : ans;
329 }
void sqrt(Image< double > &op)
static double * y
doublereal * x

◆ bessi1_5()

double bessi1_5 ( double  x)

Definition at line 551 of file numerical_recipes.cpp.

552 {
553  return (x == 0) ? 0 : sqrt(2 / (PI*x))*(cosh(x) - sinh(x) / x);
554 }
void sqrt(Image< double > &op)
doublereal * x
#define PI
Definition: tools.h:43

◆ bessi2()

double bessi2 ( double  x)

Definition at line 555 of file numerical_recipes.cpp.

556 {
557  return (x == 0) ? 0 : bessi0(x) - ((2*1) / x) * bessi1(x);
558 }
double bessi0(double x)
double bessi1(double x)
doublereal * x

◆ bessi2_5()

double bessi2_5 ( double  x)

Definition at line 559 of file numerical_recipes.cpp.

560 {
561  return (x == 0) ? 0 : bessi0_5(x) - ((2*1.5) / x) * bessi1_5(x);
562 }
doublereal * x
double bessi1_5(double x)
double bessi0_5(double x)

◆ bessi3()

double bessi3 ( double  x)

Definition at line 563 of file numerical_recipes.cpp.

564 {
565  return (x == 0) ? 0 : bessi1(x) - ((2*2) / x) * bessi2(x);
566 }
double bessi1(double x)
doublereal * x
double bessi2(double x)

◆ bessi3_5()

double bessi3_5 ( double  x)

Definition at line 567 of file numerical_recipes.cpp.

568 {
569  return (x == 0) ? 0 : bessi1_5(x) - ((2*2.5) / x) * bessi2_5(x);
570 }
doublereal * x
double bessi1_5(double x)
double bessi2_5(double x)

◆ bessi4()

double bessi4 ( double  x)

Definition at line 571 of file numerical_recipes.cpp.

572 {
573  return (x == 0) ? 0 : bessi2(x) - ((2*3) / x) * bessi3(x);
574 }
doublereal * x
double bessi2(double x)
double bessi3(double x)

◆ bessj0()

double bessj0 ( double  x)

Definition at line 250 of file numerical_recipes.cpp.

251 {
252  double ax, z;
253  double xx, y, ans, ans1, ans2;
254 
255  if ((ax = fabs(x)) < 8.0)
256  {
257  y = x * x;
258  ans1 = 57568490574.0 + y * (-13362590354.0 +
259  y * (651619640.7
260  + y * (-11214424.18 +
261  y * (77392.33017 +
262  y * (-184.9052456)))));
263  ans2 = 57568490411.0 + y * (1029532985.0 +
264  y * (9494680.718
265  + y * (59272.64853 +
266  y * (267.8532712 +
267  y * 1.0))));
268  ans = ans1 / ans2;
269  }
270  else
271  {
272  z = 8.0 / ax;
273  y = z * z;
274  xx = ax - 0.785398164;
275  ans1 = 1.0 + y * (-0.1098628627e-2 + y * (0.2734510407e-4
276  + y * (-0.2073370639e-5 + y * 0.2093887211e-6)));
277  ans2 = -0.1562499995e-1 + y * (0.1430488765e-3
278  + y * (-0.6911147651e-5 + y * (0.7621095161e-6
279  - y * 0.934935152e-7)));
280  ans = sqrt(0.636619772 / ax) * (cos(xx) * ans1 - z * sin(xx) * ans2);
281  }
282  return ans;
283 }
void sqrt(Image< double > &op)
static double * y
doublereal * x
double z

◆ bessj1_5()

double bessj1_5 ( double  x)

Definition at line 575 of file numerical_recipes.cpp.

576 {
577  double rj, ry, rjp, ryp;
578  bessjy(x, 1.5, &rj, &ry, &rjp, &ryp);
579  return rj;
580 }
doublereal * x
void bessjy(double x, double xnu, double *rj, double *ry, double *rjp, double *ryp)

◆ bessj3_5()

double bessj3_5 ( double  x)

Definition at line 581 of file numerical_recipes.cpp.

582 {
583  double rj, ry, rjp, ryp;
584  bessjy(x, 3.5, &rj, &ry, &rjp, &ryp);
585  return rj;
586 }
doublereal * x
void bessjy(double x, double xnu, double *rj, double *ry, double *rjp, double *ryp)

◆ betacf()

double betacf ( double  a,
double  b,
double  x 
)

Definition at line 630 of file numerical_recipes.cpp.

631 {
632  double qap, qam, qab, em, tem, d;
633  double bz, bm = 1.0, bp, bpp;
634  double az = 1.0, am = 1.0, ap, app, aold;
635  int m;
636 
637  qab = a + b;
638  qap = a + 1.0;
639  qam = a - 1.0;
640  bz = 1.0 - qab * x / qap;
641  for (m = 1;m <= ITMAX;m++)
642  {
643  em = (double) m;
644  tem = em + em;
645  d = em * (b - em) * x / ((qam + tem) * (a + tem));
646  ap = az + d * am;
647  bp = bz + d * bm;
648  d = -(a + em) * (qab + em) * x / ((qap + tem) * (a + tem));
649  app = ap + d * az;
650  bpp = bp + d * bz;
651  aold = az;
652  am = ap / bpp;
653  bm = bp / bpp;
654  az = app / bpp;
655  bz = 1.0;
656  if (fabs(az - aold) < (EPS*fabs(az)))
657  return az;
658  }
659  nrerror("a or b too big, or ITMAX too small in BETACF");
660  return 0;
661 }
#define EPS
void nrerror(const char error_text[])
doublereal * x
doublereal * d
doublereal * b
#define ITMAX
doublereal * a

◆ betai()

double betai ( double  a,
double  b,
double  x 
)

Definition at line 612 of file numerical_recipes.cpp.

613 {
614  double bt;
615  if (x < 0.0 || x > 1.0)
616  nrerror("Bad x in routine BETAI");
617  if (x == 0.0 || x == 1.0)
618  bt = 0.0;
619  else
620  bt = exp(gammln(a + b) - gammln(a) - gammln(b) + a * log(x) + b * log(1.0 - x));
621  if (x < (a + 1.0) / (a + b + 2.0))
622  return bt*betacf(a, b, x) / a;
623  else
624  return 1.0 -bt*betacf(b, a, 1.0 - x) / b;
625 
626 }
double betacf(double a, double b, double x)
void nrerror(const char error_text[])
doublereal * x
doublereal * b
void log(Image< double > &op)
doublereal * a
double gammln(double xx)

◆ binom()

size_t binom ( int  n,
int  k 
)
inline

Definition at line 103 of file numerical_recipes.h.

104 {
105  size_t factor=1;
106  for (int i = n; i > (n-k); --i)
107  factor *= i;
108  return factor/fact(k);
109 }
#define i
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
size_t fact(int num)
int * n

◆ cfsqp()

void cfsqp ( int  ,
int  ,
int  ,
int  ,
int  ,
int  ,
int  ,
int  ,
int  ,
int *  ,
int  ,
int  ,
int  ,
int *  ,
double  ,
double  ,
double  ,
double  ,
double *  ,
double *  ,
double *  ,
double *  ,
double *  ,
double *  ,
void(*)(int, int, double *, double *, void *)  ,
void(*)(int, int, double *, double *, void *)  ,
void(*)(int, int, double *, double *, void(*)(int, int, double *, double *, void *), void *)  ,
void(*)(int, int, double *, double *, void(*)(int, int, double *, double *, void *), void *)  ,
void *   
)

◆ choldc()

void choldc ( double *  a,
int  n,
double *  p 
)

Definition at line 9347 of file numerical_recipes.cpp.

9348 {
9349  int i, j, k;
9350  double sum;
9351 
9352  for (i = 1;i <= n;i++)
9353  {
9354  for (j = i;j <= n;j++)
9355  {
9356  for (sum = a[i*n+j], k = i - 1;k >= 1;k--)
9357  sum -= a[i*n+k] * a[j*n+k];
9358  if (i == j)
9359  {
9360  if (sum <= 0.0)
9361  nrerror("choldc failed");
9362  p[i] = sqrt(sum);
9363  }
9364  else
9365  a[j*n+i] = sum / p[i];
9366  }
9367  }
9368 }
void sqrt(Image< double > &op)
void nrerror(const char error_text[])
#define i
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
#define j
int * n
doublereal * a

◆ cholsl()

void cholsl ( double *  a,
int  n,
double *  p,
double *  b,
double *  x 
)

Definition at line 9370 of file numerical_recipes.cpp.

9371 {
9372  int i, k;
9373  double sum;
9374 
9375  for (i = 1;i <= n;i++)
9376  {
9377  for (sum = b[i], k = i - 1;k >= 1;k--)
9378  sum -= a[i*n+k] * x[k];
9379  x[i] = sum / p[i];
9380  }
9381  for (i = n;i >= 1;i--)
9382  {
9383  for (sum = x[i], k = i + 1;k <= n;k++)
9384  sum -= a[k*n+i] * x[k];
9385  x[i] = sum / p[i];
9386  }
9387 }
doublereal * x
#define i
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
doublereal * b
int * n
doublereal * a

◆ convlv()

void convlv ( double *  data,
int  n,
double *  respns,
int  m,
int  isign,
double *  ans 
)

◆ fact()

size_t fact ( int  num)
inline

Definition at line 91 of file numerical_recipes.h.

92 {
93  size_t value = 1;
94  if (num !=1 && num != 0)
95  {
96  for (int i = num; i > 0; --i)
97  value *= i;
98  }
99  return value;
100 
101 }
#define i

◆ four1() [1/2]

void four1 ( double  data[],
int  nn,
int  isign 
)

◆ four1() [2/2]

void four1 ( double *  data,
int  nn,
int  isign 
)

◆ fourn()

void fourn ( double  data[],
int  nn[],
int  ndim,
int  isign 
)

◆ gammln()

double gammln ( double  xx)

Definition at line 589 of file numerical_recipes.cpp.

590 {
591  double x, tmp, ser;
592  static double cof[6] =
593  {
594  76.18009173, -86.50532033, 24.01409822,
595  -1.231739516, 0.120858003e-2, -0.536382e-5
596  };
597  int j;
598 
599  x = xx - 1.0;
600  tmp = x + 5.5;
601  tmp -= (x + 0.5) * log(tmp);
602  ser = 1.0;
603  for (j = 0;j <= 5;j++)
604  {
605  x += 1.0;
606  ser += cof[j] / x;
607  }
608  return -tmp + log(2.50662827465*ser);
609 }
doublereal * x
void log(Image< double > &op)
#define j

◆ gammp()

double gammp ( double  a,
double  x 
)

Definition at line 9328 of file numerical_recipes.cpp.

9329 {
9330  double gamser, gammcf, gln;
9331 
9332  if (x < 0.0 || a <= 0.0)
9333  nrerror("Invalid arguments in routine gammp");
9334  if (x < (a + 1.0))
9335  {
9336  gser(&gamser, a, x, &gln);
9337  return gamser;
9338  }
9339  else
9340  {
9341  gcf(&gammcf, a, x, &gln);
9342  return 1.0 -gammcf;
9343  }
9344 }
void nrerror(const char error_text[])
void gcf(double *gammcf, double a, double x, double *gln)
doublereal * x
void gser(double *gamser, double a, double x, double *gln)
doublereal * a

◆ gasdev()

double gasdev ( int *  idum)

Definition at line 106 of file numerical_recipes.cpp.

107 {
108  static int iset = 0;
109  static double gset;
110  double fac, r, v1, v2;
111 
112  if (iset == 0)
113  {
114  do
115  {
116  v1 = 2.0 * ran1(idum) - 1.0;
117  v2 = 2.0 * ran1(idum) - 1.0;
118  r = v1 * v1 + v2 * v2;
119  }
120  while (r >= 1.0);
121  fac = sqrt(-2.0 * log(r) / r);
122  gset = v1 * fac;
123  iset = 1;
124  return v2*fac;
125  }
126  else
127  {
128  iset = 0;
129  return gset;
130  }
131 }
void sqrt(Image< double > &op)
double v1
void log(Image< double > &op)
double ran1(int *idum)
int idum

◆ gaussj()

template<class T >
void gaussj ( T *  a,
int  n,
T *  b,
int  m 
)

Definition at line 266 of file numerical_recipes.h.

267 {
268  T temp;
269  int i, icol=0, irow=0, j, k, l, ll;
270  T big, dum;
271  double pivinv;
272 
273  std::vector<int> buffer(3*n);
274  auto *indxc= buffer.data()-1;
275  auto *indxr= indxc + n;
276  auto *ipiv= indxr + n;
277  for (j = 1;j <= n;j++)
278  ipiv[j] = 0;
279  for (i = 1;i <= n;i++)
280  {
281  big = (T)0;
282  for (j = 1;j <= n;j++)
283  if (ipiv[j] != 1)
284  for (k = 1;k <= n;k++)
285  {
286  if (ipiv[k] == 0)
287  {
288  if (fabs((double)a[j*n+k]) >= (double) big)
289  {
290  big = ABS(a[j*n+k]);
291  irow = j;
292  icol = k;
293  }
294  }
295  else if (ipiv[k] > 1)
296  nrerror("GAUSSJ: Singular Matrix-1");
297  }
298  ++(ipiv[icol]);
299  if (irow != icol)
300  {
301  for (l = 1;l <= n;l++)
302  SWAP(a[irow*n+l], a[icol*n+l], temp)
303  for (l = 1;l <= m;l++)
304  SWAP(b[irow*n+l], b[icol*n+l], temp)
305  }
306  indxr[i] = irow;
307  indxc[i] = icol;
308  if (a[icol*n+icol] == 0.0)
309  nrerror("GAUSSJ: Singular Matrix-2");
310  pivinv = 1.0f / a[icol*n+icol];
311  a[icol*n+icol] = (T)1;
312  for (l = 1;l <= n;l++)
313  a[icol*n+l] = (T)(pivinv * a[icol*n+l]);
314  for (l = 1;l <= m;l++)
315  b[icol*n+l] = (T)(pivinv * b[icol*n+l]);
316  for (ll = 1;ll <= n;ll++)
317  if (ll != icol)
318  {
319  dum = a[ll*n+icol];
320  a[ll*n+icol] = (T)0;
321  for (l = 1;l <= n;l++)
322  a[ll*n+l] -= a[icol*n+l] * dum;
323  for (l = 1;l <= m;l++)
324  b[ll*n+l] -= b[icol*n+l] * dum;
325  }
326  }
327  for (l = n;l >= 1;l--)
328  {
329  if (indxr[l] != indxc[l])
330  for (k = 1;k <= n;k++)
331  SWAP(a[k*n+indxr[l]], a[k*n+indxc[l]], temp);
332  }
333 }
void nrerror(const char error_text[])
HBITMAP buffer
Definition: svm-toy.cpp:37
#define i
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
doublereal * b
#define ABS(x)
Definition: xmipp_macros.h:142
#define j
int m
#define SWAP(a, b, tmp)
Definition: xmipp_macros.h:428
int * n
doublereal * a

◆ grcnfd()

void grcnfd ( int  ,
int  ,
double *  ,
double *  ,
void(*)(int, int, double *, double *, void *)  ,
void *   
)

◆ grobfd()

void grobfd ( int  ,
int  ,
double *  ,
double *  ,
void(*)(int, int, double *, double *, void *)  ,
void *   
)

◆ indexx()

void indexx ( int  n,
double  arrin[],
int  indx[] 
)

Definition at line 206 of file numerical_recipes.cpp.

207 {
208  int l, j, ir, indxt, i;
209  double q;
210 
211  for (j = 1;j <= n;j++)
212  indx[j] = j;
213  l = (n >> 1) + 1;
214  ir = n;
215  for (;;)
216  {
217  if (l > 1)
218  q = arrin[(indxt=indx[--l])];
219  else
220  {
221  q = arrin[(indxt=indx[ir])];
222  indx[ir] = indx[1];
223  if (--ir == 1)
224  {
225  indx[1] = indxt;
226  return;
227  }
228  }
229  i = l;
230  j = l << 1;
231  while (j <= ir)
232  {
233  if (j < ir && arrin[indx[j]] < arrin[indx[j+1]])
234  j++;
235  if (q < arrin[indx[j]])
236  {
237  indx[i] = indx[j];
238  j += (i = j);
239  }
240  else
241  j = ir + 1;
242  }
243  indx[i] = indxt;
244  }
245 }
#define i
#define j
int * n
int ir

◆ ksone()

void ksone ( double  data[],
int  n,
double(*)(double)  func,
double *  d,
double *  prob 
)

Definition at line 165 of file numerical_recipes.cpp.

166 {
167  std::sort(data, data + n);
168  double fn, ff, en, dt, fo=0.;
169  en = (double)n;
170  *d = 0.;
171  for (int j=1; j<=n; j++)
172  {
173  fn = j / en;
174  ff = (*func)(data[j]);
175  dt = XMIPP_MAX(fabs(fo - ff), fabs(fn - ff));
176  if (dt> *d)
177  *d = dt;
178  fo = fn;
179  }
180  *prob = probks(sqrt(en)*(*d));
181 }
#define XMIPP_MAX(x, y)
Definition: xmipp_macros.h:193
double probks(double alam)
void sqrt(Image< double > &op)
doublereal * d
void sort(struct DCEL_T *dcel)
Definition: sorting.cpp:18
#define j
int * n

◆ lubksb()

template<class T >
void lubksb ( T *  a,
int  n,
int *  indx,
b[] 
)

Definition at line 237 of file numerical_recipes.h.

238 {
239  int i, ii = 0, ip, j;
240  T sum;
241 
242  for (i = 1;i <= n;i++)
243  {
244  ip = indx[i];
245  sum = b[ip];
246  b[ip] = b[i];
247  if (ii)
248  for (j = ii;j <= i - 1;j++)
249  sum -= a[i*n+j] * b[j];
250  else if (sum)
251  ii = i;
252  b[i] = sum;
253  }
254  for (i = n;i >= 1;i--)
255  {
256  sum = b[i];
257  for (j = i + 1;j <= n;j++)
258  sum -= a[i*n+j] * b[j];
259  b[i] = sum / a[i*n+i];
260  }
261 }
#define i
doublereal * b
#define j
int * n
doublereal * a

◆ ludcmp()

template<class T >
void ludcmp ( T *  a,
int  n,
int *  indx,
T *  d 
)

Definition at line 170 of file numerical_recipes.h.

171 {
172  int i, imax=0, j, k;
173  T big, dum, sum, temp;
174 
175  std::vector<T> buffer(n);
176  auto *vv= buffer.data()-1;
177  *d = (T)1.0;
178  for (i = 1;i <= n;i++)
179  {
180  big = (T)0.0;
181  for (j = 1;j <= n;j++)
182  if ((temp = (T)fabs((double)a[i*n+j])) > big)
183  big = temp;
184  if (big == (T)0.0)
185  nrerror("Singular matrix in routine LUDCMP");
186  vv[i] = (T)1.0 / big;
187  }
188  for (j = 1;j <= n;j++)
189  {
190  for (i = 1;i < j;i++)
191  {
192  sum = a[i*n+j];
193  for (k = 1;k < i;k++)
194  sum -= a[i*n+k] * a[k*n+j];
195  a[i*n+j] = sum;
196  }
197  big = (T)0.0;
198  for (i = j;i <= n;i++)
199  {
200  sum = a[i*n+j];
201  for (k = 1;k < j;k++)
202  sum -= a[i*n+k] * a[k*n+j];
203  a[i*n+j] = sum;
204  if ((dum = vv[i] * (T)fabs((double)sum)) >= big)
205  {
206  big = dum;
207  imax = i;
208  }
209  }
210  if (j != imax)
211  {
212  for (k = 1;k <= n;k++)
213  {
214  dum = a[imax*n+k];
215  a[imax*n+k] = a[j*n+k];
216  a[j*n+k] = dum;
217  }
218  *d = -(*d);
219  vv[imax] = vv[j];
220  }
221  indx[j] = imax;
222  if (a[j*n+j] == 0.0)
223  a[j*n+j] = (T) TINY;
224  if (j != n)
225  {
226  dum = (T)1.0 / (a[j*n+j]);
227  for (i = j + 1;i <= n;i++)
228  a[i*n+j] *= dum;
229  }
230  }
231 }
void nrerror(const char error_text[])
HBITMAP buffer
Definition: svm-toy.cpp:37
#define i
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
doublereal * d
double vv
#define j
#define TINY
int * n
doublereal * a

◆ nnls()

int nnls ( double *  a,
int  m,
int  n,
double *  b,
double *  x,
double *  rnorm,
double *  w,
double *  zz,
int *  index 
)

Definition at line 1165 of file numerical_recipes.cpp.

1183 {
1184  int pfeas, ret = 0, iz, jz, iz1, iz2, npp1, *index;
1185  double d1, d2, sm, up, ss, *w, *zz;
1186  int iter, k, j = 0, l, itmax, izmax = 0, nsetp, ii, jj = 0, ip;
1187  double temp, wmax, t, alpha, asave, dummy, unorm, ztest, cc;
1188 
1189 
1190  /* Check the parameters and data */
1191  if (m <= 0 || n <= 0 || a == NULL || b == NULL || x == NULL)
1192  return(2);
1193  /* Allocate memory for working space, if required */
1194  if (wp != NULL)
1195  w = wp;
1196  else
1197  w = (double*)calloc(n, sizeof(double));
1198  if (zzp != NULL)
1199  zz = zzp;
1200  else
1201  zz = (double*)calloc(m, sizeof(double));
1202  if (indexp != NULL)
1203  index = indexp;
1204  else
1205  index = (int*)calloc(n, sizeof(int));
1206  if (w == NULL || zz == NULL || index == NULL)
1207  return(2);
1208 
1209  /* Initialize the arrays INDEX[] and X[] */
1210  for (k = 0; k < n; k++)
1211  {
1212  x[k] = 0.;
1213  index[k] = k;
1214  }
1215  iz2 = n - 1;
1216  iz1 = 0;
1217  nsetp = 0;
1218  npp1 = 0;
1219 
1220  /* Main loop; quit if all coeffs are already in the solution or */
1221  /* if M cols of A have been triangularized */
1222  iter = 0;
1223  itmax = n * 3;
1224  while (iz1 <= iz2 && nsetp < m)
1225  {
1226  /* Compute components of the dual (negative gradient) vector W[] */
1227  for (iz = iz1; iz <= iz2; iz++)
1228  {
1229  j = index[iz];
1230  sm = 0.;
1231  for (l = npp1; l < m; l++)
1232  sm += a[j*m+l] * b[l];
1233  w[j] = sm;
1234  }
1235 
1236  while (1)
1237  {
1238  /* Find largest positive W[j] */
1239  for (wmax = 0., iz = iz1; iz <= iz2; iz++)
1240  {
1241  j = index[iz];
1242  if (w[j] > wmax)
1243  {
1244  wmax = w[j];
1245  izmax = iz;
1246  }
1247  }
1248 
1249  /* Terminate if wmax<=0.; */
1250  /* it indicates satisfaction of the Kuhn-Tucker conditions */
1251  if (wmax <= 0.0)
1252  break;
1253  iz = izmax;
1254  j = index[iz];
1255 
1256  /* The sign of W[j] is ok for j to be moved to set P. */
1257  /* Begin the transformation and check new diagonal element to avoid */
1258  /* near linear dependence. */
1259  asave = a[j*m+npp1];
1260  _nnls_h12(1, npp1, npp1 + 1, m, &a[j*m+0], 1, &up, &dummy, 1, 1, 0);
1261  unorm = 0.;
1262  if (nsetp != 0)
1263  for (l = 0; l < nsetp; l++)
1264  {
1265  d1 = a[j*m+l];
1266  unorm += d1 * d1;
1267  }
1268  unorm = sqrt(unorm);
1269  d2 = unorm + (d1 = a[j*m+npp1], fabs(d1)) * 0.01;
1270  if ((d2 - unorm) > 0.)
1271  {
1272  /* Col j is sufficiently independent. Copy B into ZZ, update ZZ */
1273  /* and solve for ztest ( = proposed new value for X[j] ) */
1274  for (l = 0; l < m; l++)
1275  zz[l] = b[l];
1276  _nnls_h12(2, npp1, npp1 + 1, m, &a[j*m+0], 1, &up, zz, 1, 1, 1);
1277  ztest = zz[npp1] / a[j*m+npp1];
1278  /* See if ztest is positive */
1279  if (ztest > 0.)
1280  break;
1281  }
1282 
1283  /* Reject j as a candidate to be moved from set Z to set P. Restore */
1284  /* A[npp1,j], set W[j]=0., and loop back to test dual coeffs again */
1285  a[j*m+npp1] = asave;
1286  w[j] = 0.;
1287  } /* while(1) */
1288  if (wmax <= 0.0)
1289  break;
1290 
1291  /* Index j=INDEX[iz] has been selected to be moved from set Z to set P. */
1292  /* Update B and indices, apply householder transformations to cols in */
1293  /* new set Z, zero subdiagonal elts in col j, set W[j]=0. */
1294  for (l = 0; l < m; ++l)
1295  b[l] = zz[l];
1296  index[iz] = index[iz1];
1297  index[iz1] = j;
1298  iz1++;
1299  nsetp = npp1 + 1;
1300  npp1++;
1301  if (iz1 <= iz2)
1302  for (jz = iz1; jz <= iz2; jz++)
1303  {
1304  jj = index[jz];
1305  _nnls_h12(2, nsetp - 1, npp1, m, &a[j*m+0], 1, &up,
1306  &a[jj*m+0], 1, m, 1);
1307  }
1308  if (nsetp != m)
1309  for (l = npp1; l < m; l++)
1310  a[j*m+l] = 0.;
1311  w[j] = 0.;
1312  /* Solve the triangular system; store the solution temporarily in Z[] */
1313  for (l = 0; l < nsetp; l++)
1314  {
1315  ip = nsetp - (l + 1);
1316  if (l != 0)
1317  for (ii = 0; ii <= ip; ii++)
1318  zz[ii] -= a[jj*m+ii] * zz[ip+1];
1319  jj = index[ip];
1320  zz[ip] /= a[jj*m+ip];
1321  }
1322 
1323  /* Secondary loop begins here */
1324  while (++iter < itmax)
1325  {
1326  /* See if all new constrained coeffs are feasible; if not, compute alpha */
1327  for (alpha = 2.0, ip = 0; ip < nsetp; ip++)
1328  {
1329  l = index[ip];
1330  if (zz[ip] <= 0.)
1331  {
1332  t = -x[l] / (zz[ip] - x[l]);
1333  if (alpha > t)
1334  {
1335  alpha = t;
1336  jj = ip - 1;
1337  }
1338  }
1339  }
1340 
1341  /* If all new constrained coeffs are feasible then still alpha==2. */
1342  /* If so, then exit from the secondary loop to main loop */
1343  if (alpha == 2.0)
1344  break;
1345  /* Use alpha (0.<alpha<1.) to interpolate between old X and new ZZ */
1346  for (ip = 0; ip < nsetp; ip++)
1347  {
1348  l = index[ip];
1349  x[l] += alpha * (zz[ip] - x[l]);
1350  }
1351 
1352  /* Modify A and B and the INDEX arrays to move coefficient i */
1353  /* from set P to set Z. */
1354  k = index[jj+1];
1355  pfeas = 1;
1356  do
1357  {
1358  x[k] = 0.;
1359  if (jj != (nsetp - 1))
1360  {
1361  jj++;
1362  for (j = jj + 1; j < nsetp; j++)
1363  {
1364  ii = index[j];
1365  index[j-1] = ii;
1366  _nnls_g1(a[ii*m+j-1], a[ii*m+j], &cc, &ss, &a[ii*m+j-1]);
1367  for (a[ii*m+j] = 0., l = 0; l < n; l++)
1368  if (l != ii)
1369  {
1370  /* Apply procedure G2 (CC,SS,A(J-1,L),A(J,L)) */
1371  temp = a[l*m+j-1];
1372  a[l*m+j-1] = cc * temp + ss * a[l*m+j];
1373  a[l*m+j] = -ss * temp + cc * a[l*m+j];
1374  }
1375  /* Apply procedure G2 (CC,SS,B(J-1),B(J)) */
1376  temp = b[j-1];
1377  b[j-1] = cc * temp + ss * b[j];
1378  b[j] = -ss * temp + cc * b[j];
1379  }
1380  }
1381  npp1 = nsetp - 1;
1382  nsetp--;
1383  iz1--;
1384  index[iz1] = k;
1385 
1386  /* See if the remaining coeffs in set P are feasible; they should */
1387  /* be because of the way alpha was determined. If any are */
1388  /* infeasible it is due to round-off error. Any that are */
1389  /* nonpositive will be set to zero and moved from set P to set Z */
1390  for (jj = 0; jj < nsetp; jj++)
1391  {
1392  k = index[jj];
1393  if (x[k] <= 0.)
1394  {
1395  pfeas = 0;
1396  break;
1397  }
1398  }
1399  }
1400  while (pfeas == 0);
1401 
1402  /* Copy B[] into zz[], then solve again and loop back */
1403  for (k = 0; k < m; k++)
1404  zz[k] = b[k];
1405  for (l = 0; l < nsetp; l++)
1406  {
1407  ip = nsetp - (l + 1);
1408  if (l != 0)
1409  for (ii = 0; ii <= ip; ii++)
1410  zz[ii] -= a[jj*m+ii] * zz[ip+1];
1411  jj = index[ip];
1412  zz[ip] /= a[jj*m+ip];
1413  }
1414  } /* end of secondary loop */
1415  if (iter > itmax)
1416  {
1417  ret = 1;
1418  break;
1419  }
1420  for (ip = 0; ip < nsetp; ip++)
1421  {
1422  k = index[ip];
1423  x[k] = zz[ip];
1424  }
1425  } /* end of main loop */
1426  /* Compute the norm of the final residual vector */
1427  sm = 0.;
1428  if (npp1 < m)
1429  for (k = npp1; k < m; k++)
1430  sm += (b[k] * b[k]);
1431  else
1432  for (j = 0; j < n; j++)
1433  w[j] = 0.;
1434  *rnorm = sqrt(sm);
1435  /* Free working space, if it was allocated here */
1436  if (wp == NULL)
1437  free(w);
1438  if (zzp == NULL)
1439  free(zz);
1440  if (indexp == NULL)
1441  free(index);
1442  return(ret);
1443 } /* nnls_ */
double alpha
Smoothness parameter.
Definition: blobs.h:121
void sqrt(Image< double > &op)
doublereal * w
glob_prnt iter
void _nnls_g1(double a, double b, double *cterm, double *sterm, double *sig)
doublereal * x
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
doublereal * b
viol index
free((char *) ob)
double dummy
#define j
int _nnls_h12(int mode, int lpivot, int l1, int m, double *u, int u_dim1, double *up, double *cm, int ice, int icv, int ncv)
int * n
doublereal * a

◆ nnlsWght()

int nnlsWght ( int  N,
int  M,
double *  A,
double *  b,
double *  weight 
)

Definition at line 1455 of file numerical_recipes.cpp.

1456 {
1457  int n, m;
1458  double *w;
1459 
1460  /* Check the arguments */
1461  if (N < 1 || M < 1 || A == NULL || b == NULL || weight == NULL)
1462  return(1);
1463 
1464  /* Allocate memory */
1465  w = (double*)malloc(M * sizeof(double));
1466  if (w == NULL)
1467  return(2);
1468 
1469  /* Check that weights are not zero and get the square roots of them to w[] */
1470  for (m = 0; m < M; m++)
1471  {
1472  if (weight[m] <= 1.0e-20)
1473  w[m] = 0.0;
1474  else
1475  w[m] = sqrt(weight[m]);
1476  }
1477 
1478  /* Multiply rows of matrix A and elements of vector b with weights*/
1479  for (m = 0; m < M; m++)
1480  {
1481  for (n = 0; n < N; n++)
1482  {
1483  A[n*M+m] *= w[m];
1484  }
1485  b[m] *= w[m];
1486  }
1487 
1488  free(w);
1489  return(0);
1490 }
void sqrt(Image< double > &op)
doublereal * w
doublereal * b
free((char *) ob)
int * n

◆ nrerror()

void nrerror ( const char  error_text[])

Definition at line 35 of file numerical_recipes.cpp.

36 {
37  fprintf(stderr, "Numerical Recipes run-time error...\n");
38  fprintf(stderr, "%s\n", error_text);
39  fprintf(stderr, "...now exiting to system...\n");
40  exit(1);
41 }
fprintf(glob_prnt.io, "\)

◆ polint()

void polint ( double *  xa,
double *  ya,
int  n,
double  x,
double &  y,
double &  dy 
)

Definition at line 9390 of file numerical_recipes.cpp.

9391 {
9392  int i, m, ns = 1;
9393  double den, dif, dift, ho, hp, w;
9394  dif = fabs(x - xa[1]);
9395  std::vector<double> buffer(2*n);
9396  auto *c= buffer.data()-1;
9397  auto *d= c + n;
9398  for (i = 1;i <= n;i++)
9399  {
9400  if ((dift = fabs(x - xa[i])) < dif)
9401  {
9402  ns = i;
9403  dif = dift;
9404  }
9405  c[i] = ya[i];
9406  d[i] = ya[i];
9407  }
9408  y = ya[ns--];
9409  for (m = 1;m < n;m++)
9410  {
9411  for (i = 1;i <= n - m;i++)
9412  {
9413  ho = xa[i] - x;
9414  hp = xa[i+m] - x;
9415  w = c[i+1] - d[i];
9416  if ((den = ho - hp) == 0.0)
9417  {
9418  nrerror("error in routine polint\n");
9419  }
9420  den = w / den;
9421  d[i] = hp * den;
9422  c[i] = ho * den;
9423  }
9424  y += (dy = (2 * ns < (n - m) ? c[ns+1] : d[ns--]));
9425  }
9426 }
doublereal * c
HBITMAP buffer
Definition: svm-toy.cpp:37
static double * y
doublereal * w
void nrerror(const char error_text[])
doublereal * x
#define i
doublereal * d
int * n

◆ powell()

void powell ( double *  p,
double *  xi,
int  n,
double  ftol,
int &  iter,
double &  fret,
double(*)(double *, void *)  func,
void *  prm,
bool  show 
)

Definition at line 877 of file numerical_recipes.cpp.

880 {
881  int i, ibig, j;
882  double t, fptt, fp, del;
883  std::vector<double> buffer(3*n);
884  auto *pt= buffer.data()-1;
885  auto *ptt= pt + n;
886  auto *xit= ptt + n;
887  bool different_from_0;
888 
889  fret = (*func)(p,prm);
890  for (j = 1;j <= n;j++)
891  pt[j] = p[j];
892 
893  for (iter = 1;;(iter)++)
894  {
895  /* By coss ----- */
896  if (show)
897  {
898  std::cout << iter << " (" << p[1];
899  for (int co = 2; co <= n; co++)
900  std::cout << "," << p[co];
901  std::cout << ")--->" << fret << std::endl;
902  }
903  /* ------------- */
904 
905  fp = fret;
906  ibig = 0;
907  del = 0.0;
908  for (i = 1;i <= n;i++)
909  {
910  different_from_0 = false; // CO
911  for (j = 1;j <= n;j++)
912  {
913  xit[j] = xi[j*n+i];
914  if (xit[j] != 0)
915  different_from_0 = true;
916  }
917  if (different_from_0)
918  {
919  fptt = fret;
920  linmin(p, xit, n, fret, func, prm);
921  if (fabs(fptt - fret) > del)
922  {
923  del = fabs(fptt - fret);
924  ibig = i;
925  }
926  /* By coss ----- */
927  if (show)
928  {
929  std::cout << " (";
930  if (i == 1)
931  std::cout << "***";
932  std::cout << p[1];
933  for (int co = 2; co <= n; co++)
934  {
935  std::cout << ",";
936  if (co == i)
937  std::cout << "***";
938  std::cout << p[co];
939  }
940  std::cout << ")--->" << fret << std::endl;
941  }
942  /* ------------- */
943  }
944  }
945  if (2.0*fabs(fp - fret) <= ftol*(fabs(fp) + fabs(fret)) || n==1) return;
946  if (iter == ITMAX)
947  nrerror("Too many iterations in routine POWELL");
948  for (j = 1;j <= n;j++)
949  {
950  ptt[j] = 2.0 * p[j] - pt[j];
951  xit[j] = p[j] - pt[j];
952  pt[j] = p[j];
953  }
954  fptt = (*func)(ptt,prm);
955  if (fptt < fp)
956  {
957 #define SQR(a) ((a)*(a))
958  t = 2.0 * (fp - 2.0 * fret + fptt) * SQR(fp - fret - del) - del * SQR(fp - fptt);
959  if (t < 0.0)
960  {
961  linmin(p, xit, n, fret, func, prm);
962  for (j = 1;j <= n;j++)
963  xi[j*n+ibig] = xit[j];
964  }
965  }
966  }
967 }
double xi
HBITMAP buffer
Definition: svm-toy.cpp:37
float del
void nrerror(const char error_text[])
glob_prnt iter
#define i
#define SQR(a)
void linmin(double *p, double *xi, int n, double &fret, double(*func)(double *, void *), void *prm)
#define ITMAX
#define j
ProgClassifyCL2D * prm
int * n

◆ probks()

double probks ( double  alam)

Definition at line 184 of file numerical_recipes.cpp.

185 {
186  int j;
187  double a2, fac=2.0, sum=0.0, term, termbf=0.0;
188  double EPS1=0.001, EPS2=1.0e-8;
189 
190  a2 = -2.0 * alam * alam;
191  for (j = 1; j<= 100; j++)
192  {
193  term = fac * exp(a2*j*j);
194  sum += term;
195  if (fabs(term) <= EPS1*termbf || fabs(term) <= EPS2*sum)
196  return sum;
197  fac = -fac;
198  termbf = fabs(term);
199  }
200  return 1.0;
201 
202 }
#define j

◆ pwt()

void pwt ( double  a[],
unsigned long  n,
int  isign 
)

◆ pwtset()

void pwtset ( int  n)

◆ ran1()

double ran1 ( int *  idum)

Definition at line 58 of file numerical_recipes.cpp.

59 {
60  static long ix1, ix2, ix3;
61  static double r[98];
62  double temp;
63  static int iff = 0;
64  int j;
65 
66  if (*idum < 0 || iff == 0)
67  {
68  iff = 1;
69  ix1 = (IC1 - (*idum)) % M1;
70  ix1 = (IA1 * ix1 + IC1) % M1;
71  ix2 = ix1 % M2;
72  ix1 = (IA1 * ix1 + IC1) % M1;
73  ix3 = ix1 % M3;
74  for (j = 1;j <= 97;j++)
75  {
76  ix1 = (IA1 * ix1 + IC1) % M1;
77  ix2 = (IA2 * ix2 + IC2) % M2;
78  r[j] = (ix1 + ix2 * RM2) * RM1;
79  }
80  *idum = 1;
81  }
82  ix1 = (IA1 * ix1 + IC1) % M1;
83  ix2 = (IA2 * ix2 + IC2) % M2;
84  ix3 = (IA3 * ix3 + IC3) % M3;
85  j = 1 + ((97 * ix3) / M3);
86  if (j > 97 || j < 1)
87  nrerror("RAN1: This cannot happen.");
88  temp = r[j];
89  r[j] = (ix1 + ix2 * RM2) * RM1;
90  return temp;
91 }
#define IC2
void nrerror(const char error_text[])
#define M3
#define RM2
#define M2
#define M1
#define RM1
#define j
#define IA2
#define IA3
#define IC1
#define IC3
int idum
#define IA1

◆ realft() [1/2]

void realft ( double  data[],
int  n,
int  isign 
)

◆ realft() [2/2]

void realft ( double *  data,
int  n,
int  isign 
)

◆ sinc()

double sinc ( double  x)
inline

Definition at line 81 of file numerical_recipes.h.

82 {
83  if (fabs(x)<0.0001)
84  return 1;
85  else
86  {
87  double arg=PI*x;
88  return sin(arg)/arg;
89  }
90 }
doublereal * x
#define PI
Definition: tools.h:43

◆ svbksb()

void svbksb ( double *  u,
double *  w,
double *  v,
int  m,
int  n,
double *  b,
double *  x 
)

Definition at line 1791 of file numerical_recipes.cpp.

1792 {
1793  int jj, j, i;
1794  double s;
1795 
1796  std::vector<double> buffer(n);
1797  auto *tmp= buffer.data()-1;
1798  for (j = 1;j <= n;j++)
1799  {
1800  s = 0.0;
1801  if (w[j])
1802  {
1803  for (i = 1;i <= m;i++)
1804  s += u[i*n+j] * b[i];
1805  s /= w[j];
1806  }
1807  tmp[j] = s;
1808  }
1809  for (j = 1;j <= n;j++)
1810  {
1811  s = 0.0;
1812  for (jj = 1;jj <= n;jj++)
1813  s += v[j*n+jj] * tmp[jj];
1814  x[j] = s;
1815  }
1816 }
HBITMAP buffer
Definition: svm-toy.cpp:37
doublereal * w
doublereal * x
#define i
doublereal * b
#define j
doublereal * u
int * n

◆ svdcmp()

void svdcmp ( double *  a,
int  m,
int  n,
double *  w,
double *  v 
)

Definition at line 1507 of file numerical_recipes.cpp.

1508 {
1509  double Norm, Scale;
1510  double c, f, g, h, s;
1511  double x, y, z;
1512  long i, its, j, jj, k, l = 0L, nm = 0L;
1513  bool Flag;
1514  int MaxIterations = SVDMAXITER;
1515 
1516  std::vector<double> buffer(Columns*Columns);
1517  auto *rv1= buffer.data();
1518  g = Scale = Norm = 0.0;
1519  for (i = 0L; (i < Columns); i++)
1520  {
1521  l = i + 1L;
1522  rv1[i] = Scale * g;
1523  g = s = Scale = 0.0;
1524  if (i < Lines)
1525  {
1526  for (k = i; (k < Lines); k++)
1527  {
1528  Scale += fabs(U[k * Columns + i]);
1529  }
1530  if (Scale != 0.0)
1531  {
1532  for (k = i; (k < Lines); k++)
1533  {
1534  U[k * Columns + i] /= Scale;
1535  s += U[k * Columns + i] * U[k * Columns + i];
1536  }
1537  f = U[i * Columns + i];
1538  g = (0.0 <= f) ? (-sqrt(s)) : (sqrt(s));
1539  h = f * g - s;
1540  U[i * Columns + i] = f - g;
1541  for (j = l; (j < Columns); j++)
1542  {
1543  for (s = 0.0, k = i; (k < Lines); k++)
1544  {
1545  s += U[k * Columns + i] * U[k * Columns + j];
1546  }
1547  f = s / h;
1548  for (k = i; (k < Lines); k++)
1549  {
1550  U[k * Columns + j] += f * U[k * Columns + i];
1551  }
1552  }
1553  for (k = i; (k < Lines); k++)
1554  {
1555  U[k * Columns + i] *= Scale;
1556  }
1557  }
1558  }
1559  W[i] = Scale * g;
1560  g = s = Scale = 0.0;
1561  if ((i < Lines) && (i != (Columns - 1L)))
1562  {
1563  for (k = l; (k < Columns); k++)
1564  {
1565  Scale += fabs(U[i * Columns + k]);
1566  }
1567  if (Scale != 0.0)
1568  {
1569  for (k = l; (k < Columns); k++)
1570  {
1571  U[i * Columns + k] /= Scale;
1572  s += U[i * Columns + k] * U[i * Columns + k];
1573  }
1574  f = U[i * Columns + l];
1575  g = (0.0 <= f) ? (-sqrt(s)) : (sqrt(s));
1576  h = f * g - s;
1577  U[i * Columns + l] = f - g;
1578  for (k = l; (k < Columns); k++)
1579  {
1580  rv1[k] = U[i * Columns + k] / h;
1581  }
1582  for (j = l; (j < Lines); j++)
1583  {
1584  for (s = 0.0, k = l; (k < Columns); k++)
1585  {
1586  s += U[j * Columns + k] * U[i * Columns + k];
1587  }
1588  for (k = l; (k < Columns); k++)
1589  {
1590  U[j * Columns + k] += s * rv1[k];
1591  }
1592  }
1593  for (k = l; (k < Columns); k++)
1594  {
1595  U[i * Columns + k] *= Scale;
1596  }
1597  }
1598  }
1599  Norm = ((fabs(W[i]) + fabs(rv1[i])) < Norm) ? (Norm) : (fabs(W[i]) + fabs(rv1[i]));
1600  }
1601  for (i = Columns - 1L; (0L <= i); i--)
1602  {
1603  if (i < (Columns - 1L))
1604  {
1605  if (g != 0.0)
1606  {
1607  for (j = l; (j < Columns); j++)
1608  {
1609  V[j * Columns + i] = U[i * Columns + j] / (U[i * Columns + l] * g);
1610  }
1611  for (j = l; (j < Columns); j++)
1612  {
1613  for (s = 0.0, k = l; (k < Columns); k++)
1614  {
1615  s += U[i * Columns + k] * V[k * Columns + j];
1616  }
1617  for (k = l; (k < Columns); k++)
1618  {
1619  if (s != 0.0)
1620  {
1621  V[k * Columns + j] += s * V[k * Columns + i];
1622  }
1623  }
1624  }
1625  }
1626  for (j = l; (j < Columns); j++)
1627  {
1628  V[i * Columns + j] = V[j * Columns + i] = 0.0;
1629  }
1630  }
1631  V[i * Columns + i] = 1.0;
1632  g = rv1[i];
1633  l = i;
1634  }
1635  for (i = (Lines < Columns) ? (Lines - 1L) : (Columns - 1L); (0L <= i); i--)
1636  {
1637  l = i + 1L;
1638  g = W[i];
1639  for (j = l; (j < Columns); j++)
1640  {
1641  U[i * Columns + j] = 0.0;
1642  }
1643  if (g != 0.0)
1644  {
1645  g = 1.0 / g;
1646  for (j = l; (j < Columns); j++)
1647  {
1648  for (s = 0.0, k = l; (k < Lines); k++)
1649  {
1650  s += U[k * Columns + i] * U[k * Columns + j];
1651  }
1652  f = s * g / U[i * Columns + i];
1653  for (k = i; (k < Lines); k++)
1654  {
1655  if (f != 0.0)
1656  {
1657  U[k * Columns + j] += f * U[k * Columns + i];
1658  }
1659  }
1660  }
1661  for (j = i; (j < Lines); j++)
1662  {
1663  U[j * Columns + i] *= g;
1664  }
1665  }
1666  else
1667  {
1668  for (j = i; (j < Lines); j++)
1669  {
1670  U[j * Columns + i] = 0.0;
1671  }
1672  }
1673  U[i * Columns + i] += 1.0;
1674  }
1675  for (k = Columns - 1L; (0L <= k); k--)
1676  {
1677  for (its = 1L; (its <= MaxIterations); its++)
1678  {
1679  Flag = true;
1680  for (l = k; (0L <= l); l--)
1681  {
1682  nm = l - 1L;
1683  if ((fabs(rv1[l]) + Norm) == Norm)
1684  {
1685  Flag = false;
1686  break;
1687  }
1688  if ((fabs(W[nm]) + Norm) == Norm)
1689  {
1690  break;
1691  }
1692  }
1693  if (Flag)
1694  {
1695  c = 0.0;
1696  s = 1.0;
1697  for (i = l; (i <= k); i++)
1698  {
1699  f = s * rv1[i];
1700  rv1[i] *= c;
1701  if ((fabs(f) + Norm) == Norm)
1702  {
1703  break;
1704  }
1705  g = W[i];
1706  h = Pythag(f, g);
1707  W[i] = h;
1708  h = 1.0 / h;
1709  c = g * h;
1710  s = -f * h;
1711  for (j = 0L; (j < Lines); j++)
1712  {
1713  y = U[j * Columns + nm];
1714  z = U[j * Columns + i];
1715  U[j * Columns + nm] = y * c + z * s;
1716  U[j * Columns + i] = z * c - y * s;
1717  }
1718  }
1719  }
1720  z = W[k];
1721  if (l == k)
1722  {
1723  if (z < 0.0)
1724  {
1725  W[k] = -z;
1726  for (j = 0L; (j < Columns); j++)
1727  {
1728  V[j * Columns + k] = -V[j * Columns + k];
1729  }
1730  }
1731  break;
1732  }
1733  if (its == MaxIterations) return;
1734  x = W[l];
1735  nm = k - 1L;
1736  y = W[nm];
1737  g = rv1[nm];
1738  h = rv1[k];
1739  f = ((y - z) * (y + z) + (g - h) * (g + h)) / (2.0 * h * y);
1740  g = Pythag(f, 1.0);
1741  f = ((x - z) * (x + z) + h * ((y / (f + ((0.0 <= f) ? (fabs(g))
1742  : (-fabs(g))))) - h)) / x;
1743  c = s = 1.0;
1744  for (j = l; (j <= nm); j++)
1745  {
1746  i = j + 1L;
1747  g = rv1[i];
1748  y = W[i];
1749  h = s * g;
1750  g = c * g;
1751  z = Pythag(f, h);
1752  rv1[j] = z;
1753  c = f / z;
1754  s = h / z;
1755  f = x * c + g * s;
1756  g = g * c - x * s;
1757  h = y * s;
1758  y *= c;
1759  for (jj = 0L; (jj < Columns); jj++)
1760  {
1761  x = V[jj * Columns + j];
1762  z = V[jj * Columns + i];
1763  V[jj * Columns + j] = x * c + z * s;
1764  V[jj * Columns + i] = z * c - x * s;
1765  }
1766  z = Pythag(f, h);
1767  W[j] = z;
1768  if (z != 0.0)
1769  {
1770  z = 1.0 / z;
1771  c = f * z;
1772  s = h * z;
1773  }
1774  f = c * g + s * y;
1775  x = c * y - s * g;
1776  for (jj = 0L; (jj < Lines); jj++)
1777  {
1778  y = U[jj * Columns + j];
1779  z = U[jj * Columns + i];
1780  U[jj * Columns + j] = y * c + z * s;
1781  U[jj * Columns + i] = z * c - y * s;
1782  }
1783  }
1784  rv1[l] = 0.0;
1785  rv1[k] = f;
1786  W[k] = x;
1787  }
1788  }
1789 }
doublereal * c
doublereal * g
void sqrt(Image< double > &op)
HBITMAP buffer
Definition: svm-toy.cpp:37
static double * y
doublereal * x
#define i
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
double * f
double z
#define SVDMAXITER
#define j
double Pythag(double a, double b)

◆ tdev()

double tdev ( double  nu,
int *  idum 
)

Definition at line 136 of file numerical_recipes.cpp.

137 {
138  static int iset = 0;
139  static double gset;
140  double fac, r, v1, v2;
141 
142  if (iset == 0)
143  {
144  do
145  {
146  v1 = 2.0 * ran1(idum) - 1.0;
147  v2 = 2.0 * ran1(idum) - 1.0;
148  r = v1 * v1 + v2 * v2;
149  }
150  while (r >= 1.0);
151  fac = sqrt(nu*(pow(r,-2.0/nu) -1.0)/r);
152  gset = v1 * fac;
153  iset = 1;
154  return v2*fac;
155  }
156  else
157  {
158  iset = 0;
159  return gset;
160  }
161 }
void sqrt(Image< double > &op)
double v1
double ran1(int *idum)
int idum

◆ twofft()

void twofft ( double *  data1,
double *  data2,
double *  fft1,
double *  fft2,
int  n 
)

◆ wtn()

void wtn ( double  a[],
unsigned long  nn[],
int  ndim,
int  isign,
void(*)(double [], unsigned long, int)  wtstep 
)