Bayesian Optimisation#

class flickerprint.workflow.bayesian_optimisation.GranuleDetectorBayes(frame: MicroscopeFrame)#

Daughter Class to Granule Dector.

findGranules(threshold, min_sigma, max_sigma)#

Redefine class to accomendate for structure of optimisation.

flood_granules(min_sigma, max_sigma, threshold)#

Return the number of granules that can be succesfully flooded.

granules(padding=5) Iterator[Granule]#

Iterator for the granules detected by in this frame.

labelGranules(min_sigma, max_sigma, threshold)#

Keeps the same structure has the original labelGranules but is adaptet such that it takes the parameters from the Bayesian optimisation as input.

plot(ax=None, save_path: Path | None = None, cmap='viridis')#

Show the labelled granules within the image.

If no ax is provided then create a new matplotlib axis and save to save_path.

flickerprint.workflow.bayesian_optimisation.bayesOptFunction_maxSG_multiImages(threshold, min_sigma, max_sigma, images)#

Minimalistic optimimzation function. Finds the lowest number of flooded blobs for the images of each video file for the given parameters. The sum of these are then returned. Goal is to maximise this sum.

Images refer to video files. From each video file multiple images can be selected.

  1. Use DoG algorithm with optimisation parameters to find number blobs in the images.

  2. Try to flood the found blobs.

  3. Take the minimum number of blobs that could be flooded in any of the images and add it to the total number of flooded blobs

  4. Objective: sum of the minimum number of blobs in each video file

flickerprint.workflow.bayesian_optimisation.bayesOptFunction_minBlobs_multiImages(threshold, min_sigma, max_sigma, images)#

Minimalistic function optimimzation function that only concerns itself with the return of the constraint. Only function necessary to calulate the flooding are called.

!!! Images refer to video files. From each video file multiple images can be selected.

  1. Uses DoG algorithm to find number of blobs in images

  2. Takes the average number of blobs and adds it to total average number of blobs found

flickerprint.workflow.bayesian_optimisation.check_dir_structure(experiment_dir)#

Check the directory structure to make sure everything needed is there. If the config file specifices a microscope file location different from the default, this will be used instead.

flickerprint.workflow.bayesian_optimisation.extractParametersFromInput(input_data)#

Transform the parameters used by trieste into a format that can be handled by the optimisation function.

flickerprint.workflow.bayesian_optimisation.get_image_pathes(dir_path)#

Returns a list containing all image pathes.

flickerprint.workflow.bayesian_optimisation.get_random_indicies(n_images, n_samples, method='random', rng=None)#

Returns an array of length n_samples of random indicies. The indicies lie between 0 and n_images.

flickerprint.workflow.bayesian_optimisation.get_sorted_results(data, threshold=None)#

Get the values of the best attempt in the optimisation.

Returns:

sorted_data – List of querry points sorted by optimisation score

Return type:

np.array

flickerprint.workflow.bayesian_optimisation.main(experiment_dir: Path, n_samples: int = 12, n_frames_per_sample: int = 2, method: str = 'random', n_iter=30, constraint_multiplier: float = 0.9, seed=None)#

Run Bayesian optimisation.

flickerprint.workflow.bayesian_optimisation.optimisationMaxSG(images, num_steps, num_initial_points=5)#

Wrapper function to initialise and run optimisation to find the maximum number of stress granules.

flickerprint.workflow.bayesian_optimisation.optimisationReduceInvalidSGs(images, threshold_constraint, num_steps=20, probe_params=None, num_initial_points=5)#

Wrapper function to initialise and run optimisation to reduce the number of invalid SGs.

Follows very closely the example for constrained optimisation in the trieste documentation.

Initiate the partly lexicographic Bayesian optimisation. First runs a maximisation to find all possible granules. Afterwards runs an minimisation to reduce the number of blobs found. The minimisation runs with the constraint to keep the number of SG above a certain threshold.

Returns:

data_blobs_sorted – List of all querry points sorted by objective

Return type:

list

flickerprint.workflow.bayesian_optimisation.update_config_file(data, config_location, frame)#

Update the parameter values in the config file with the new values from the optimisation.