mirror of
https://bitbucket.org/cosmicvoids/vide_public.git
synced 2025-07-04 23:31:12 +00:00
beginning to fold in HOD code with jeremy tinker's approval
This commit is contained in:
parent
d8108d3a8e
commit
44cd0eb71f
95 changed files with 21950 additions and 0 deletions
58
c_tools/hod/powell.c
Normal file
58
c_tools/hod/powell.c
Normal file
|
@ -0,0 +1,58 @@
|
|||
#include <math.h>
|
||||
#define NRANSI
|
||||
#include "nrutil.h"
|
||||
#define ITMAX 200
|
||||
|
||||
void powell(double p[], double **xi, int n, double ftol, int *iter, double *fret,
|
||||
double (*func)(double []))
|
||||
{
|
||||
void linmin(double p[], double xi[], int n, double *fret,
|
||||
double (*func)(double []));
|
||||
int i,ibig,j;
|
||||
double del,fp,fptt,t,*pt,*ptt,*xit;
|
||||
|
||||
pt=dvector(1,n);
|
||||
ptt=dvector(1,n);
|
||||
xit=dvector(1,n);
|
||||
*fret=(*func)(p);
|
||||
for (j=1;j<=n;j++) pt[j]=p[j];
|
||||
for (*iter=1;;++(*iter)) {
|
||||
fp=(*fret);
|
||||
ibig=0;
|
||||
del=0.0;
|
||||
for (i=1;i<=n;i++) {
|
||||
for (j=1;j<=n;j++) xit[j]=xi[j][i];
|
||||
fptt=(*fret);
|
||||
linmin(p,xit,n,fret,func);
|
||||
if (fabs(fptt-(*fret)) > del) {
|
||||
del=fabs(fptt-(*fret));
|
||||
ibig=i;
|
||||
}
|
||||
}
|
||||
if (2.0*fabs(fp-(*fret)) <= ftol*(fabs(fp)+fabs(*fret))) {
|
||||
free_dvector(xit,1,n);
|
||||
free_dvector(ptt,1,n);
|
||||
free_dvector(pt,1,n);
|
||||
return;
|
||||
}
|
||||
if (*iter == ITMAX) nrerror("powell exceeding maximum iterations.");
|
||||
for (j=1;j<=n;j++) {
|
||||
ptt[j]=2.0*p[j]-pt[j];
|
||||
xit[j]=p[j]-pt[j];
|
||||
pt[j]=p[j];
|
||||
}
|
||||
fptt=(*func)(ptt);
|
||||
if (fptt < fp) {
|
||||
t=2.0*(fp-2.0*(*fret)+fptt)*SQR(fp-(*fret)-del)-del*SQR(fp-fptt);
|
||||
if (t < 0.0) {
|
||||
linmin(p,xit,n,fret,func);
|
||||
for (j=1;j<=n;j++) {
|
||||
xi[j][ibig]=xi[j][n];
|
||||
xi[j][n]=xit[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#undef ITMAX
|
||||
#undef NRANSI
|
Loading…
Add table
Add a link
Reference in a new issue