66#define uniform(a,b) ( a + (b - a) * xsh_dr250() )
72#define BIG_VAL 400000.0
123 int nparam,
double* abest,
136 cpl_table* conf_tab=NULL ;
141 fprintf(stderr,
"%d points read for analysis\n", DS_size);
144 printf(
"%d nparam \n",nparam);
148 fprintf(stderr,
"trouble initializing in xsh_SAInit\n");
159 for (ii=0;ii<DS_size;ii++) {
167 printf(
"%d obsx: %lf obsy:%lf, obsarm: %d sp: %d\n",
181 printf(
"bef ener %lf %lf %lf %lf %lf \n",a[0], a[1],a[2], a[3],a[4]);
187 printf(
"bef init %lf %lf %lf %lf %lf \n",a[0], a[1],a[2], a[3],a[4]);
192 printf(
"aft boltz %lf %lf %lf %lf %lf \n",a[0], a[1],a[2], a[3],a[4]);
196 fprintf(stderr,
"Boltzman constant: %f\tlearning rate:%f\n",
199 fprintf(stderr,
"Initial values: ");
201 fprintf(stderr,
"%g\t", a[ii]);
202 fprintf(stderr,
"\t(energy = %g)\n", z);
207 printf(
"aft melt %lf %lf %lf %lf %lf \n",a[0], a[1],a[2], a[3],a[4]);
212 printf(
"aft current %lf %lf %lf %lf %lf \n",a[0], a[1],a[2], a[3],a[4]);
218 printf(
"aft energy %lf %lf %lf %lf %lf \n",a[0], a[1],a[2], a[3],a[4]);
221 fprintf(stderr,
"melt values: ");
224 fprintf(stderr,
"%g\t", a[i]);
225 fprintf(stderr,
"\t(energy = %g)\n", z);
231 printf(
"aft temp %lf %lf %lf %lf %lf\n",a[0], a[1],a[2], a[3],a[4]);
239 printf(
"aft temp t0 %lf %lf %lf %lf %lf \n",a[0], a[1],a[2], a[3],a[4]);
244 printf(
"aft anneal %lf %lf %lf %lf %lf \n",a[0], a[1],a[2], a[3],a[4]);
248 printf(
"aft current %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf \n",
249 a[0], a[1],a[2], a[3],a[4],a[5], a[6],a[7], a[8],a[9]);
253 printf(
"aft energy %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf \n",
254 a[0], a[1],a[2], a[3],a[4],a[5], a[6],a[7], a[8],a[9]);
256 fprintf(stderr,
"Initial temperature: %f\tfinal temperature: %f\n", t0, t);
257 fprintf(stderr,
"Estimated minimum at: ");
259 fprintf(stderr,
"%g\t", a[i]);
260 fprintf(stderr,
"\t(energy = %g)\n", z);
277 for (ii = 0; ii < nparam; ii++)
285 if(cpl_error_get_code() != CPL_ERROR_NONE) {
312 for (ii = 0; ii <
size; ii++) {
325 printf(
"%d %lf %lf %lf %lf %lf %lf %d %d %d %lf %lf\n",
336 printf(
"%lf\n",quad_diff);
346 static int first_time;
347 static float bestyet;
348 static int first_ann_flag;
361 float sum_nw = 0.0, val = 0.0;
362 float sum_fw = 0.0, val_fw = 0.0;
363 float sum_x = 0.0, val_x = 0.0;
364 float sum_y = 0.0, val_y = 0.0;
367 if (first_ann_flag==0) {
392 blaze_wav=2.0*sin_min_nug_div_sg/
mm;
395 blaze_ref = 0.0162780076852276/
mm;
399 blaze_ref=0.0074015783175532/
mm;
403 blaze_ref = 0.0261873316874793/
mm;
405 if (fabs(blaze_wav-blaze_ref)>blaze_wav/200.0) {
411 double tmpval = fabs(blaze_wav-blaze_ref);
412 if (tmpval>blaze_off) {
421 for (ii = 0; ii <
size; ii++) {
422 if (sum_nw<HUGE_VAL) {
427 blaze_wav=2.0*sin_min_nug_div_sg/
mm;
429 blaze_ref = 0.0162780076852276/
mm;
432 blaze_wav=2.0*sin_min_nug_div_sg/
mm;
434 blaze_ref=0.0074015783175532/
mm;
443 if (val_x<0.0) val_x=-val_x;
446 if (val_y<0.0) val_y=-val_y;
448 val=(val_x*val_x+val_y*val_y);
464 if (val>val_max && val<
BIG_VAL) {
480 if (
size>4 && val_max>0.5) {
485 size_use=(float)(
size-1);
488 size_use=(float)(
size);
494 else if (flux_wt==1) {
501 if (sqrt(sum/size_use)<bestyet && sum>0.0) {
503 xsh_msg(
"it: %d blaze off %lf nw %lf fw %lf",counter,blaze_off*1000000.0, sqrt(sum_nw/size_use), sqrt(sum_fw/size_use));
504 xsh_msg(
"x %lf y %lf max %lf T %lf last %lf", sum_x/size_use, sum_y/size_use, sqrt(val_max),
local_p_xs->
temper, bestyet);
510 xsh_msg(
"Iteration No./10: %d; Mean x residual: %f; Mean y residual: %f", counter/10, sum_x/size_use, sum_y/size_use);
513 bestyet=sqrt(sum/size_use);
728 for (kk=0;kk<9;kk++) {
729 sprintf(tempstr,
"slit[%d]",kk);
730 indlen=strlen(tempstr);
cpl_table * xsh_model_io_output_cfg(struct xs_3 *p_xs_3)
void xsh_3_detpix(struct xs_3 *p_xs_3)
Takes the physical x,y position at the detector array and converts this to a pixel position.
void xsh_3_eval(DOUBLE lambda, int morder, DOUBLE **ref_ind, struct xs_3 *p_xs_3)
Compute the physical x,y position at the detector array for a given wavelength, order and parameter c...
void xsh_3_init(struct xs_3 *p_xs_3)
Pre-compute a number of non-wavelength dependent secondary parameters required by the model.
ann_all_par * local_p_all_par
float xsh_SAanneal(int iters)
void xsh_SAinitial(double *xi)
float xsh_3_energy(double *a)
void xsh_SAcurrent(double *xc)
void xsh_3_output_data(double *)
float xsh_SABoltzmann(float k)
float xsh_SAmelt(int iters)
float xsh_SAtemperature(float t)
void xsh_3_assign(int loc, double val)
cpl_table * xsh_model_anneal_comp(ann_all_par *p_all_par, int nparam, double *abest, double *amin, double *amax, int *aname, struct xs_3 *p_xs_3, int DS_size, coord *msp_coord, DOUBLE *p_wlarray, DOUBLE **ref_ind, int maxit)
Use the simulated annealing algorithm to adjust the model parameters so that the metric (mean Euclide...
void xsh_report_cpu(FILE *fp, char *str)
int xsh_SAiterations(int m)
float xsh_SAlearning_rate(float r)
int xsh_SAInit(CostFunction f, int d)
#define xsh_msg(...)
Print a message on info level.