magoptlib.genetic_algorithm
Functions
|
Compute fitness values and total magnetic fields for a population of |
|
|
|
|
|
Roulette-wheel selection that supports both minimization and maximization. |
|
|
|
Runs a GA where each generation’s fitness is evaluated in one GPU batch. |
Module Contents
- magoptlib.genetic_algorithm.fitness_batch_gpu(angle_vectors, positions_gpu, init_orientations_gpu, l_vals, m_vals, shX_gpu, shY_gpu, shZ_gpu, pG_gpu, objective, alpha)
Compute fitness values and total magnetic fields for a population of Halbach configurations.
- Parameters:
angle_vectors (cupy.ndarray of shape (pop_size, d)) – Candidate magnetization angles per individual.
positions_gpu (cupy.ndarray of shape (d, 3)) – 3D positions of the magnets.
init_orientations_gpu (cupy.ndarray of shape (d, 3, 3)) – Base orientation matrices for each magnet.
l_vals (np.ndarray) – Spherical harmonic degrees and orders.
m_vals (np.ndarray) – Spherical harmonic degrees and orders.
shZ_gpu (cupy.ndarray) – SH coefficients for each magnet.
shX_gpu (cupy.ndarray) – SH coefficients for each magnet.
shY_gpu (cupy.ndarray) – SH coefficients for each magnet.
pG_gpu (cupy.ndarray of shape (n_points, 3)) – Points of interest to evaluate the field.
alpha (float) – Penalty scaling factor (currently unused).
- Returns:
fitnesses (cupy.ndarray of shape (pop_size,)) – Fitness for each individual.
B_total (cupy.ndarray of shape (pop_size, n_points, 3)) – Total magnetic field at all PoIs per individual.
- magoptlib.genetic_algorithm.best_50_selection(population, population_size, sorted_idx)
- magoptlib.genetic_algorithm.tournament_selection(population, fitnesses_cpu, T_size, population_size, max_fitness_wins=True)
- magoptlib.genetic_algorithm.roulette_wheel_selection(population, fitnesses_cpu, population_size, minimize=True)
Roulette-wheel selection that supports both minimization and maximization.
Uses a shift based on min() or max() of the fitnesses so that probabilities are well-scaled and nonnegative.
- magoptlib.genetic_algorithm.ACROMUSE_adaptive(population, fitnesses_cpu, T_size_max, population_size, HPD, HPD_max, minimize)
- magoptlib.genetic_algorithm.genetic_algorithm_gpu(positions_cpu, init_orientations_gpu, l_vals_cpu, m_vals_cpu, shX_cpu, shY_cpu, shZ_cpu, points_of_interest, possible_angles_cpu, population_size, generations, mutation_rate, objective, parent_selection, alpha, elitism_frac=0.05)
Runs a GA where each generation’s fitness is evaluated in one GPU batch. Returns: best_angles (d,), best_fitness (scalar), Bx,By,Bz at best, fitness_history (generations,).