feat(ga, api): Implement advanced GA strategy and refactor API for v0.4.0 #16
@@ -310,15 +310,17 @@ class Function:
|
|||||||
parent_pool = solutions[:data_size // 2]
|
parent_pool = solutions[:data_size // 2]
|
||||||
|
|
||||||
# 2. Crossover: Breed two parents to create a child
|
# 2. Crossover: Breed two parents to create a child
|
||||||
parent1_indices = np.random.randint(0, parent_pool.size, crossover_size)
|
# Select from the full list (indices 0 to data_size-1)
|
||||||
parent2_indices = np.random.randint(0, parent_pool.size, crossover_size)
|
parent1_indices = np.random.randint(0, data_size, crossover_size)
|
||||||
parents1 = parent_pool[parent1_indices]
|
parent2_indices = np.random.randint(0, data_size, crossover_size)
|
||||||
parents2 = parent_pool[parent2_indices]
|
parents1 = solutions[parent1_indices]
|
||||||
|
parents2 = solutions[parent2_indices]
|
||||||
# Simple "average" crossover
|
# Simple "average" crossover
|
||||||
crossover_solutions = (parents1 + parents2) / 2.0
|
crossover_solutions = (parents1 + parents2) / 2.0
|
||||||
|
|
||||||
# 3. Mutation: Apply your original mutation logic
|
# 3. Mutation:
|
||||||
mutation_candidates = parent_pool[np.random.randint(0, parent_pool.size, mutation_size)]
|
# Select from the full list (indices 0 to data_size-1)
|
||||||
|
mutation_candidates = solutions[np.random.randint(0, data_size, mutation_size)]
|
||||||
|
|
||||||
# Use mutation_strength (the new name)
|
# Use mutation_strength (the new name)
|
||||||
mutation_factors = np.random.uniform(
|
mutation_factors = np.random.uniform(
|
||||||
@@ -400,15 +402,17 @@ class Function:
|
|||||||
parent_pool_size = d_parent_pool.size
|
parent_pool_size = d_parent_pool.size
|
||||||
|
|
||||||
# 2. Crossover
|
# 2. Crossover
|
||||||
parent1_indices = cupy.random.randint(0, parent_pool_size, crossover_size)
|
# Select from the full list (indices 0 to data_size-1)
|
||||||
parent2_indices = cupy.random.randint(0, parent_pool_size, crossover_size)
|
parent1_indices = cupy.random.randint(0, data_size, crossover_size)
|
||||||
d_parents1 = d_parent_pool[parent1_indices]
|
parent2_indices = cupy.random.randint(0, data_size, crossover_size)
|
||||||
d_parents2 = d_parent_pool[parent2_indices]
|
d_parents1 = d_solutions[parent1_indices]
|
||||||
|
d_parents2 = d_solutions[parent2_indices]
|
||||||
d_crossover_solutions = (d_parents1 + d_parents2) / 2.0
|
d_crossover_solutions = (d_parents1 + d_parents2) / 2.0
|
||||||
|
|
||||||
# 3. Mutation
|
# 3. Mutation
|
||||||
mutation_indices = cupy.random.randint(0, parent_pool_size, mutation_size)
|
# Select from the full list (indices 0 to data_size-1)
|
||||||
d_mutation_candidates = d_parent_pool[mutation_indices]
|
mutation_indices = cupy.random.randint(0, data_size, mutation_size)
|
||||||
|
d_mutation_candidates = d_solutions[mutation_indices]
|
||||||
|
|
||||||
# Use mutation_strength (the new name)
|
# Use mutation_strength (the new name)
|
||||||
d_mutation_factors = cupy.random.uniform(
|
d_mutation_factors = cupy.random.uniform(
|
||||||
|
|||||||
Reference in New Issue
Block a user