morphogen.design.search¶
Search algorithms for discrete design problems, and the inverse design of automata.
simulated_annealing and genetic_algorithm minimize a cost over any
representation (bit strings, tile weights, rule tables…), given the moves.
fit_rule searches the outer-totalistic rules (birth and survival sets) of a cellular
automaton whose structures, grown from noise, match target morphological descriptors:
volume fraction, interface density and two-point correlation function, measured on an
image (e.g. a real microstructure, at the resolution of the automaton’s cells) or given.
- class morphogen.design.search.SearchResult(best: Any, cost: float, evaluations: int, history: dict[str, list]=<factory>)[source]¶
Bases:
objectBest solution found, its cost and the history of the search.
- morphogen.design.search.simulated_annealing(x0, cost: Callable[[Any], float], neighbour: Callable[[Any, Generator], Any], rng: Generator, *, steps: int = 1000, t_start: float | None = None, t_end: float | None = None, callback=None) SearchResult[source]¶
Minimize
costby Metropolis movesx -> neighbour(x, rng)with a geometric cooling fromt_starttot_end(default: from the spread of the costs of 20 random moves, down to a thousandth of it).
- morphogen.design.search.genetic_algorithm(population: list, cost: Callable[[Any], float], rng: Generator, *, mutate: Callable[[Any, Generator], Any], crossover: Callable[[Any, Any, Generator], Any] | None = None, generations: int = 50, elite: int = 2, tournament: int = 3, callback=None) SearchResult[source]¶
Minimize
costwith a generational genetic algorithm: theelitebest individuals are kept, the others are children of parents chosen by tournaments oftournamentindividuals, bycrossover(if given) thenmutate.
- morphogen.design.search.structure_descriptors(state, max_lag: int = 4, periodic: bool = True) ndarray[source]¶
Volume fraction, interface density (fraction of unlike neighbour pairs) and two-point correlation
rho(h) = (C(h) - f^2) / (f - f^2)at lags 1..max_lag (mean over the axes of more than one cell).
- morphogen.design.search.descriptor_cost(d: ndarray, target: ndarray) float[source]¶
Squared errors: relative for the volume fraction and the interface density, absolute for the correlation function.
- class morphogen.design.search.RuleFit(rule: str, initial_fraction: float, cost: float, descriptors: ndarray, target: ndarray, evaluations: int, history: dict[str, list])[source]¶
Bases:
objectResult of
fit_rule().
- morphogen.design.search.fit_rule(target, *, neighbourhood: str = 'moore', radius: float = 1, dims: int = 3, lattice: str = 'square', shape=(24, 24, 24), steps: int = 15, initial_fraction: float | None = None, population: int = 24, generations: int = 15, max_lag: int = 4, rng: Generator | None = None, callback=None) RuleFit[source]¶
Rule
B.../S...(and initial noise density) whose structures best matchtarget.targetis a phase image (phase 1 is the automaton’s state 1) or an array of descriptors (seestructure_descriptors()). Each candidate rule is run forstepssynchronous updates from noise of densityinitial_fraction(searched too when not given) on a periodic lattice ofshapecells, and scored bydescriptor_cost(); a genetic algorithm searches the birth and survival sets. All candidates start from the same noise (common random numbers). Otherlatticevalues thansquarerun the candidates on a tiling of the box ofshapecell sizes (morphogen.automata.tilings; a free patch for quasi-periodic tilings), rasterized at one voxel per cell size before their descriptors are measured.