Optimization pipeline — napari_easytrack.analysis.optim_pipeline
This module contains functions for cell tracking using Bayesian Optimization with timeout handling.
- napari_easytrack.analysis.optim_pipeline.add_config_params_to_dict(params_dict, config_file_path, dataset_name)
Add default parameters from the config file to the dictionary.
- Parameters:
params_dict (dict) – Dictionary to add parameters to.
config_file_path (str) – Path to the config file.
dataset_name (str) – Name of the dataset.
- Returns:
Updated dictionary with added parameters.
- Return type:
dict
- napari_easytrack.analysis.optim_pipeline.add_missing_attributes(graph)
Add attributes to nodes without any attributes, essentially inserting dummy nodes where necessary.
- Parameters:
graph (networkx.Graph) – The graph to update.
- napari_easytrack.analysis.optim_pipeline.calculate_accuracy(lbep, segm, gt_data)
Calculate the accuracy of the tracking algorithm.
- Parameters:
lbep – LBEP data from tracking.
segm – Segmentation data.
gt_data – Ground truth data.
- Returns:
Dictionary containing accuracy metrics.
- Return type:
dict
- napari_easytrack.analysis.optim_pipeline.optimize_dataset(dataset, gt_data, objectives, study_name, n_trials=64, use_parallel_backend=True, sampler='tpe', search_space=None)
Optimize a dataset without timeout for each trial.
- Parameters:
dataset – Dataset to be optimized.
gt_data – Ground truth data.
objectives (str) – Objectives type, ‘1obj’ or ‘2obj’.
study_name (str) – Name of the Optuna study.
n_trials (int, optional) – Number of trials to run. Defaults to 64.
use_parallel_backend (bool, optional) – Whether to use parallel backend. Defaults to True.
sampler (str, optional) – Sampler to use for the optimization. Defaults to ‘tpe’.
search_space (dict, optional) – Search space for grid sampling.
- Returns:
The Optuna study object.
- Return type:
optuna.study.Study
- napari_easytrack.analysis.optim_pipeline.optimize_dataset_with_timeout(dataset, gt_data, objectives, study_name, n_trials=64, timeout=300, timeout_penalty=10000, use_parallel_backend=True, sampler='tpe', search_space=None)
Optimize a dataset with a timeout for each trial.
- Parameters:
dataset – Dataset to be optimized.
gt_data – Ground truth data.
objectives (str) – Objectives type, ‘1obj’ or ‘2obj’.
study_name (str) – Name of the Optuna study.
n_trials (int, optional) – Number of trials to run. Defaults to 64.
timeout (int, optional) – Timeout for each trial in seconds. Defaults to 300.
timeout_penalty (float, optional) – Penalty value for timeouts. Defaults to 10000.
use_parallel_backend (bool, optional) – Whether to use parallel backend. Defaults to True.
sampler (str, optional) – Sampler to use for the optimization. Defaults to ‘tpe’.
search_space (dict, optional) – Search space for grid sampling.
- Returns:
The Optuna study object.
- Return type:
optuna.study.Study
- napari_easytrack.analysis.optim_pipeline.read_config_params(config_file_path)
Read parameters from a config file.
- Parameters:
config_file_path (str) – Path to the config file.
- Returns:
Dictionary containing the config parameters.
- Return type:
dict
- napari_easytrack.analysis.optim_pipeline.run_cell_tracking_algorithm(objects, config, volume, max_search_radius=100, use_napari=False)
Run the cell tracking algorithm.
- Parameters:
objects – Objects to track.
config – Tracking configuration.
volume – Volume of the tracking space.
max_search_radius (int, optional) – Maximum search radius. Defaults to 100.
use_napari (bool, optional) – Whether to use napari for visualization. Defaults to False.
- Returns:
Tracking results including LBEP and tracks, and napari data if use_napari is True.
- Return type:
tuple
- napari_easytrack.analysis.optim_pipeline.run_with_timeout(func, args, kwargs, timeout, objectives, sem, timeout_penalty)
Run a function with a timeout and handle termination if it exceeds the timeout.
- Parameters:
func (callable) – Function to be executed.
args (tuple) – Arguments to pass to the function.
kwargs (dict) – Keyword arguments to pass to the function.
timeout (int) – Timeout in seconds.
objectives (str) – Objectives type, ‘1obj’ or ‘2obj’.
sem (multiprocessing.Semaphore) – Semaphore to control concurrent execution.
timeout_penalty (float) – Penalty value for timeouts.
- Returns:
Result of the function execution or a default value if timed out.
- Return type:
result
- napari_easytrack.analysis.optim_pipeline.write_best_params_to_config(params, config_file_path)
Write the best parameters to the config file in JSON format.
- Parameters:
params (dict) – Dictionary containing the best parameters.
config_file_path (str) – Path to the config file where parameters will be written.