darfix.core.geneticShiftDetection.GeneticShiftDetection#
- class darfix.core.geneticShiftDetection.GeneticShiftDetection(data, optimal_shift)[source]#
Bases:
object
Class performing feature selection with a genetic algorithm. Selects the best shift to apply to each image from a set of images. Given a linear (increasing through the stack) shift that produces optimal results, it tries to find the best 2d normal distibution that, added to the optimal shift, produces the best result.
- Parameters:
data (array_like) – Stack of images.
optimal_shift (array_like) – Array with 2 rows (y and x) and
len(data)
columns with an optimal linear shift.
- crossover(parents)[source]#
Given a set of parents individuals, it randomly mixes pairs of them to create a new generation of children. A fixed number of parents,
elite_size
, automatically becomes a child. It assumes that a first portion, bigger than elite_size, of parents is from the elite choosen in the select() method.- Parameters:
parents (array_like) – Individuals previously chosen to become parents.
- fit(mean, sigma, n_gens, size)[source]#
Computes the genetic algorithm.
- Parameters:
mean (Union(list, tuple)) – 2d vector to be the mean of the starting population of normals.
sigma (number) – Standard deviation used to create the covariance matrix (set in the diagonal of 2x2 matrix).
n_gens (int) – number of generations to compute.
size (int) – number of individuals of the population.
- Returns:
The genetic algorithm
- Return type:
GA
- fitness(population, shift_approach='linear')[source]#
Finds the score of each of the individuals of a population, by means of the fitness function.
- Parameters:
population (array_like) – List of individuals to score.
shift_approach (str) – Name of the shift approach to be used.
- Returns:
ndarray, ndarray
- generate(population)[source]#
Creates a new generation of indidivuals.
- Parameters:
population (array_like) – Actual population of individuals.
- initialize(size)[source]#
Initializes size normal distributions to be used as initial populations.
- Parameters:
size (int) – Size of the initial population.
- Returns:
ndarray
- mutate(children)[source]#
Given a set of children individuals, it randomly mutates some of their gens.
- Parameters:
children (array_like) – List of individuals.
- select(population, scores)[source]#
Selects the parents to breed the new generation. A fixed number
self.elite_size
of best score population automatically becomes a parent, the others are added with a certain probability, which increases as the fitness score.- Parameters:
population (array_like) – Population ordered by higher score.
score (array_like) – Score, ordered from top to bottom, of each inidivual.
- property support_#
Returns the best chromosome from the last iteration.