Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

steepest.h File Reference

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Functions

void Utilit1 (double *, double *, int)
void Utilit2 (double *X, double *X1, double *Y, double *D, double *dd, double xk, int l, float(*my_func)(EMData *, EMData *, EMData *, float, float, float), EMData *image, EMData *refim, EMData *mask)
void Derivatives (double *X, double *D, double *Y, double *dd, double xk, int l, float(*my_func)(EMData *, EMData *, EMData *, float, float, float), EMData *, EMData *, EMData *)
void Steepda (double *X, double xk, double e, int l, int m, int *n, float(*my_func)(EMData *, EMData *, EMData *, float, float, float), EMData *, EMData *, EMData *)
void Utilit2_G (double *X, double *X1, double *Y, double *D, double *dd, double xk, int l, float(*my_func)(EMData *, EMData *, EMData *, Util::KaiserBessel &, float, float, float), EMData *image, EMData *refim, EMData *mask, Util::KaiserBessel &kb)
void Derivatives_G (double *X, double *D, double *Y, double *dd, double xk, int l, float(*my_func)(EMData *, EMData *, EMData *, Util::KaiserBessel &, float, float, float), EMData *image, EMData *refim, EMData *mask, Util::KaiserBessel &kb)
void Steepda_G (double *X, double xk, double e, int l, int m, int *n, float(*my_func)(EMData *, EMData *, EMData *, Util::KaiserBessel &, float, float, float), EMData *image, EMData *refim, EMData *mask, Util::KaiserBessel &kb)


Function Documentation

void Derivatives double *  X,
double *  D,
double *  Y,
double *  dd,
double  xk,
int  l,
float(*)(EMData *, EMData *, EMData *, float, float, float)  my_func,
EMData ,
EMData ,
EMData
 

Definition at line 79 of file steepest.cpp.

References b, Utilit1(), X, and Y.

Referenced by Steepda().

00080                          {
00081     double a,b,yy;
00082     int i;
00083     for (i=1; i<l+1; i++) {
00084       // Save X(i)
00085       a=X[i];
00086       // Find increment
00087       b=D[i]*xk/(2.0*(*dd));
00088       // Move increment in X(i)
00089       X[i]=X[i]+b;
00090       // Obtain yy
00091       yy=(*my_func)(image, refim, mask, (float)X[1], (float)X[2], (float)X[3]);
00092       // Guard against divide by zero near maximum
00093       if (b==0) b=1e-12;
00094       // Update D(i)
00095       D[i]=(yy-Y[3])/b;
00096       // Guard against locked up derivative
00097       if (D[i]==0) D[i]=1e-5;
00098       // Restore X(i) and yy
00099       X[i]=a; yy=Y[3];
00100     }
00101     // Obtain dd
00102     Utilit1(D, dd, l);
00103   }

void Derivatives_G double *  X,
double *  D,
double *  Y,
double *  dd,
double  xk,
int  l,
float(*)(EMData *, EMData *, EMData *, Util::KaiserBessel &, float, float, float)  my_func,
EMData image,
EMData refim,
EMData mask,
Util::KaiserBessel kb
 

Definition at line 223 of file steepest.cpp.

References b, Utilit1(), X, and Y.

Referenced by Steepda_G().

00224                                                {
00225     double a,b,yy;
00226     int i;
00227     for (i=1; i<l+1; i++) {
00228       // Save X(i)
00229       a=X[i];
00230       // Find increment
00231       b=D[i]*xk/(2.0*(*dd));
00232       // Move increment in X(i)
00233       X[i]=X[i]+b;
00234       // Obtain yy
00235       yy=(*my_func)(image, refim, mask, kb, (float)X[1], (float)X[2], (float)X[3]);
00236       // Guard against divide by zero near maximum
00237       if (b==0) b=1e-12;
00238       // Update D(i)
00239       D[i]=(yy-Y[3])/b;
00240       // Guard against locked up derivative
00241       if (D[i]==0) D[i]=1e-5;
00242       // Restore X(i) and yy
00243       X[i]=a; yy=Y[3];
00244     }
00245     // Obtain dd
00246     Utilit1(D, dd, l);
00247   }

void Steepda double *  X,
double  xk,
double  e,
int  l,
int  m,
int *  n,
float(*)(EMData *, EMData *, EMData *, float, float, float)  my_func,
EMData ,
EMData ,
EMData
 

Definition at line 127 of file steepest.cpp.

References Derivatives(), sqrt(), Utilit1(), Utilit2(), X, and Y.

Referenced by EMAN::Util::twoD_fine_ali_SD().

00128           {
00129   // Labels: e50,e51,e100,e200
00130   int i;
00131   double dd;
00132   double  D[4], Y[4];
00133   double  X1[11];
00134   
00135   *n=0;
00136   //The routine needs three values of Y to get started
00137   //Generate starting D(i) values
00138   //These are not even good guesses and slow the program a little
00139   dd=1.0;
00140   D[1]=1.0/sqrt((double)l);
00141   for (i=2; i<l+1; i++)  D[i]=D[i-1];
00142   // Start initial probe
00143   for (i=1; i<l+1; i++) {
00144     // Obtain yy and D[i]
00145     Y[i]=(*my_func)(image, refim, mask, (float)X[1], (float)X[2], (float)X[3]);
00146     // Update X[i]
00147     Utilit1(D, &dd, l);
00148     Utilit2(X, X1, Y, D, &dd, xk, l, my_func, image, refim, mask);
00149   }
00150   // We now have a history to base the subsequent search on
00151   // Accelerate search if approach is monotonic 
00152 e50: if (fabs(Y[2]-Y[1])<MACHEPS) goto e51;
00153   if ((Y[3]-Y[2])/(Y[2]-Y[1])>0.0) xk=xk*1.2;
00154   // Decelerate if heading the wrong way
00155 e51: if (Y[3]<Y[2]) xk=xk/2.0;
00156   // Update the Y[i] if value has decreased
00157   if (Y[3]>Y[2]) goto e100;
00158   // Restore the X[i]
00159   for (i=1; i<l+1; i++) {
00160     X[i]=X1[i];
00161   }
00162   goto e200;
00163 e100: Y[1]=Y[2]; Y[2]=Y[3];
00164   // Obtain new values
00165 e200: Y[3]=(*my_func)(image, refim, mask, (float)X[1], (float)X[2], (float)X[3]);
00166   Derivatives(X, D, Y, &dd, xk, l, my_func, image, refim, mask); // Get D(i)
00167   //if dd=0 then the precision limit of the computer has been reached
00168   if (dd==0) return;
00169   // Update X[i]
00170   Utilit2(X, X1, Y, D, &dd, xk, l, my_func, image, refim, mask);
00171   // Check for maximum iterations and convergence
00172   (*n)++;
00173   //printf("Step %3d: X[0]=%12.6f  X[1]=%12.6f  X[2]=%12.6f\n",*n,X[1],X[2],X[3]);
00174   if (*n>=m) return;
00175   if (fabs(Y[3]-Y[2])<e) return;
00176   // Try another iteration
00177   goto e50;
00178 } // Steepds()

void Steepda_G double *  X,
double  xk,
double  e,
int  l,
int  m,
int *  n,
float(*)(EMData *, EMData *, EMData *, Util::KaiserBessel &, float, float, float)  my_func,
EMData image,
EMData refim,
EMData mask,
Util::KaiserBessel kb
 

Definition at line 251 of file steepest.cpp.

References Derivatives_G(), sqrt(), Utilit1(), Utilit2_G(), X, and Y.

Referenced by EMAN::Util::twoD_fine_ali_SD_G().

00252                                 {
00253   // Labels: e50,e51,e100,e200
00254   int i;
00255   double dd;
00256   double  D[4], Y[4];
00257   double  X1[11];
00258   
00259   *n=0;
00260   //The routine needs three values of Y to get started
00261   //Generate starting D(i) values
00262   //These are not even good guesses and slow the program a little
00263   dd=1.0;
00264   D[1]=1.0/sqrt((double)l);
00265   for (i=2; i<l+1; i++)  D[i]=D[i-1];
00266   // Start initial probe
00267   for (i=1; i<l+1; i++) {
00268     // Obtain yy and D[i]
00269     Y[i]=(*my_func)(image, refim, mask, kb, (float)X[1], (float)X[2], (float)X[3]);
00270     // Update X[i]
00271     Utilit1(D, &dd, l);
00272     Utilit2_G(X, X1, Y, D, &dd, xk, l, my_func, image, refim, mask, kb);
00273   }
00274   // We now have a history to base the subsequent search on
00275   // Accelerate search if approach is monotonic 
00276 e50: if (fabs(Y[2]-Y[1])<MACHEPS) goto e51;
00277   if ((Y[3]-Y[2])/(Y[2]-Y[1])>0.0) xk=xk*1.2;
00278   // Decelerate if heading the wrong way
00279 e51: if (Y[3]<Y[2]) xk=xk/2.0;
00280   // Update the Y[i] if value has decreased
00281   if (Y[3]>Y[2]) goto e100;
00282   // Restore the X[i]
00283   for (i=1; i<l+1; i++) {
00284     X[i]=X1[i];
00285   }
00286   goto e200;
00287 e100: Y[1]=Y[2]; Y[2]=Y[3];
00288   // Obtain new values
00289 e200: Y[3]=(*my_func)(image, refim, mask, kb, (float)X[1], (float)X[2], (float)X[3]);
00290   Derivatives_G(X, D, Y, &dd, xk, l, my_func, image, refim, mask, kb); // Get D(i)
00291   //if dd=0 then the precision limit of the computer has been reached
00292   if (dd==0) return;
00293   // Update X[i]
00294   Utilit2_G(X, X1, Y, D, &dd, xk, l, my_func, image, refim, mask, kb);
00295   // Check for maximum iterations and convergence
00296   (*n)++;
00297   //printf("Step %3d: X[0]=%12.6f  X[1]=%12.6f  X[2]=%12.6f\n",*n,X[1],X[2],X[3]);
00298   if (*n>=m) return;
00299   if (fabs(Y[3]-Y[2])<e) return;
00300   // Try another iteration
00301   goto e50;
00302 } // Steepds()

void Utilit1 double *  ,
double *  ,
int 
 

Definition at line 57 of file steepest.cpp.

References sqrt().

Referenced by Derivatives(), Derivatives_G(), Steepda(), and Steepda_G().

00057                                              {
00058     int i;
00059     // Find the magnitude of the gradient
00060     *dd=0.0;
00061     for (i=1; i<l+1; i++) *dd += D[i]*D[i];
00062     *dd=sqrt(*dd);
00063   }

void Utilit2 double *  X,
double *  X1,
double *  Y,
double *  D,
double *  dd,
double  xk,
int  l,
float(*)(EMData *, EMData *, EMData *, float, float, float)  my_func,
EMData image,
EMData refim,
EMData mask
 

Definition at line 65 of file steepest.cpp.

References X, and Y.

Referenced by Steepda().

00066                                {
00067         int i;
00068     // Update the X[i] 
00069     for (i=1; i<l+1; i++) {
00070       // Save old values
00071       X1[i]=X[i];
00072       X[i] += xk*D[i]/(*dd);
00073     }
00074     Y[3]=(*my_func)(image, refim, mask, (float)X[1], (float)X[2], (float)X[3]);
00075   }

void Utilit2_G double *  X,
double *  X1,
double *  Y,
double *  D,
double *  dd,
double  xk,
int  l,
float(*)(EMData *, EMData *, EMData *, Util::KaiserBessel &, float, float, float)  my_func,
EMData image,
EMData refim,
EMData mask,
Util::KaiserBessel kb
 

Definition at line 209 of file steepest.cpp.

References X, and Y.

Referenced by Steepda_G().

00210                                                      {
00211         int i;
00212     // Update the X[i] 
00213     for (i=1; i<l+1; i++) {
00214       // Save old values
00215       X1[i]=X[i];
00216       X[i] += xk*D[i]/(*dd);
00217     }
00218     Y[3]=(*my_func)(image, refim, mask, kb, (float)X[1], (float)X[2], (float)X[3]);
00219   }


Generated on Tue Jun 11 13:47:26 2013 for EMAN2 by  doxygen 1.3.9.1