mailr4525 - /1.3/prompt/minimisation.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on January 09, 2008 - 10:57:
Author: bugman
Date: Wed Jan  9 10:57:51 2008
New Revision: 4525

URL: http://svn.gna.org/viewcvs/relax?rev=4525&view=rev
Log:
Converted all the bin args (0/1) to bool args (True/False) in the 
minimisation user functions.


Modified:
    1.3/prompt/minimisation.py

Modified: 1.3/prompt/minimisation.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/prompt/minimisation.py?rev=4525&r1=4524&r2=4525&view=diff
==============================================================================
--- 1.3/prompt/minimisation.py (original)
+++ 1.3/prompt/minimisation.py Wed Jan  9 10:57:51 2008
@@ -27,7 +27,7 @@
 # relax module imports.
 from minimise.generic import generic_minimise
 from generic_fns import minimise
-from relax_errors import RelaxBinError, RelaxError, RelaxIntError, 
RelaxIntListIntError, RelaxListError, RelaxListNumError, RelaxNoneError, 
RelaxNoneNumError, RelaxNumError, RelaxStrError
+from relax_errors import RelaxBoolError, RelaxError, RelaxIntError, 
RelaxIntListIntError, RelaxListError, RelaxListNumError, RelaxNoneError, 
RelaxNoneNumError, RelaxNumError, RelaxStrError
 
 
 class Minimisation:
@@ -61,7 +61,7 @@
         minimise.calc(verbosity=verbosity)
 
 
-    def grid_search(self, lower=None, upper=None, inc=21, constraints=1, 
verbosity=1):
+    def grid_search(self, lower=None, upper=None, inc=21, constraints=True, 
verbosity=1):
         """The grid search function.
 
         Keyword Arguments
@@ -78,8 +78,8 @@
         direction can be set if 'inc' is set to an array of integers of 
length equal to the number
         of parameters.
 
-        constraints:  A flag specifying whether the parameters should be 
constrained.  The default
-        is to turn constraints on (constraints=1).
+        constraints:  A boolean flag specifying whether the parameters 
should be constrained.  The
+        default is to turn constraints on (constraints=True).
 
         verbosity:  The amount of information to print to screen.  Zero 
corresponds to minimal
         output while higher values increase the amount of output.  The 
default value is 1.
@@ -141,8 +141,8 @@
             raise RelaxIntListIntError, ('incrementation value', inc)
 
         # Constraint flag.
-        if type(constraints) != int or (constraints != 0 and constraints != 
1):
-            raise RelaxBinError, ('constraint flag', constraints)
+        if type(constraints) != bool:
+            raise RelaxBoolError, ('constraint flag', constraints)
 
         # The verbosity level.
         if type(verbosity) != int:
@@ -184,11 +184,10 @@
 
         max_iterations:  The maximum number of iterations.  The default 
value is 1e7.
 
-        constraints:  A flag specifying whether the parameters should be 
constrained.  The default
-        is to turn constraints on (constraints=1).
-
-        scaling:  The diagonal scaling flag.  The default that scaling is on 
(scaling=1).
-
+        constraints:  A boolean flag specifying whether the parameters 
should be constrained.  The
+        default is to turn constraints on (constraints=True).
+
+        scaling:  The diagonal scaling boolean flag.  The default that 
scaling is on (scaling=True).
 
         verbosity:  The amount of information to print to screen.  Zero 
corresponds to minimal
         output while higher values increase the amount of output.  The 
default value is 1.
@@ -229,12 +228,12 @@
         relax> minimise('newton', func_tol=1e-25)
         relax> minimise('newton', func_tol=1e-25, grad_tol=None)
         relax> minimise('newton', max_iter=1e7)
-        relax> minimise('newton', constraints=1, max_iter=1e7)
+        relax> minimise('newton', constraints=True, max_iter=1e7)
         relax> minimise('newton', verbosity=1)
 
         To use constrained Simplex minimisation with a maximum of 5000 
iterations, type:
 
-        relax> minimise('simplex', constraints=1, max_iter=5000)
+        relax> minimise('simplex', constraints=True, max_iter=5000)
 
 
 
@@ -281,13 +280,13 @@
         if keywords.has_key('constraints'):
             constraints = keywords['constraints']
         else:
-            constraints = 1
+            constraints = True
 
         # Keyword: scaling.
         if keywords.has_key('scaling'):
             scaling = keywords['scaling']
         else:
-            scaling = 1
+            scaling = True
 
         # Keyword: verbosity.
         if keywords.has_key('verbosity'):
@@ -320,10 +319,10 @@
         # Test for invalid keywords.
         valid_keywords = ['func_tol', 'grad_tol', 'max_iter', 
'max_iterations', 'constraints', 'scaling', 'verbosity']
         for key in keywords:
-            valid = 0
+            valid = False
             for valid_key in valid_keywords:
                 if key == valid_key:
-                    valid = 1
+                    valid = True
             if not valid:
                 raise RelaxError, "Unknown keyword argument " + `key` + "."
 
@@ -340,15 +339,15 @@
             raise RelaxIntError, ('maximum number of iterations', 
max_iterations)
 
         # Constraint flag.
-        if type(constraints) != int or (constraints != 0 and constraints != 
1):
-            raise RelaxBinError, ('constraint flag', constraints)
-        elif constraints == 1:
+        if type(constraints) != bool:
+            raise RelaxBoolError, ('constraint flag', constraints)
+        elif constraints:
             min_algor = 'Method of Multipliers'
             min_options = args
 
         # Scaling.
-        if type(scaling) != int or (scaling != 0 and scaling != 1):
-            raise RelaxBinError, ('scaling', scaling)
+        if type(scaling) != bool:
+            raise RelaxBoolError, ('scaling', scaling)
 
         # The verbosity level.
         if type(verbosity) != int:




Related Messages


Powered by MHonArc, Updated Wed Jan 09 11:40:09 2008