Author: bugman Date: Fri Jul 18 15:03:54 2014 New Revision: 24569 URL: http://svn.gna.org/viewcvs/relax?rev=24569&view=rev Log: Created the parameter object infrastructure for registering parameter scalings. The _add() method now accepts the scaling keyword argument, which can be either a value or function. This is then stored in the _scaling dictionary. The public method scaling() has been added to return the scaling factor corresponding to the given parameter. Modified: branches/zooming_grid_search/specific_analyses/parameter_object.py Modified: branches/zooming_grid_search/specific_analyses/parameter_object.py URL: http://svn.gna.org/viewcvs/relax/branches/zooming_grid_search/specific_analyses/parameter_object.py?rev=24569&r1=24568&r2=24569&view=diff ============================================================================== --- branches/zooming_grid_search/specific_analyses/parameter_object.py (original) +++ branches/zooming_grid_search/specific_analyses/parameter_object.py Fri Jul 18 15:03:54 2014 @@ -63,6 +63,7 @@ self._grid_upper = {} self._set = {} self._err = {} + self._scaling = {} self._sim = {} # Add some spin specific objects. @@ -94,7 +95,7 @@ return cls._instance - def _add(self, name, scope=None, string=None, default=None, units=None, desc=None, py_type=None, set='all', conv_factor=None, grid_lower=None, grid_upper=None, grace_string=None, err=False, sim=False): + def _add(self, name, scope=None, string=None, default=None, units=None, desc=None, py_type=None, set='all', conv_factor=None, scaling=1.0, grid_lower=None, grid_upper=None, grace_string=None, err=False, sim=False): """Add a parameter to the list. @param name: The name of the parameter. This will be used as the variable name. @@ -115,6 +116,8 @@ @type set: str @keyword conv_factor: The factor of conversion between different parameter units. @type conv_factor: None, float or func + @keyword scaling: The diagonal scaling factor for optimisation. + @type scaling: float or function @keyword grid_lower: The lower bound for the grid search. @type grid_lower: int or function @keyword grid_upper: The upper bound for the grid search. @@ -149,6 +152,7 @@ self._sim[name] = sim self._grid_lower[name] = grid_lower self._grid_upper[name] = grid_upper + self._scaling[name] = scaling # The parameter string. if string: @@ -640,6 +644,28 @@ yield name + '_sim' + def scaling(self, name, model_info=None): + """Return the scaling factor for the parameter. + + @param model_info: The model information from the model_loop() specific API method. If the scaling factor is a function, this information is sent into it. + @type model_info: int + @param name: The name of the parameter. + @type name: str + @return: The scaling factor for optimisation. + @rtype: int + """ + + # Parameter check. + self.check_param(name) + + # Call any function or method. + if isinstance(self._scaling[name], FunctionType) or isinstance(self._scaling[name], MethodType): + return self._scaling[name](model_info) + + # Return the scaling factor. + return self._scaling[name] + + def scope(self, name): """Return the parameter scope.