pycotools3.tasks.ParameterEstimation.Config¶
-
class
pycotools3.tasks.ParameterEstimation.
Config
(models, datasets, items, settings={}, defaults=None)¶ A parameter estimation configuration class
Stores as attibutes all the settings needed for configuration of a parameter estimation using COPASI. Base class is a
Bunch
- Structure of a
ParameterEstimation.Config
Object has four main sections: - models
- datasets
- items
- settings
Examples
>>> ## create a model >>> antimony_string = ''' ... model TestModel1() ... R1: A => B; k1*A; ... R2: B => A; k2*B ... A = 1 ... B = 0 ... k1 = 4; ... k2 = 9; ... end ... ''' >>> copasi_filename = os.path.join(os.path.dirname(__file__), 'example_model.cps') >>> mod = moddel.loada(antimony_string, copasi_filename) >>> ## Simulate some data from the model and write to file >>> fname = os.path.join(os.path.dirname(__file__), 'timeseries.txt') >>> data = self.model.simulate(0, 10, 11) >>> data.to_csv(fname) >>> >>> ## create nested dict containing all the relevant arguments for your configuration >>> config_dict = dict( ... models=dict( ... ## model name is the users choice here ... example1=dict( ... copasi_file=copasi_filename ... ) ... ), ... datasets=dict( ... experiments=dict( ... ## experiment names are the users choice ... report1=dict( ... filename=self.TC1.report_name, ... ), ... ), ... ## our validations entry is empty here ... ## but if you have validation data this should ... ## be the same as the experiments section ... validations=dict(), ... ), ... items=dict( ... fit_items=dict( ... A=dict( ... affected_experiments='report1' ... ), ... B=dict( ... affected_validation_experiments=['report2'] ... ), ... k1={}, ... k2={}, ... ), ... constraint_items=dict( ... k1=dict( ... lower_bound=1e-2, ... upper_bound=10 ... ) ... ) ... ), ... settings=dict( ... method='genetic_algorithm_sr', ... population_size=2, ... number_of_generations=2, ... working_directory=os.path.dirname(__file__), ... copy_number=4, ... pe_number=2, ... weight_method='value_scaling', ... validation_weight=2.5, ... validation_threshold=9, ... randomize_start_values=True, ... calculate_statistics=False, ... create_parameter_sets=False ... ) ... ) >>> config = ParameterEstimation.Config(**config_dict)
-
__init__
(models, datasets, items, settings={}, defaults=None)¶ Initialisation method for Config class
Parameters: - models (dict) – Dict containing model names and paths to copasi files
- datasets (dict) – Dict containing experiments and validation experiments
- items (dict) – Dict containing fit items and constraint items
- settings (dict) – Dict containing all other settings for parameter estimation
- defaults (ParameterEstimation._Defaults) – Custom set of Defaults to use for unspecified arguments
Returns:
Methods
__init__
(models, datasets, items[, …])Initialisation method for Config class check_integrity
(allowed, given)Method to raise an error when a wrong kwarg is passed to a subclass clear
()configure
()Configure the class for production of parameter estimation config convert_bool_to_numeric
(dct)CopasiML uses 1’s and 0’s for True or False in some but not all places. convert_bool_to_numeric2
()CopasiML uses 1’s and 0’s for True or False in some but not all places. copy
()fromDict
(d)Recursively transforms a dictionary into a Munch via copy. fromYAML
(*args, **kwargs)from_json
(string)Create config object from json format :param string: a valid json string :type string: Str from_yaml
(yml)Read config object from yaml file :param yml: full path to text file containing configuration arguments in yaml format :type yml: str fromkeys
Returns a new dict with keys from iterable and values equal to value. get
(k[,d])get_variable_from_string
(m, v[, glob])Use model entity name to get the pycotools3 variable items
()keys
()pop
(k[,d])If key is not found, d is returned if given, otherwise KeyError is raised popitem
()2-tuple; but raise KeyError if D is empty. set_default_fit_items_dct
()Configure missing entries for items.fit_items when they are in nested dict format set_default_fit_items_str
()Configure missing entries for items.fit_items when they are strings pointing towards model variables setdefault
(k[,d])toDict
()Recursively converts a munch back into a dictionary. toJSON
(**options)Serializes this Munch to JSON. toYAML
(**options)Serializes this Munch to YAML, using yaml.safe_dump() if no Dumper is provided. to_json
()Output arguments as json to_yaml
([filename])Output arguments as yaml update
([E, ]**F)If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k] update_properties
(kwargs)method for updating properties from kwargs values
()Attributes
constraint_items
The constraint items as nested dict experiment_filenames
A list of experiment filesnames experiment_names
A list of experiment names experiments
The experiments property :returns: datasets.experiments as dict fit_items
The fit items as nested dict model_objects
A list of model objects for mapping schema
validation_filenames
a list of validation filenames validation_names
A list of validation names validations
The validations property :returns: datasets.validations as dict -
configure
()¶ Configure the class for production of parameter estimation config
Like a main method for this class. Uses the other methods in the class to configure a
ParameterEstimation.Config object
Returns: Operates inplace and returns None
-
constraint_items
¶ The constraint items as nested dict
Type: Returns
-
experiment_filenames
¶ A list of experiment filesnames
Type: Returns
-
experiment_names
¶ A list of experiment names
Type: Returns
-
experiments
¶ The experiments property :returns: datasets.experiments as dict
-
fit_items
¶ The fit items as nested dict
Type: Returns
-
from_json
(string)¶ Create config object from json format :param string: a valid json string :type string: Str
Returns: ParameterEstimation.Config
-
static
from_yaml
(yml)¶ Read config object from yaml file :param yml: full path to text file containing configuration arguments in yaml format :type yml: str
Returns: ParameterEstimation.Config
-
model_objects
¶ A list of model objects for mapping
Type: Returns
-
models_affected_experiments
¶ Get which experiment datasets affect which models
Returns: dict. Keys are model names, value are list of affected models
-
models_affected_validation_experiments
¶ Get which experiment datasets affect which models
Returns: dict. Keys are model names, value are list of affected models
-
multi_experiments
¶ List of experiment names that have more than one experiment separated by blank line Returns (tuple): (list, int)
-
set_default_fit_items_dct
()¶ Configure missing entries for items.fit_items when they are in nested dict format
Returns: None. Method operates inplace on class attributes
-
set_default_fit_items_str
()¶ Configure missing entries for items.fit_items when they are strings pointing towards model variables
Returns: None. Method operates inplace on class attributes
-
to_json
()¶ Output arguments as json
- Returns: str
- All arguments in json format
-
to_yaml
(filename=None)¶ Output arguments as yaml
Parameters: filename (str, None) – If not None (default), path to write yaml configuration to Returns: Config object as string in yaml format
-
validation_filenames
¶ a list of validation filenames
Type: Returns
-
validation_names
¶ A list of validation names
Type: Returns
-
validations
¶ The validations property :returns: datasets.validations as dict
- Structure of a