Skip to content

Commit

Permalink
smurf: Allow convergence to be specified by max change rather than me…
Browse files Browse the repository at this point in the history
…an change

Useful if you are using numiter = ast.skip + 1 (i.e. all "preparatory"
iterations and no "real" iterations).
  • Loading branch information
David Berry committed Mar 10, 2014
1 parent 8b0f57d commit c11543f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
35 changes: 24 additions & 11 deletions applications/smurf/defaults/smurf_makemap.def
Expand Up @@ -1555,19 +1555,32 @@ itermap = 0
# Type: real
# Default: 0.05
# Purpose: Specifies when to stop iterating.
# Description: If the normalised mean change between the maps created on
# subsequent iterations falls below the value of maptol, then the
# map-maker performs one more iteration and then terminates. Only
# used if parameter "numiter" is negative. The normalised mean
# change between maps is defined as the mean of the absolute
# change in map pixel value, averaged over all pixels within the
# region of the AST mask (if any, see parameter "ast.zero_mask",
# etc), and normalised by the RMS of the square root of the
# pixel variances. Compared to parameter "chitol", this is much
# more like a "by eye" test, that will stop the solution when
# the map stops changing.
# Description: If the normalised change (either the mean or maximum change -
# see parameter "maptol_mean") between the maps created on
# subsequent iterations falls below the value of maptol, then the
# map-maker performs one more iteration and then terminates. Only
# used if parameter "numiter" is negative. The normalised mean
# (or maximum) change between maps is defined as the mean (or
# maximum) of the absolute change in map pixel value, taken
# over all pixels within the region of the AST mask (if any,
# see parameter "ast.zero_mask", etc), and normalised by the RMS
# of the square root of the pixel variances. Compared to parameter
# "chitol", this is much more like a "by eye" test, that will stop
# the solution when the map stops changing.
maptol = 0.05

#-----------------------------------------------------------------
# Name: maptol_mean
# Type: integer
# Default: 1
# Purpose: Specifies when to stop iterating.
# Description: If this value is non-zero, then the value specified by
# parameter "maptol" defines a target value for the mean
# change in normalised pixel value between iterations.
# Otherwise, "maptol" defines a target value for the
# maximum change in normalised pixel value between iterations.
maptol_mean = 1

#-----------------------------------------------------------------
# Name: maxlen
# Type: integer
Expand Down
9 changes: 8 additions & 1 deletion applications/smurf/libsmf/smf_iteratemap.c
Expand Up @@ -618,6 +618,7 @@ void smf_iteratemap( ThrWorkForce *wf, const Grp *igrp, const Grp *iterrootgrp,
double mapchange_mean=0; /* Mean change in map */
double mapchange_max=0; /* Maximum change in the map */
double maptol=VAL__BADD; /* map change tolerance for stopping */
int maptol_mean; /* Use mean map change instead of max map change? */
double *mapweights=NULL; /* Weight for each pixel including chunk weight */
double *mapweightsq=NULL; /* Sum of bolometer weights squared */
dim_t maxconcat; /* Longest continuous chunk that fits in mem.*/
Expand Down Expand Up @@ -676,6 +677,7 @@ void smf_iteratemap( ThrWorkForce *wf, const Grp *igrp, const Grp *iterrootgrp,
size_t try; /* Try to concatenate this many samples */
size_t tstride; /* Time stride */
struct timeval tv1, tv2; /* Timers */
double tol; /* Map change value to compare to maptol */
int untilconverge=0; /* Set if iterating to convergence */
int varmapmethod=0; /* Method for calculating varmap */
dim_t whichast=0; /* Model index of AST (must be specified) */
Expand Down Expand Up @@ -800,6 +802,9 @@ void smf_iteratemap( ThrWorkForce *wf, const Grp *igrp, const Grp *iterrootgrp,
FUNC_NAME ": MAPTOL is ^MAPTOL, must be > 0", status);
}

/* Does maptol refer to mean map change or max map change? */
astMapGet0I( keymap, "MAPTOL_MEAN", &maptol_mean );

/* Number of iterations */
astMapGet0I( keymap, "NUMITER", &numiter );
if( numiter == 0 ) {
Expand Down Expand Up @@ -2406,8 +2411,10 @@ void smf_iteratemap( ThrWorkForce *wf, const Grp *igrp, const Grp *iterrootgrp,
convergence has been reached (i.e. when quit=0). We do not
allow convergence to be reached until we have done at least
one iteration in which the AST model was not skipped. */

tol = maptol_mean ? mapchange_mean : mapchange_max;
if( untilconverge &&
( ( (maptol!=VAL__BADD) && (mapchange_mean > maptol) ) ||
( ( (maptol!=VAL__BADD) && (tol > maptol) ) ||
last_skipped ) && quit == -1 ) {
/* Map hasn't converged yet */
converged=0;
Expand Down

0 comments on commit c11543f

Please sign in to comment.