mailr4528 - in /branches/N_state_model: ./ prompt/ test_suite/unit_tests/_prompt/


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

Header


Content

Posted by edward on January 09, 2008 - 11:28:
Author: bugman
Date: Wed Jan  9 11:28:35 2008
New Revision: 4528

URL: http://svn.gna.org/viewcvs/relax?rev=4528&view=rev
Log:
Merged revisions 4523-4527 via svnmerge from 
svn+ssh://bugman@xxxxxxxxxxx/svn/relax/1.3

........
  r4523 | bugman | 2008-01-09 10:50:39 +0100 (Wed, 09 Jan 2008) | 5 lines
  
  Renamed 'print_flag' to 'verbosity' in the calc(), grid_search(), and 
minimise() user functions.
  
  This arg is not really a flag, and it is the verbosity level, so this makes 
more sense.
........
  r4524 | bugman | 2008-01-09 10:53:06 +0100 (Wed, 09 Jan 2008) | 3 lines
  
  Created a new error type for booleans - RelaxBoolError.
........
  r4525 | bugman | 2008-01-09 10:57:51 +0100 (Wed, 09 Jan 2008) | 3 lines
  
  Converted all the bin args (0/1) to bool args (True/False) in the 
minimisation user functions.
........
  r4526 | bugman | 2008-01-09 11:25:14 +0100 (Wed, 09 Jan 2008) | 3 lines
  
  Changed all references to 'print_flag' to 'verbosity' in the user function 
arg unit tests.
........
  r4527 | bugman | 2008-01-09 11:26:16 +0100 (Wed, 09 Jan 2008) | 3 lines
  
  Changed all the bin minimisation arg unit tests to tests for boolean args.
........

Modified:
    branches/N_state_model/   (props changed)
    branches/N_state_model/prompt/minimisation.py
    branches/N_state_model/relax_errors.py
    branches/N_state_model/test_suite/unit_tests/_prompt/test_minimisation.py

Propchange: branches/N_state_model/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: branches/N_state_model/prompt/minimisation.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/N_state_model/prompt/minimisation.py?rev=4528&r1=4527&r2=4528&view=diff
==============================================================================
--- branches/N_state_model/prompt/minimisation.py (original)
+++ branches/N_state_model/prompt/minimisation.py Wed Jan  9 11:28:35 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:
@@ -37,31 +37,31 @@
         self.relax = relax
 
 
-    def calc(self, print_flag=1):
+    def calc(self, verbosity=1):
         """Function for calculating the function value.
 
         Keyword Arguments
         ~~~~~~~~~~~~~~~~~
 
-        print_flag:  The amount of information to print to screen.  Zero 
corresponds to minimal
+        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.
         """
 
         # Function intro text.
         if self.relax.interpreter.intro:
             text = sys.ps3 + "calc("
-            text = text + "print_flag=" + `print_flag` + ")"
+            text = text + "verbosity=" + `verbosity` + ")"
             print text
 
-        # The print flag.
-        if type(print_flag) != int:
-            raise RelaxIntError, ('print flag', print_flag)
+        # The verbosity level.
+        if type(verbosity) != int:
+            raise RelaxIntError, ('verbosity level', verbosity)
 
         # Execute the functional code.
-        minimise.calc(print_flag=print_flag)
-
-
-    def grid_search(self, lower=None, upper=None, inc=21, constraints=1, 
print_flag=1):
+        minimise.calc(verbosity=verbosity)
+
+
+    def grid_search(self, lower=None, upper=None, inc=21, constraints=True, 
verbosity=1):
         """The grid search function.
 
         Keyword Arguments
@@ -78,10 +78,10 @@
         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).
-
-        print_flag:  The amount of information to print to screen.  Zero 
corresponds to minimal
+        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.
         """
 
@@ -92,7 +92,7 @@
             text = text + ", upper=" + `upper`
             text = text + ", inc=" + `inc`
             text = text + ", constraints=" + `constraints`
-            text = text + ", print_flag=" + `print_flag` + ")"
+            text = text + ", verbosity=" + `verbosity` + ")"
             print text
 
         # The lower bounds.
@@ -141,15 +141,15 @@
             raise RelaxIntListIntError, ('incrementation value', inc)
 
         # Constraint flag.
-        if type(constraints) != int or (constraints != 0 and constraints != 
1):
-            raise RelaxBinError, ('constraint flag', constraints)
-
-        # The print flag.
-        if type(print_flag) != int:
-            raise RelaxIntError, ('print flag', print_flag)
+        if type(constraints) != bool:
+            raise RelaxBoolError, ('constraint flag', constraints)
+
+        # The verbosity level.
+        if type(verbosity) != int:
+            raise RelaxIntError, ('verbosity level', verbosity)
 
         # Execute the functional code.
-        minimise.grid_search(lower=lower, upper=upper, inc=inc, 
constraints=constraints, print_flag=print_flag)
+        minimise.grid_search(lower=lower, upper=upper, inc=inc, 
constraints=constraints, verbosity=verbosity)
 
 
     def minimise(self, *args, **keywords):
@@ -184,13 +184,12 @@
 
         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).
-
-
-        print_flag:  The amount of information to print to screen.  Zero 
corresponds to minimal
+        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', print_flag=1)
+        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,19 +280,19 @@
         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
-
-        # Keyword: print_flag.
-        if keywords.has_key('print_flag'):
-            print_flag = keywords['print_flag']
-        else:
-            print_flag = 1
+            scaling = True
+
+        # Keyword: verbosity.
+        if keywords.has_key('verbosity'):
+            verbosity = keywords['verbosity']
+        else:
+            verbosity = 1
 
         # Function intro text.
         if self.relax.interpreter.intro:
@@ -303,7 +302,7 @@
             text = text + ", max_iterations=" + `max_iterations`
             text = text + ", constraints=" + `constraints`
             text = text + ", scaling=" + `scaling`
-            text = text + ", print_flag=" + `print_flag` + ")"
+            text = text + ", verbosity=" + `verbosity` + ")"
             print text
 
         # Minimisation algorithm.
@@ -318,12 +317,12 @@
         min_options = args[1:]
 
         # Test for invalid keywords.
-        valid_keywords = ['func_tol', 'grad_tol', 'max_iter', 
'max_iterations', 'constraints', 'scaling', 'print_flag']
+        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,22 +339,22 @@
             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)
-
-        # Print flag.
-        if type(print_flag) != int:
-            raise RelaxIntError, ('print flag', print_flag)
+        if type(scaling) != bool:
+            raise RelaxBoolError, ('scaling', scaling)
+
+        # The verbosity level.
+        if type(verbosity) != int:
+            raise RelaxIntError, ('verbosity level', verbosity)
 
         # Execute the functional code.
-        minimise.minimise(min_algor=min_algor, min_options=min_options, 
func_tol=func_tol, grad_tol=grad_tol, max_iterations=max_iterations, 
constraints=constraints, scaling=scaling, print_flag=print_flag)
+        minimise.minimise(min_algor=min_algor, min_options=min_options, 
func_tol=func_tol, grad_tol=grad_tol, max_iterations=max_iterations, 
constraints=constraints, scaling=scaling, verbosity=verbosity)
 
 
 

Modified: branches/N_state_model/relax_errors.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/N_state_model/relax_errors.py?rev=4528&r1=4527&r2=4528&view=diff
==============================================================================
--- branches/N_state_model/relax_errors.py (original)
+++ branches/N_state_model/relax_errors.py Wed Jan  9 11:28:35 2008
@@ -1,6 +1,6 @@
 
###############################################################################
 #                                                                            
 #
-# Copyright (C) 2003-2007 Edward d'Auvergne                                  
 #
+# Copyright (C) 2003-2008 Edward d'Auvergne                                  
 #
 #                                                                            
 #
 # This file is part of the program relax.                                    
 #
 #                                                                            
 #
@@ -194,6 +194,13 @@
         if Debug:
             self.save_state()
 
+# Boolean - the values True and False.
+class RelaxBoolError(BaseError):
+    def __init__(self, name, value):
+        self.text = "The " + name + " boolean argument " + `value` + " must 
either be True or False."
+        if Debug:
+            self.save_state()
+
 # Binary - integers 0 and 1.
 class RelaxBinError(BaseError):
     def __init__(self, name, value):

Modified: 
branches/N_state_model/test_suite/unit_tests/_prompt/test_minimisation.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/N_state_model/test_suite/unit_tests/_prompt/test_minimisation.py?rev=4528&r1=4527&r2=4528&view=diff
==============================================================================
--- branches/N_state_model/test_suite/unit_tests/_prompt/test_minimisation.py 
(original)
+++ branches/N_state_model/test_suite/unit_tests/_prompt/test_minimisation.py 
Wed Jan  9 11:28:35 2008
@@ -26,7 +26,7 @@
 # relax module imports.
 from data import Data as relax_data_store
 from prompt.minimisation import Minimisation
-from relax_errors import RelaxError, RelaxBinError, RelaxIntError, 
RelaxIntListIntError, RelaxListError, RelaxListNumError, RelaxNoneError, 
RelaxNoneNumError, RelaxStrError
+from relax_errors import RelaxError, RelaxBoolError, RelaxIntError, 
RelaxIntListIntError, RelaxListError, RelaxListNumError, RelaxNoneError, 
RelaxNoneNumError, RelaxStrError
 from test_suite.unit_tests.minimisation_testing_base import 
Minimisation_base_class
 
 # Unit test imports.
@@ -41,8 +41,8 @@
     minimisation_fns = Minimisation(fake_relax.fake_instance())
 
 
-    def test_calc_argfail_print_flag(self):
-        """The print_flag arg test of the calc() user function."""
+    def test_calc_argfail_verbosity(self):
+        """The verbosity arg test of the calc() user function."""
 
         # Loop over the data types.
         for data in DATA_TYPES:
@@ -51,7 +51,7 @@
                 continue
 
             # The argument test.
-            self.assertRaises(RelaxIntError, self.minimisation_fns.calc, 
print_flag=data[1])
+            self.assertRaises(RelaxIntError, self.minimisation_fns.calc, 
verbosity=data[1])
 
 
     def test_grid_search_argfail_lower(self):
@@ -118,16 +118,16 @@
 
         # Loop over the data types.
         for data in DATA_TYPES:
-            # Catch the bin arguments, and skip them.
-            if data[0] == 'bin':
-                continue
-
-            # The argument test.
-            self.assertRaises(RelaxBinError, 
self.minimisation_fns.grid_search, constraints=data[1])
-
-
-    def test_grid_search_argfail_print_flag(self):
-        """The print_flag arg test of the grid_search() user function."""
+            # Catch the bool arguments, and skip them.
+            if data[0] == 'bool':
+                continue
+
+            # The argument test.
+            self.assertRaises(RelaxBoolError, 
self.minimisation_fns.grid_search, constraints=data[1])
+
+
+    def test_grid_search_argfail_verbosity(self):
+        """The verbosity arg test of the grid_search() user function."""
 
         # Loop over the data types.
         for data in DATA_TYPES:
@@ -136,7 +136,7 @@
                 continue
 
             # The argument test.
-            self.assertRaises(RelaxIntError, 
self.minimisation_fns.grid_search, print_flag=data[1])
+            self.assertRaises(RelaxIntError, 
self.minimisation_fns.grid_search, verbosity=data[1])
 
 
     def test_minimise_argfail_args(self):
@@ -210,12 +210,12 @@
 
         # Loop over the data types.
         for data in DATA_TYPES:
-            # Catch the bin arguments, and skip them.
-            if data[0] == 'bin':
-                continue
-
-            # The argument test.
-            self.assertRaises(RelaxBinError, self.minimisation_fns.minimise, 
'Newton', constraints=data[1])
+            # Catch the bool arguments, and skip them.
+            if data[0] == 'bool':
+                continue
+
+            # The argument test.
+            self.assertRaises(RelaxBoolError, 
self.minimisation_fns.minimise, 'Newton', constraints=data[1])
 
 
     def test_minimise_argfail_scaling(self):
@@ -223,16 +223,16 @@
 
         # Loop over the data types.
         for data in DATA_TYPES:
-            # Catch the bin arguments, and skip them.
-            if data[0] == 'bin':
-                continue
-
-            # The argument test.
-            self.assertRaises(RelaxBinError, self.minimisation_fns.minimise, 
'Newton', scaling=data[1])
-
-
-    def test_minimise_argfail_print_flag(self):
-        """The print_flag arg test of the minimise() user function."""
+            # Catch the bool arguments, and skip them.
+            if data[0] == 'bool':
+                continue
+
+            # The argument test.
+            self.assertRaises(RelaxBoolError, 
self.minimisation_fns.minimise, 'Newton', scaling=data[1])
+
+
+    def test_minimise_argfail_verbosity(self):
+        """The verbosity arg test of the minimise() user function."""
 
         # Loop over the data types.
         for data in DATA_TYPES:
@@ -241,6 +241,6 @@
                 continue
 
             # The argument test.
-            self.assertRaises(RelaxIntError, self.minimisation_fns.minimise, 
'Newton', print_flag=data[1])
-
-
+            self.assertRaises(RelaxIntError, self.minimisation_fns.minimise, 
'Newton', verbosity=data[1])
+
+




Related Messages


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