Author: bugman Date: Thu Jul 24 08:51:48 2014 New Revision: 24691 URL: http://svn.gna.org/viewcvs/relax?rev=24691&view=rev Log: Implemented the zooming grid search. If the zoom level is set to any value other than 0, then the grid width will be divided by 2**zoom_level and centred at the current parameter values. If the new grid is outside of the bounds of the original grid, the entire grid will be translated so that it lies entirely within the original. Modified: branches/zooming_grid_search/pipe_control/minimise.py Modified: branches/zooming_grid_search/pipe_control/minimise.py URL: http://svn.gna.org/viewcvs/relax/branches/zooming_grid_search/pipe_control/minimise.py?rev=24691&r1=24690&r2=24691&view=diff ============================================================================== --- branches/zooming_grid_search/pipe_control/minimise.py (original) +++ branches/zooming_grid_search/pipe_control/minimise.py Thu Jul 24 08:51:48 2014 @@ -276,6 +276,14 @@ # Print out the model title. api.print_model_title(prefix="Grid search setup: ", model_info=model_info) + # The grid zoom level. + zoom = 0 + if hasattr(cdp, 'grid_zoom_level'): + zoom = cdp.grid_zoom_level + zoom_factor = 1.0 / 2.0**zoom + if zoom > 0: + print("Zooming grid level of %s, scaling the grid size by a factor of %s.\n" % (zoom, zoom_factor)) + # Append empty lists for the bounds to be built up. model_lower.append([]) model_upper.append([]) @@ -308,12 +316,49 @@ upper_i = param_object.grid_upper(names[i], incs=incs, model_info=model_info) # Skip preset values. - if skip_preset and not values[i] in [None, {}, []] and not isNaN(values[i]): + if not zoom and skip_preset and not values[i] in [None, {}, []] and not isNaN(values[i]): lower_i = values[i] upper_i = values[i] model_inc[-1][i] = incs = 1 comment = 'Preset value' + # Zooming grid. + if zoom: + # The full size and scaled size. + size = upper_i - lower_i + zoom_size = size * zoom_factor + half_size = zoom_size / 2.0 + comment = 'Zoom grid width of %s %s' % (zoom_size, param_object.units(names[i])) + + # The new size around the current value. + lower_zoom = values[i] - half_size + upper_zoom = values[i] + half_size + + # Outside of the original lower bound, so shift the grid to fit. + if lower_zoom < lower_i: + print "low" + # The amount to shift by. + shift = lower_i - lower_zoom + + # Set the new bounds. + upper_i = upper_zoom + shift + + # Outside of the original upper bound, so shift the grid to fit. + elif upper_zoom > upper_i: + # The amount to shift by. + shift = upper_i - upper_zoom + + # Set the new bounds. + lower_i = lower_zoom + shift + + # Inside the original bounds. + else: + lower_i = lower_zoom + upper_i = upper_zoom + + # Add to the data list for printing out. + data.append([names[i], "%15s" % lower_i, "%15s" % upper_i, "%15s" % incs, comment]) + # Scale the bounds. scaling = param_object.scaling(names[i], model_info=model_info) lower_i /= scaling @@ -322,9 +367,6 @@ # Append. model_lower[-1].append(lower_i) model_upper[-1].append(upper_i) - - # Add to the data list for printing out. - data.append([names[i], "%15s" % lower_i, "%15s" % upper_i, "%15s" % incs, comment]) # Printout. if verbosity: