Assorted minor cleanups to pysawsim/parameter_scan.py.
authorW. Trevor King <wking@drexel.edu>
Wed, 27 Oct 2010 00:35:24 +0000 (20:35 -0400)
committerW. Trevor King <wking@drexel.edu>
Wed, 27 Oct 2010 00:35:24 +0000 (20:35 -0400)
pysawsim/parameter_scan.py

index 377e210ab15eb07e33320df2fe65a9ad0fa4f557..b8e95c0df39d53fce92ccf725c3c52c3451b47ce 100644 (file)
@@ -237,7 +237,7 @@ class HistogramMatcher (object):
         return '%s %s' % (
             self.param_format_string % tuple(params), hist_params)
 
-    def _residual(self, params):
+    def residual(self, params):
         residual = 0
         for hist_params,experiment_hist in self.experiment_histograms.iteritems():
             sawsim_hist = sawsim_histogram(
@@ -253,7 +253,7 @@ class HistogramMatcher (object):
                 self._plot_residual_comparison(
                     experiment_hist, sawsim_hist, residual=r,
                     title=title, filename=filename)
-        log().debug('residual: %g' % residual)
+        log().debug('residual %s: %g' % (params, residual))
         return residual
 
     def plot(self, param_ranges, logx=False, logy=False, contour=False):
@@ -276,7 +276,7 @@ class HistogramMatcher (object):
                 log().info('point %d %d (%d of %d)'
                            % (i, j, i*(len(y)-1) + j, (len(x)-1)*(len(y)-1)))
                 params = (xi,yj)
-                r = self._residual(params)
+                r = self.residual(params)
                 C[j,i] = numpy.log(r) # better resolution in valleys
                 if MEM_DEBUG == True:
                     log().debug('RSS: %d KB' % rss())
@@ -323,6 +323,8 @@ def parse_param_ranges_string(string):
 
     >>> parse_param_ranges_string('[1,2,3],[4,5,6]')
     [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]
+    >>> parse_param_ranges_string('[1,2,3]')
+    [[1.0, 2.0, 3.0]]
     """
     ranges = []
     for range_string in string.split("],["):
@@ -390,19 +392,20 @@ def main(argv=None):
                       metavar="PARAMS",
                       help="Param range for plotting (%default).",
                       default='[1e-5,1e-3,20],[0.1e-9,1e-9,20]')
-    parser.add_option("-R","--residual", dest="residual",
-                      metavar="STRING",
-                      help="Residual type (from 'jensen-shannon', 'chi-squared', 'mean', 'std-dev'; default: %default).",
-                      default='jensen-shannon')
-    parser.add_option("-P","--plot-residuals", dest="plot_residuals",
-                      help="Generate residual difference plots for each point in the plot range.",
-                      default=False, action="store_true")
     parser.add_option("--logx", dest="logx",
                       help="Use a log scale for the x range.",
                       default=False, action="store_true")
     parser.add_option("--logy", dest="logy",
                       help="Use a log scale for the y range.",
                       default=False, action="store_true")
+    parser.add_option("-R","--residual", dest="residual",
+                      metavar="STRING",
+                      help="Residual type (from %s; default: %%default)."
+                      % ', '.join(Histogram().types()),
+                      default='jensen-shannon')
+    parser.add_option("-P","--plot-residuals", dest="plot_residuals",
+                      help="Generate residual difference plots for each point in the plot range.",
+                      default=False, action="store_true")
     parser.add_option("-c","--contour-plot", dest="contour_plot",
                       help="Select contour plot (vs. the default pseudocolor plot).",
                       default=False, action="store_true")