pyrfume.optimization module

class pyrfume.optimization.BetterFitness(values=())[source]

Bases: deap.base.Fitness

class pyrfume.optimization.OdorantSetOptimizer(library: pandas.core.frame.DataFrame, n_desired: int, weights: list, keep_cids: bool = None, fitness=None, n_gen: int = 300, mu: int = 100, lamda: int = 200, p_cx: float = 0.4, p_mut: float = 0.4, sel='selBest', standardize_weights=False, npartitions=1)[source]

Bases: object

compute_weight_stats()[source]

Compute scores for a bunch of random individuals to use for standardizing fitness scores and thus making weights interpretable as # of sd’s better or worse than random individuals

crossover(ind1, ind2) → tuple[source]

Apply a crossover operation on input sets.

Args:
ind1: The first individual ind2: The second individual
Returns:
tuple: Two new individuals
dask_map(f, x: list) → list[source]

A mapping function for Dask. Used for multithreading.

Args:

f: Any function. x (list): A list of inputs to be sequentially passed

to that function.
Returns:
list: A list of outputs from that function.
eval_individual(individual, standardize: bool = None)[source]

Evaluate the fitness of the odorant set.

Args:

individual: A DEAP individual as registered above. standardize (bool, optional): Whether to standardize the

resulting score.
Returns:
A fitness score.
eval_mean(individual, column: str) → float[source]

Evaluation the mean of column for the selected individual

Args:
individual: An individual. column (str): A column name from the library dataframe.
Returns:
float: The mean of that column, for the subset
described by the individual
eval_sum(individual, column: str)[source]

Evaluation the sum of column for the selected individual

Args:
individual: An individual. column (str): A column name from the library dataframe.
Returns:
float: The sum of that column, for the subset
described by the individual
force_keep(ind)[source]

Ensure that the CIDs in self.keep get included

Args:
ind: An individual.
Returns:
An individual with certain additional items kept.
mutate(individual) → tuple[source]

Mutation that pops or adds some elements.

Args:
individual: An individual
Returns:
tuple: A new individual (wrapped in a tuple)
plot_score_history()[source]

Plot the history of each of the scores over generations.

run(pop=None, hof=None, quiet: bool = False) → tuple[source]

Run the optimization

Args:

pop: The population to start with. hof: The Hall of Fame to start with quiet: (bool, optional): Whether to suppress stdout.

Defaults to False.
Returns:
tuple: The population, stats, Hall of Fame, and logboox
pyrfume.optimization.get_coverage(odorant_indices, space, sigma=2)[source]

This function will be used to compute coverage of odorant space during optimization. We want non-selected odorants to be ‘covered’ as much as possible by selected ones

pyrfume.optimization.get_entropy(odorant_indices, space, bins_per_dim=10)[source]
pyrfume.optimization.get_spacing(odorant_indices, space, n=5)[source]

These function will be used to determine the spacing between the selected odorants in the low-d manifold. We don’t want to select odorants which are right next to each other in odorant space

pyrfume.optimization.suppress_stdout(on)[source]