def opt_normalizations(params, func, limits, abandon_threshold=<NUM_LIT:100>, noimprovement_threshold=<NUM_LIT>,<EOL>disp=<NUM_LIT:0>):
newparams = numpy.copy(params)<EOL>lower = [lo for lo, hi in limits]<EOL>upper = [hi for lo, hi in limits]<EOL>for i, p in enumerate(params):<EOL><INDENT>startval = p<EOL>beststat = func(newparams)<EOL>bestval = startval<EOL>if disp > <NUM_LIT:0>:<EOL><INDENT>print('<STR_LIT>' % (startval, beststat))<EOL><DEDENT>go_up = True<EOL>go_down = True<EOL>for n in list(<NUM_LIT>**numpy.arange(<NUM_LIT:1>, <NUM_LIT:20>)) + [None] + list(<NUM_LIT>**numpy.arange(<NUM_LIT:1>, <NUM_LIT>)):<EOL><INDENT>if n is None:<EOL><INDENT>startval = bestval<EOL>if disp > <NUM_LIT:0>:<EOL><INDENT>print('<STR_LIT>' % (startval))<EOL><DEDENT>go_up = True<EOL>go_down = True<EOL>continue<EOL><DEDENT>if go_up and startval * n > upper[i]:<EOL><INDENT>if disp > <NUM_LIT:0>:<EOL><INDENT>print('<STR_LIT>' %<EOL>(startval, n, upper[i]))<EOL><DEDENT>go_up = False<EOL><DEDENT>if go_down and startval / n < lower[i]:<EOL><INDENT>if disp > <NUM_LIT:0>:<EOL><INDENT>print('<STR_LIT>' %<EOL>(startval, n, lower[i]))<EOL><DEDENT>go_down = False<EOL><DEDENT>if go_up:<EOL><INDENT>if disp > <NUM_LIT:1>:<EOL><INDENT>print('<STR_LIT>' % (startval * n))<EOL><DEDENT>newparams[i] = startval * n<EOL>newstat = func(newparams)<EOL>if disp > <NUM_LIT:1>:<EOL><INDENT>print('<STR_LIT>' % (newparams[i], newstat))<EOL><DEDENT>if newstat <= beststat:<EOL><INDENT>bestval = newparams[i]<EOL>beststat = newstat<EOL>if disp > <NUM_LIT:0>:<EOL><INDENT>print('<STR_LIT>' % newparams[i])<EOL><DEDENT><DEDENT>if newstat > beststat + abandon_threshold:<EOL><INDENT>go_up = False<EOL><DEDENT><DEDENT>if go_down:<EOL><INDENT>if disp > <NUM_LIT:1>:<EOL><INDENT>print('<STR_LIT>' % (startval / n))<EOL><DEDENT>newparams[i] = startval / n<EOL>newstat = func(newparams)<EOL>if disp > <NUM_LIT:1>:<EOL><INDENT>print('<STR_LIT>' % (newparams[i], newstat))<EOL><DEDENT>if newstat + noimprovement_threshold < beststat:  <EOL><INDENT>bestval = newparams[i]<EOL>beststat = newstat<EOL>if disp > <NUM_LIT:0>:<EOL><INDENT>print('<STR_LIT>' % newparams[i])<EOL><DEDENT><DEDENT>if newstat > beststat + abandon_threshold:<EOL><INDENT>go_down = False<EOL><DEDENT><DEDENT><DEDENT>newparams[i] = bestval<EOL>print('<STR_LIT>' % (i, newparams[i]))<EOL><DEDENT>print('<STR_LIT>' % (beststat))<EOL>return newparams<EOL>
**optimization algorithm for scale variables (positive value of unknown magnitude)**

Each parameter is a normalization of a feature, and its value is sought.
The parameters are handled in order (assumed to be independent), 
but a second round can be run.
Various magnitudes of the normalization are tried. If the normalization converges
to zero, the largest value yielding a comparable value is used.

Optimizes each normalization parameter in rough steps 
using multiples of 3 of start point
to find reasonable starting values for another algorithm.

parameters, minimization function, parameter space definition [(lo, hi) for i in params]

:param abandon_threshold:
        if in one direction the function increases by this much over the best value, 
        abort search in this direction
:param noimprovement_threshold:
        when decreasing the normalization, if the function increases by less than 
        this amount, abort search in this direction
:param disp:
        verbosity