fddcec3471432c6266bf31dec8839286c2b66622,deeppavlov/models/evolution/neuroevolution_param_generator.py,NetworkAndParamsEvolution,crossover,#NetworkAndParamsEvolution#Any#Any#Any#,327
Before Change
part_of_population offsprings
perm = np.random.permutation(self.population_size)
offsprings = []
for i in range(self.population_size // 2):
parents = population[perm[2 * i]], population[perm[2 * i + 1]]
if self.decision(p_crossover):
params_perm = np.random.permutation(self.n_evolving_params)
train_params_perm = np.random.permutation(self.n_evolving_train_params)
nodes_perm = np.random.permutation(self.total_nodes)
binary_mask_perm = np.random.permutation(self.total_nodes * self.total_nodes)
curr_offsprings = [deepcopy(parents[0]),
deepcopy(parents[1])]
part = int(crossover_power * self.n_evolving_params)
train_part = int(crossover_power * self.n_evolving_train_params)
nodes_part = int(crossover_power * self.total_nodes)
binary_mask_part = int(crossover_power * self.total_nodes * self.total_nodes)
// exchange of model params (not layers params)
for j in range(self.n_evolving_params - part):
curr_offsprings[0]["chainer"]["pipe"][self.model_to_evolve_index][
self.evolving_params[params_perm[j]]] = parents[0][
"chainer"]["pipe"][self.model_to_evolve_index][
self.evolving_params[params_perm[j]]]
curr_offsprings[1]["chainer"]["pipe"][self.model_to_evolve_index][
self.evolving_params[params_perm[j]]] = parents[1][
"chainer"]["pipe"][self.model_to_evolve_index][
self.evolving_params[params_perm[j]]]
for j in range(self.n_evolving_params - part, self.n_evolving_params):
curr_offsprings[0]["chainer"]["pipe"][self.model_to_evolve_index][
self.evolving_params[params_perm[j]]] = parents[1][
"chainer"]["pipe"][self.model_to_evolve_index][
self.evolving_params[params_perm[j]]]
curr_offsprings[1]["chainer"]["pipe"][self.model_to_evolve_index][
self.evolving_params[params_perm[j]]] = parents[0][
"chainer"]["pipe"][self.model_to_evolve_index][
self.evolving_params[params_perm[j]]]
// exchange of train params
for j in range(self.n_evolving_train_params - train_part):
curr_offsprings[0]["train"][
self.evolving_train_params[train_params_perm[j]]] = parents[0]["train"][
self.evolving_train_params[train_params_perm[j]]]
curr_offsprings[1]["train"][
self.evolving_train_params[train_params_perm[j]]] = parents[1]["train"][
self.evolving_train_params[train_params_perm[j]]]
for j in range(self.n_evolving_train_params - train_part, self.n_evolving_train_params):
curr_offsprings[0]["train"][
self.evolving_train_params[train_params_perm[j]]] = parents[1]["train"][
self.evolving_train_params[train_params_perm[j]]]
curr_offsprings[1]["train"][
self.evolving_train_params[train_params_perm[j]]] = parents[0]["train"][
self.evolving_train_params[train_params_perm[j]]]
if self.evolve_binary_mask:
// exchange of nodes
for j in range(self.total_nodes - nodes_part):
node_key = self.nodes[str(nodes_perm[j])]
curr_offsprings[0]["chainer"]["pipe"][self.model_to_evolve_index][node_key] = deepcopy(
parents[0]["chainer"]["pipe"][self.model_to_evolve_index][node_key])
curr_offsprings[1]["chainer"]["pipe"][self.model_to_evolve_index][node_key] = deepcopy(
parents[1]["chainer"]["pipe"][self.model_to_evolve_index][node_key])
for j in range(self.total_nodes - nodes_part, self.total_nodes):
node_key = self.nodes[str(nodes_perm[j])]
curr_offsprings[0]["chainer"]["pipe"][self.model_to_evolve_index][node_key] = deepcopy(
parents[1]["chainer"]["pipe"][self.model_to_evolve_index][node_key])
curr_offsprings[1]["chainer"]["pipe"][self.model_to_evolve_index][node_key] = deepcopy(
parents[0]["chainer"]["pipe"][self.model_to_evolve_index][node_key])
// exchange of binary mask elements
for j in range(self.total_nodes * self.total_nodes - binary_mask_part):
node_x, node_y = binary_mask_perm[j] // self.total_nodes, binary_mask_perm[j] % self.total_nodes
curr_offsprings[0]["chainer"]["pipe"][self.model_to_evolve_index]["binary_mask"][node_x, node_y] =\
parents[0]["chainer"]["pipe"][self.model_to_evolve_index]["binary_mask"][node_x, node_y]
curr_offsprings[1]["chainer"]["pipe"][self.model_to_evolve_index]["binary_mask"][node_x, node_y] =\
parents[1]["chainer"]["pipe"][self.model_to_evolve_index]["binary_mask"][node_x, node_y]
for j in range(self.total_nodes * self.total_nodes - binary_mask_part,
self.total_nodes * self.total_nodes):
node_x, node_y = binary_mask_perm[j] // self.total_nodes, binary_mask_perm[j] % self.total_nodes
curr_offsprings[0]["chainer"]["pipe"][self.model_to_evolve_index]["binary_mask"][node_x, node_y] =\
parents[1]["chainer"]["pipe"][self.model_to_evolve_index]["binary_mask"][node_x, node_y]
curr_offsprings[1]["chainer"]["pipe"][self.model_to_evolve_index]["binary_mask"][node_x, node_y] =\
parents[0]["chainer"]["pipe"][self.model_to_evolve_index]["binary_mask"][node_x, node_y]
curr_offsprings[0]["chainer"]["pipe"][self.model_to_evolve_index]["binary_mask"] = \
check_and_correct_binary_mask(self.nodes,
curr_offsprings[0]["chainer"]["pipe"][self.model_to_evolve_index][
"binary_mask"])
curr_offsprings[1]["chainer"]["pipe"][self.model_to_evolve_index]["binary_mask"] = \
check_and_correct_binary_mask(self.nodes,
curr_offsprings[1]["chainer"]["pipe"][self.model_to_evolve_index][
"binary_mask"])
// if parent is one of the best and will be saved with weights
if perm[2 * i] in range(self.n_saved_best_with_weights):
curr_offsprings[0] = deepcopy(parents[0])
if perm[2 * i + 1] in range(self.n_saved_best_with_weights):
curr_offsprings[1] = deepcopy(parents[1])
offsprings.extend(curr_offsprings)
else:
offsprings.extend(deepcopy(parents))
if self.population_size % 2 == 1:
offsprings.append(deepcopy(population[perm[-1]]))
return offsprings
After Change
part_of_population offsprings
perm = np.random.permutation(self.population_size)
offsprings = deepcopy(population)
for i in range(self.population_size // 2):
parents = population[perm[2 * i]], population[perm[2 * i + 1]]
if self.decision(p_crossover):
params_perm = np.random.permutation(self.n_evolving_params)
train_params_perm = np.random.permutation(self.n_evolving_train_params)
nodes_perm = np.random.permutation(self.total_nodes)
binary_mask_perm = np.random.permutation(self.total_nodes * self.total_nodes)
curr_offsprings = [deepcopy(parents[0]),
deepcopy(parents[1])]
part = int(crossover_power * self.n_evolving_params)
train_part = int(crossover_power * self.n_evolving_train_params)
nodes_part = int(crossover_power * self.total_nodes)
binary_mask_part = int(crossover_power * self.total_nodes * self.total_nodes)
// exchange of model params (not layers params)
for j in range(self.n_evolving_params - part):
curr_offsprings[0]["chainer"]["pipe"][self.model_to_evolve_index][
self.evolving_params[params_perm[j]]] = parents[0][
"chainer"]["pipe"][self.model_to_evolve_index][
self.evolving_params[params_perm[j]]]
curr_offsprings[1]["chainer"]["pipe"][self.model_to_evolve_index][
self.evolving_params[params_perm[j]]] = parents[1][
"chainer"]["pipe"][self.model_to_evolve_index][
self.evolving_params[params_perm[j]]]
for j in range(self.n_evolving_params - part, self.n_evolving_params):
curr_offsprings[0]["chainer"]["pipe"][self.model_to_evolve_index][
self.evolving_params[params_perm[j]]] = parents[1][
"chainer"]["pipe"][self.model_to_evolve_index][
self.evolving_params[params_perm[j]]]
curr_offsprings[1]["chainer"]["pipe"][self.model_to_evolve_index][
self.evolving_params[params_perm[j]]] = parents[0][
"chainer"]["pipe"][self.model_to_evolve_index][
self.evolving_params[params_perm[j]]]
// exchange of train params
for j in range(self.n_evolving_train_params - train_part):
curr_offsprings[0]["train"][
self.evolving_train_params[train_params_perm[j]]] = parents[0]["train"][
self.evolving_train_params[train_params_perm[j]]]
curr_offsprings[1]["train"][
self.evolving_train_params[train_params_perm[j]]] = parents[1]["train"][
self.evolving_train_params[train_params_perm[j]]]
for j in range(self.n_evolving_train_params - train_part, self.n_evolving_train_params):
curr_offsprings[0]["train"][
self.evolving_train_params[train_params_perm[j]]] = parents[1]["train"][
self.evolving_train_params[train_params_perm[j]]]
curr_offsprings[1]["train"][
self.evolving_train_params[train_params_perm[j]]] = parents[0]["train"][
self.evolving_train_params[train_params_perm[j]]]
if self.evolve_binary_mask:
// exchange of nodes
for j in range(self.total_nodes - nodes_part):
node_key = self.nodes[str(nodes_perm[j])]
curr_offsprings[0]["chainer"]["pipe"][self.model_to_evolve_index][node_key] = deepcopy(
parents[0]["chainer"]["pipe"][self.model_to_evolve_index][node_key])
curr_offsprings[1]["chainer"]["pipe"][self.model_to_evolve_index][node_key] = deepcopy(
parents[1]["chainer"]["pipe"][self.model_to_evolve_index][node_key])
for j in range(self.total_nodes - nodes_part, self.total_nodes):
node_key = self.nodes[str(nodes_perm[j])]
curr_offsprings[0]["chainer"]["pipe"][self.model_to_evolve_index][node_key] = deepcopy(
parents[1]["chainer"]["pipe"][self.model_to_evolve_index][node_key])
curr_offsprings[1]["chainer"]["pipe"][self.model_to_evolve_index][node_key] = deepcopy(
parents[0]["chainer"]["pipe"][self.model_to_evolve_index][node_key])
// exchange of binary mask elements
for j in range(self.total_nodes * self.total_nodes - binary_mask_part):
node_x, node_y = binary_mask_perm[j] // self.total_nodes, binary_mask_perm[j] % self.total_nodes
curr_offsprings[0]["chainer"]["pipe"][self.model_to_evolve_index]["binary_mask"][node_x, node_y] =\
parents[0]["chainer"]["pipe"][self.model_to_evolve_index]["binary_mask"][node_x, node_y]
curr_offsprings[1]["chainer"]["pipe"][self.model_to_evolve_index]["binary_mask"][node_x, node_y] =\
parents[1]["chainer"]["pipe"][self.model_to_evolve_index]["binary_mask"][node_x, node_y]
for j in range(self.total_nodes * self.total_nodes - binary_mask_part,
self.total_nodes * self.total_nodes):
node_x, node_y = binary_mask_perm[j] // self.total_nodes, binary_mask_perm[j] % self.total_nodes
curr_offsprings[0]["chainer"]["pipe"][self.model_to_evolve_index]["binary_mask"][node_x, node_y] =\
parents[1]["chainer"]["pipe"][self.model_to_evolve_index]["binary_mask"][node_x, node_y]
curr_offsprings[1]["chainer"]["pipe"][self.model_to_evolve_index]["binary_mask"][node_x, node_y] =\
parents[0]["chainer"]["pipe"][self.model_to_evolve_index]["binary_mask"][node_x, node_y]
curr_offsprings[0]["chainer"]["pipe"][self.model_to_evolve_index]["binary_mask"] = \
check_and_correct_binary_mask(self.nodes,
curr_offsprings[0]["chainer"]["pipe"][self.model_to_evolve_index][
"binary_mask"])
curr_offsprings[1]["chainer"]["pipe"][self.model_to_evolve_index]["binary_mask"] = \
check_and_correct_binary_mask(self.nodes,
curr_offsprings[1]["chainer"]["pipe"][self.model_to_evolve_index][
"binary_mask"])
// if parent is one of the best and will be saved with weights
if perm[2 * i] in range(self.n_saved_best_with_weights):
offsprings[perm[2 * i]] = deepcopy(population[perm[2 * i]])
if perm[2 * i + 1] in range(self.n_saved_best_with_weights):
offsprings[perm[2 * i + 1]] = deepcopy(population[perm[2 * i + 1]])
offsprings[perm[2 * i]] = deepcopy(curr_offsprings[0])
offsprings[perm[2 * i + 1]] = deepcopy(curr_offsprings[1])
else:
pass
if self.population_size % 2 == 1:
offsprings[-1] = deepcopy(population[perm[-1]])
return offsprings
def mutation(self, population, p_mutation, mutation_power):
In pattern: SUPERPATTERN
Frequency: 3
Non-data size: 10
Instances
Project Name: deepmipt/DeepPavlov
Commit Name: fddcec3471432c6266bf31dec8839286c2b66622
Time: 2018-05-28
Author: dilyara.rimovna@gmail.com
File Name: deeppavlov/models/evolution/neuroevolution_param_generator.py
Class Name: NetworkAndParamsEvolution
Method Name: crossover
Project Name: tyarkoni/pliers
Commit Name: ef0e833dc06eee63f0baf4bcaf1a27e47ad5f1c3
Time: 2018-02-09
Author: quinten.mcnamara@gmail.com
File Name: pliers/extractors/microsoft.py
Class Name: MicrosoftAPIFaceExtractor
Method Name: _parse_response_json
Project Name: deepmipt/DeepPavlov
Commit Name: fddcec3471432c6266bf31dec8839286c2b66622
Time: 2018-05-28
Author: dilyara.rimovna@gmail.com
File Name: deeppavlov/models/evolution/neuroevolution_param_generator.py
Class Name: NetworkAndParamsEvolution
Method Name: crossover
Project Name: etal/cnvkit
Commit Name: a2712fc53806ec4ce7f838392ee07d7249f8339e
Time: 2015-08-24
Author: eric.talevich@gmail.com
File Name: cnvlib/export.py
Class Name:
Method Name: export_seg