fsml package

Subpackages

Submodules

fsml.utils module

class fsml.utils.Errors

Bases: object

CONVERSION_ERROR = 3
FILE_NOT_EXISTS = 1
XML_READ_ERROR = 2
fsml.utils.compute_accuracy(output: Tensor, y_true: Tensor) float

Compute the accuracy between the output of the predictor and the y_true values.

Parameters:
  • output – the output from the predictor

  • y_true – the true values

Returns:

the accuarcy

fsml.utils.compute_percent(params: ndarray, percentage: float = 50.0) ndarray

Compute the input percentage of the input array

fsml.utils.count_folder_elements(path: str, condition: ~typing.Callable[[str], bool] = <function <lambda>>) Tuple[int, List[str]]

Given the absolute path to a folder count the total number of files, folder and all the other types of possible content inside that folder. Notice that this counting operation can be altered given as input also a condition that each element should satisfy, for example: that element is a file or a folder, etc.

:param path : A fully qualified path to a folder :param condition: The condition to apply at each element :return: The number of element satisfing that condition

fsml.utils.download_model(prefix_path: str, model_id: int) str

Download a SBML model given the ID from the BioModels Database

Parameters:
  • model_id – the ID of the model that needs to be downloaded

  • prefix_path – the folder where store the new model

Returns:

the path where the model has been stored

fsml.utils.evaluate(model: RandomForestRegressor, test_data: ndarray, test_y: ndarray) float

Evaluate the predictions produced by the model on the test data

Parameters:
  • model – The predictor

  • test_data – the data to test

  • test_y – the ground truth

Returns:

The accuracy

fsml.utils.find_indexes(df: DataFrame, col_name: str = 'time', value: float = 0.0) List[int]

Given a Pandas dataframe returns a list of indexes such that at each index the value of the input column col_name is equal to the input value reset_value.

:param df : the Pandas Dataframe :param col_name: The name of the column to be checked :param value : The value to be checked :return: a list of indexes

fsml.utils.get_mean_std(points: DataFrame, vars: List[str]) DataFrame

Return a pandas dataFrame with only the mean and the variance for all the variables specified in the input list.

Parameters:
  • points – a pandas DataFrame with the points

  • vars – a list of variable’s name

Returns:

a DataFrame with mean and var for all variables

fsml.utils.get_ranges(nmax: int, cpu_count: int) List[Tuple[int, int]]

Given a maximum horizon and the number of cpus return a number of ranges between the max number and the cpu count. The number of returned ranges is exactly (nmax / cpu_count) if nmax is a multiple of cpu_count, otherwise it is (nmax / cpu_count) + (nmax % cpu_count).

example:
>>> get_ranges(67, 16)
[[0, 16], [16, 32], [32, 48], [48, 64], [64, 67]]
Parameters:
  • nmax – the maximum horizon

  • cpu_count – the total number of cpus

Returns:

a list containing all the ranges

fsml.utils.handle_run_errors(task_id: str) None

Print error messages from COPASI when the trajectory task failed.

Parameters:

task_id – the ID of the task that call this function

Returns:

fsml.utils.handle_sbml_errors(document: SBMLDocument, result: int) None

Takes as input an integer that represent the output code from a SBML function. If the code is different from libsbml.LIBSBML_OPERATION_SUCCESS than print all the errors and raise a ValueError exception.

Parameters:

document – a handle to the SBML document

:param result : the output code :return:

fsml.utils.load_model(path_to_model: str) CModel

Load the SBML model from a filename to a COPASI Model

Parameters:

path_to_model – the absolute path to the SBML model file

Returns:

a handle to the respective COPASI model

fsml.utils.load_report(report: str) DataFrame

Load the report file into a pandas DataFrame

Parameters:

report – the path to the report file

Returns:

a pandas DataFrame with the report

fsml.utils.load_sbml(sbmlpath: str) SBMLDocument

Given an SBML file with the absolute path load the file as an SBML document

Parameters:

sbmlpath – the absolute path to the SBML file

Returns:

a handler to the SBMLDocument given by the SBML file

fsml.utils.normalize(points: DataFrame, vars: List[str], ntype: str = 'statistical') DataFrame

Normalize each point (pointed by vars) in the input dataframe with the usual formula: z = (x - mean) / std. Then return the newly created and normalized dataframe. The applied normalization depends on the input type: “statistical” means the one with mean and std. deviation; “classical” means between 0 and 1, i.e., take the min value away and divide by the difference between the max and the min.

Parameters:

points – a pandas DataFrame with the points

:param vars : a list of variable’s name :param model : a handle to the COPASI Model :param ntype : (optional) normalization type “statistical” or “classical” :return: the normalized dataframe

fsml.utils.plot(points: DataFrame, vars: List[str]) None

Plot one or more variables given a matrix of points

Parameters:
  • points – a pandas DataFrame with the points

  • vars – a list of variable names

Returns:

fsml.utils.print_dict(dictionary: Dict[str, Any]) None

Just a utility to print a Python Dictionary in a better way

Parameters:

dictionary – the dict to be printed

Returns:

fsml.utils.print_errors(doc: SBMLDocument, nerrors: int) None

Print all the errors for a given SBML document

Parameters:
  • doc – A handle to the SBML document

  • nerrors – The number of errors to be printed

fsml.utils.print_parameters(model: CModel, foutput: str | None = None) None

Print information about all the parameters of the model on file or std output. Whenever the output file is given, the content will be writte in CSV.

Parameters:
  • model – a handle to a COPASI model

  • foutput – an optional file where the write the output

Returns:

fsml.utils.print_species(model: CModel, foutput: str | None = None) None

Print all the species of the Model inside a file or on the std output. Whenever the output file is given, the content will be writte in CSV.

Parameters:
  • model – the COPASI Model

  • foutput – an optional file where the write the output

Returns:

fsml.utils.read_csv_content(csv_path: str) Tuple[int, DataFrame]

Given a CSV file as input, it counts the number of rows of the file. Obvioulsy not of the file itself, but only of the matrix. Essentially, we do not consider the header.

Parameters:

csv_path – the fully qualified path to the CSV file

Returns:

the number of elements of the CSV and the CSV content

fsml.utils.read_paths_file(paths_file: str) List[str]

Read the content of the paths file. The file contains for each row the current path of a model inside a folder.

Parameters:

paths_file – the absolute path to the file

Returns:

a list with all the paths

fsml.utils.remove_original(paths: List[str]) None

Remove the original model files

Parameters:

paths – the list with all the output paths

Returns:

fsml.utils.save_model(model: Model, path: str) None

Write a SBML Model inside a file

Parameters:
  • model – a handle to the SBML model

  • path – a string representing the output path

fsml.utils.select_data(points: DataFrame, vars: List[str]) DataFrame

Select all the points in the dataframe that matches the names in the input vars list.

Parameters:

points – the dataframe with all the points

:param vars : the name of the column to consider :return: the selected points

fsml.utils.setup_seed(seed: int = 42) None

Just setup the seed for the experiments

Parameters:

seed – the seed

Returns:

fsml.utils.to_integral(params: List[float]) List[float]

Given a list of parameters convert each parameter from the original value to a value between 1 and 9. That is, given a parameter value x we obtain z = x / (10 ** int(log10(x))).

Parameters:

params – the list with all the parameters value

Returns:

the new list of parameters

fsml.utils.to_string(vector: ndarray | List[float]) str

Convert a Numpy vector to a string.

Parameters:

vector – the input vector

Returns:

the string representation

fsml.utils.write_paths(paths: List[str], output_path: str) None

Save the list of paths inside a file: one path per row

Parameters:
  • paths – the list with all the paths

  • output_path – the file where to store the pats

Returns:

Module contents