def main(seed=None, play=0, NGEN=40, MU=4 * 10): # random.seed(seed) # MU has to be a multiple of 4. period. CXPB = 0.9 stats = tools.Statistics(lambda ind: ind.fitness.values[1]) # stats.register("avg", numpy.mean, axis=0) # stats.register("std", numpy.std, axis=0) stats.register("min", numpy.min, axis=0) stats.register("max", numpy.max, axis=0) logbook = tools.Logbook() logbook.header = "gen", "evals", "std", "min", "avg", "max" toolbox.register("evaluate", minimize_src) time1 = time.time() pop_src = toolbox.population(n=MU) time2 = time.time() print("After population initialisation", time2 - time1) print(type(pop_src)) # print("population initialized") # network_obj = Neterr(indim, outdim, n_hidden, np.random) # Evaluate the individuals with an invalid fitness invalid_ind = [ind for ind in pop_src if not ind.fitness.valid] fitnesses = toolbox.map(toolbox.evaluate, invalid_ind) for ind, fit in zip(invalid_ind, fitnesses): ind.fitness.values = fit time3 = time.time() print("After feedforward", time3 - time2) # This is just to assign the crowding distance to the individuals # no actual selection is done pop_src = toolbox.select(pop_src, len(pop_src)) # print( "first population selected, still outside main loop") # print(pop) record = stats.compile(pop_src) logbook.record(gen=0, evals=len(invalid_ind), **record) print(logbook.stream) maxi = 0 stri = '' flag = 0 # Begin the generational process # print(pop.__dir__()) time4 = time.time() for gen in range(1, NGEN): # Vary the population if gen == 1: time6 = time.time() if gen == NGEN - 1: time7 = time.time() print() print("here in gen no.", gen) offspring = tools.selTournamentDCD(pop_src, len(pop_src)) offspring = [toolbox.clone(ind) for ind in offspring] if play: if play == 1: pgen = NGEN * 0.1 elif play == 2: pgen = NGEN * 0.9 if gen == int(pgen): print("gen:", gen, "doing clustering") to_bp_lis = cluster.give_cluster_head(offspring, int(MU * bp_rate)) assert (to_bp_lis[0] in offspring) print("doing bp") [ item.modify_thru_backprop(indim, outdim, network_obj_src.rest_setx, network_obj_src.rest_sety, epochs=10, learning_rate=0.1, n_par=10) for item in to_bp_lis ] # Evaluate the individuals with an invalid fitness invalid_ind = [ ind for ind in offspring if not ind.fitness.valid ] fitnesses = toolbox.map(toolbox.evaluate, invalid_ind) for ind, fit in zip(invalid_ind, fitnesses): ind.fitness.values = fit if gen == 1: time8 = time.time() if gen == NGEN - 1: time9 = time.time() dum_ctr = 0 for ind1, ind2 in zip(offspring[::2], offspring[1::2]): flag = 0 if random.random() <= CXPB: ind1, ind2 = toolbox.mate(ind1, ind2, gen) ind1 = creator.Individual(indim, outdim, ind1) ind2 = creator.Individual(indim, outdim, ind2) flag = 1 maxi = max(maxi, ind1.node_ctr, ind2.node_ctr) toolbox.mutate(ind1) toolbox.mutate(ind2) offspring[dum_ctr] = ind1 offspring[dum_ctr + 1] = ind2 del offspring[dum_ctr].fitness.values, offspring[dum_ctr + 1].fitness.values dum_ctr += 2 if gen == 1: print("1st gen after newpool", time.time() - time8) if gen == NGEN - 1: print("last gen after newpool", time.time() - time9) # Evaluate the individuals with an invalid fitness invalid_ind = [ind for ind in offspring if not ind.fitness.valid] fitnesses = toolbox.map(toolbox.evaluate, invalid_ind) for ind, fit in zip(invalid_ind, fitnesses): ind.fitness.values = fit # Select the next generation population pop_src = toolbox.select(pop_src + offspring, MU) record = stats.compile(pop_src) logbook.record(gen=gen, evals=len(invalid_ind), **record) anost = logbook.stream liso = [item.rstrip() for item in anost.split("\t")] mse = float(liso[3]) print(anost) stri += anost + '\n' print("generation done") # file_ob.write(str(logbook.stream)) # print(len(pop)) # file_ob.close() time5 = time.time() print("Overall time", time5 - time4) # print(stri) print( ' ------------------------------------src done------------------------------------------- ' ) fronts = tools.sortNondominated(pop_src, len(pop_src)) pareto_front = fronts[0] print(pareto_front) st = '\n\n' pareto_log_fileo = open( "./log_folder/log_pareto_just_src_nll_mse_misc_com" + str(NGEN) + ".txt", "a") for i in range(len(pareto_front)): print(pareto_front[i].fitness.values) st += str(pareto_front[i].fitness.values) pareto_log_fileo.write(st + '\n') pareto_log_fileo.close() return pop_src, logbook
def main(seed=None, play=0, NGEN=40, MU=4 * 10): # random.seed(seed) # MU has to be a multiple of 4. period. CXPB = 0.9 stats = tools.Statistics(lambda ind: ind.fitness.values[1]) # stats.register("avg", numpy.mean, axis=0) # stats.register("std", numpy.std, axis=0) stats.register("min", numpy.min, axis=0) stats.register("max", numpy.max, axis=0) logbook = tools.Logbook() logbook.header = "gen", "evals", "std", "min", "avg", "max" toolbox.register("evaluate", minimize_tar) time1 = time.time() pop_tar = toolbox.population(n=MU) time2 = time.time() print("After population initialisation", time2 - time1) invalid_ind = [ind for ind in pop_tar if not ind.fitness.valid] fitnesses = toolbox.map(toolbox.evaluate, invalid_ind) for ind, fit in zip(invalid_ind, fitnesses): ind.fitness.values = fit # This is just to assign the crowding distance to the individuals # no actual selection is done pop_tar = toolbox.select(pop_tar, len(pop_tar)) # print( "first population selected, still outside main loop") # print(pop) record = stats.compile(pop_tar) logbook.record(gen=0, evals=len(invalid_ind), **record) print(logbook.stream) maxi = 0 stri = '' flag = 0 # Begin the generational process # print(pop.__dir__()) for gen in range(1, NGEN): # Vary the population print() print("here in gen no.", gen) offspring = tools.selTournamentDCD(pop_tar, len(pop_tar)) offspring = [toolbox.clone(ind) for ind in offspring] if play: if play == 1: pgen = NGEN * 0.1 elif play == 2: pgen = NGEN * 0.9 if gen == int(pgen): print("gen:", gen, "doing clustering") to_bp_lis = cluster.give_cluster_head(offspring, int(MU * bp_rate)) assert (to_bp_lis[0] in offspring) print("doing bp") [ item.modify_thru_backprop(indim, outdim, network_obj_tar.rest_setx, network_obj_tar.rest_sety, epochs=10, learning_rate=0.1, n_par=10) for item in to_bp_lis ] # Evaluate the individuals with an invalid fitness invalid_ind = [ ind for ind in offspring if not ind.fitness.valid ] fitnesses = toolbox.map(toolbox.evaluate, invalid_ind) for ind, fit in zip(invalid_ind, fitnesses): ind.fitness.values = fit dum_ctr = 0 for ind1, ind2 in zip(offspring[::2], offspring[1::2]): # print(ind1.fitness.values) """if not flag : ind1.modify_thru_backprop(indim, outdim, network_obj.rest_setx, network_obj.rest_sety, epochs=10, learning_rate=0.1, n_par=10) flag = 1 print("just testing") """ flag = 0 if random.random() <= CXPB: ind1, ind2 = toolbox.mate(ind1, ind2, gen) ind1 = creator.Individual(indim, outdim, ind1) ind2 = creator.Individual(indim, outdim, ind2) flag = 1 maxi = max(maxi, ind1.node_ctr, ind2.node_ctr) toolbox.mutate(ind1) toolbox.mutate(ind2) offspring[dum_ctr] = ind1 offspring[dum_ctr + 1] = ind2 del offspring[dum_ctr].fitness.values, offspring[dum_ctr + 1].fitness.values dum_ctr += 2 # Evaluate the individuals with an invalid fitness invalid_ind = [ind for ind in offspring if not ind.fitness.valid] fitnesses = toolbox.map(toolbox.evaluate, invalid_ind) for ind, fit in zip(invalid_ind, fitnesses): ind.fitness.values = fit # Select the next generation population pop_tar = toolbox.select(pop_tar + offspring, MU) record = stats.compile(pop_tar) logbook.record(gen=gen, evals=len(invalid_ind), **record) anost = logbook.stream liso = [item.rstrip() for item in anost.split("\t")] mse = float(liso[3]) print(anost) stri += anost + '\n' print("generation done") # file_ob.write(str(logbook.stream)) # print(len(pop)) # file_ob.close() # print(stri) ##from here starting target return pop_tar, logbook
def main(seed=None, play=0, NGEN=40, MU=4 * 10): # this has to be a multiple of 4. period. CXPB = 0.9 stats = tools.Statistics(lambda ind: ind.fitness.values[1]) # stats.register("avg", numpy.mean, axis=0) # stats.register("std", numpy.std, axis=0) stats.register("min", numpy.min, axis=0) stats.register("max", numpy.max, axis=0) logbook = tools.Logbook() logbook.header = "gen", "evals", "std", "min", "avg", "max" time1 = time.time() pop = toolbox.population(n=MU) time2 = time.time() print("After population initialisation", time2 - time1) #network_obj = Neterr(indim, outdim, n_hidden, np.random) # Evaluate the individuals with an invalid fitness invalid_ind = [ind for ind in pop if not ind.fitness.valid] fitnesses = toolbox.map(toolbox.evaluate, invalid_ind) for ind, fit in zip(invalid_ind, fitnesses): ind.fitness.values = fit time3 = time.time() print("After feedforward", time3 - time2) # This is just to assign the crowding distance to the individuals # no actual selection is done pop = toolbox.select(pop, len(pop)) # print(pop) record = stats.compile(pop) logbook.record(gen=0, evals=len(invalid_ind), **record) print(logbook.stream) maxi = 0 stri = '' flag = 0 # Begin the generational process # print(pop.__dir__()) time4 = time.time() for gen in range(1, NGEN): # Vary the population if gen == 1: time6 = time.time() if gen == NGEN - 1: time7 = time.time() offspring = tools.selTournamentDCD(pop, len(pop)) offspring = [toolbox.clone(ind) for ind in offspring] if gen == 1: print("1st gen after clone", time.time() - time6) if gen == NGEN - 1: print("last gen after clone", time.time() - time7) if play: if play == 1: pgen = NGEN * 0.1 elif play == 2: pgen = NGEN * 0.9 if gen == int(pgen): print("gen:", gen, "doing clustering") to_bp_lis = cluster.give_cluster_head(offspring, int(MU * bp_rate)) assert (to_bp_lis[0] in offspring) print("doing bp") [ item.modify_thru_backprop(indim, outdim, network_obj.rest_setx, network_obj.rest_sety, epochs=10, learning_rate=0.1, n_par=10) for item in to_bp_lis ] # Evaluate the individuals with an invalid fitness invalid_ind = [ ind for ind in offspring if not ind.fitness.valid ] fitnesses = toolbox.map(toolbox.evaluate, invalid_ind) for ind, fit in zip(invalid_ind, fitnesses): ind.fitness.values = fit if gen == 1: time8 = time.time() if gen == NGEN - 1: time9 = time.time() for ind1, ind2 in zip(offspring[::2], offspring[1::2]): # print(ind1.fitness.values) """if not flag : ind1.modify_thru_backprop(indim, outdim, network_obj.rest_setx, network_obj.rest_sety, epochs=10, learning_rate=0.1, n_par=10) flag = 1 print("just testing") """ if random.random() <= CXPB: ind1, ind2 = toolbox.mate(ind1, ind2, gen) ind1 = creator.Individual(indim, outdim, ind1) ind2 = creator.Individual(indim, outdim, ind2) maxi = max(maxi, ind1.node_ctr, ind2.node_ctr) toolbox.mutate(ind1) toolbox.mutate(ind2) del ind1.fitness.values, ind2.fitness.values if gen == 1: print("1st gen after newpool", time.time() - time8) if gen == NGEN - 1: print("last gen after newpool", time.time() - time9) # Evaluate the individuals with an invalid fitness invalid_ind = [ind for ind in offspring if not ind.fitness.valid] fitnesses = toolbox.map(toolbox.evaluate, invalid_ind) for ind, fit in zip(invalid_ind, fitnesses): ind.fitness.values = fit # Select the next generation population pop = toolbox.select(pop + offspring, MU) record = stats.compile(pop) logbook.record(gen=gen, evals=len(invalid_ind), **record) anost = logbook.stream liso = [item.rstrip() for item in anost.split("\t")] mse = float(liso[3]) if (mse <= 115): print( "already achieved a decent performance(validation), breaking at gen_no.", gen) break print(anost) stri += anost + '\n' # file_ob.write(str(logbook.stream)) # print(len(pop)) # file_ob.close() #print(stri) time5 = time.time() print("Overall time", time5 - time4) return pop, logbook
def test_for_cluster(): for_node = [(i, 'I') for i in range(1, 4)] for_node += [(i, 'O') for i in range(4, 6)] for_node += [(i, 'H2') for i in range(6, 8)] node_ctr = 8 indim = 3 outdim = 2 innov_num = 11 dob = 0 node_lis = [gene.Node(x, y) for x, y in for_node] for_conn = [(1, (1, 4), 0.4, False), (2, (1, 5), 0.25, True), (3, (2, 4), 0.25, True), (4, (2, 5), 0.5, True), (5, (3, 4), 0.7, True), (6, (3, 5), 0.6, False), (7, (1, 6), 0.5, True), (8, (6, 4), 0.4, True), (9, (3, 7), 0.3, True), (10, (7, 5), 0.6, True)] conn_lis = [ gene.Conn(x, (node_lis[tup[0] - 1], node_lis[tup[1] - 1]), w, status) for x, tup, w, status in for_conn ] for_bias = [(4, 0.2), (5, 0.1)] bias_conn_lis = [gene.BiasConn(node_lis[x - 1], y) for x, y in for_bias] newchromo1 = Chromosome(indim, outdim) newchromo1.__setattr__('conn_arr', conn_lis) newchromo1.__setattr__('bias_conn_arr', bias_conn_lis) newchromo1.__setattr__('node_arr', node_lis) newchromo1.__setattr__('dob', dob) newchromo1.set_node_ctr(node_ctr) for_node = [(i, 'I') for i in range(1, 4)] for_node += [(i, 'O') for i in range(4, 6)] st = '2212211' for_node += [(i + 6, 'H' + st[i]) for i in range(len(st))] node_ctr = 13 innov_num = 25 dob = 0 indim = 8 outdim = 2 node_lis = [gene.Node(x, y) for x, y in for_node] for_conn = [ (1, (1, 4), 0.3, True), (2, (1, 5), 0.25, False), (3, (2, 4), 0.25, False), (4, (2, 5), 0.5, False), (5, (3, 4), 0.7, False), (6, (3, 5), 0.5, True), (7, (1, 6), 0.2, True), (8, (6, 4), 0.1, True), (9, (2, 7), 0.1, True), (10, (7, 4), 0.15, True), (11, (1, 8), 0.5, True), (12, (8, 6), 0.7, True), (13, (1, 9), 0.3, False), (14, (9, 5), 1.0, True), (15, (3, 10), 0.33, True), (16, (10, 5), 0.77, True), (17, (1, 11), 0.25, True), (18, (11, 9), 0.15, True), (19, (2, 12), 0.6, True), (20, (12, 7), 0.4, True), (21, (3, 12), 0.8, True), (22, (2, 9), 0.9, True), (23, (12, 4), 0.75, True), (24, (11, 5), 0.25, True), ] conn_lis = [ gene.Conn(x, (node_lis[tup[0] - 1], node_lis[tup[1] - 1]), w, status) for x, tup, w, status in for_conn ] for_bias = [(4, 0.2), (5, 0.1)] bias_conn_lis = [gene.BiasConn(node_lis[x - 1], y) for x, y in for_bias] newchromo2 = Chromosome(indim, outdim) newchromo2.__setattr__('conn_arr', conn_lis) newchromo2.__setattr__('bias_conn_arr', bias_conn_lis) newchromo2.__setattr__('node_arr', node_lis) newchromo2.__setattr__('dob', dob) newchromo2.set_node_ctr(node_ctr) # newchromo.pp() for_node = [(i, 'I') for i in range(1, 4)] for_node += [(i, 'O') for i in range(4, 6)] st = '221221' for_node += [(i + 6, 'H' + st[i]) for i in range(len(st))] node_ctr = 12 dob = 0 indim = 3 outdim = 2 node_lis = [gene.Node(x, y) for x, y in for_node] for_conn = [(1, (1, 4), 0.3, True), (2, (1, 5), 0.25, False), (3, (2, 4), 0.25, False), (4, (2, 5), 0.5, False), (5, (3, 4), 0.7, False), (6, (3, 5), 0.5, True), (7, (1, 6), 0.2, True), (8, (6, 4), 0.1, True), (9, (2, 7), 0.1, True), (10, (7, 4), 0.15, True), (11, (1, 8), 0.5, True), (12, (8, 6), 0.7, True), (13, (1, 9), 0.3, False), (14, (9, 5), 1.0, True), (15, (3, 10), 0.33, True), (16, (10, 5), 0.77, True), (19, (2, 11), 0.6, True), (20, (11, 7), 0.4, True), (22, (3, 11), 0.75, True)] conn_lis = [ gene.Conn(x, (node_lis[tup[0] - 1], node_lis[tup[1] - 1]), w, status) for x, tup, w, status in for_conn ] for_bias = [(4, 0.2), (5, 0.1)] bias_conn_lis = [gene.BiasConn(node_lis[x - 1], y) for x, y in for_bias] newchromo3 = Chromosome(indim, outdim) newchromo3.__setattr__('conn_arr', conn_lis) newchromo3.__setattr__('bias_conn_arr', bias_conn_lis) newchromo3.__setattr__('node_arr', node_lis) newchromo3.__setattr__('dob', dob) newchromo3.set_node_ctr(node_ctr) for_node = [(i, 'I') for i in range(1, 4)] for_node += [(i, 'O') for i in range(4, 6)] st = '221221' for_node += [(i + 6, 'H' + st[i]) for i in range(len(st))] node_ctr = 12 innov_num = 21 dob = 0 indim = 3 outdim = 2 node_lis = [gene.Node(x, y) for x, y in for_node] for_conn = [(1, (1, 4), 0.3, True), (2, (1, 5), 0.25, False), (3, (2, 4), 0.25, False), (4, (2, 5), 0.5, False), (5, (3, 4), 0.7, False), (6, (3, 5), 0.5, True), (7, (1, 6), 0.2, True), (8, (6, 4), 0.1, True), (9, (2, 7), 0.1, True), (10, (7, 4), 0.15, True), (11, (1, 8), 0.5, True), (12, (8, 6), 0.7, True), (13, (1, 9), 0.3, False), (14, (9, 5), 1.0, True), (15, (3, 10), 0.33, True), (16, (10, 5), 0.77, True), (17, (1, 11), 0.25, True), (18, (11, 9), 0.15, True), (21, (2, 9), 0.65, True)] conn_lis = [ gene.Conn(x, (node_lis[tup[0] - 1], node_lis[tup[1] - 1]), w, status) for x, tup, w, status in for_conn ] for_bias = [(4, 0.2), (5, 0.1)] bias_conn_lis = [gene.BiasConn(node_lis[x - 1], y) for x, y in for_bias] newchromo4 = Chromosome(indim, outdim) newchromo4.__setattr__('conn_arr', conn_lis) newchromo4.__setattr__('bias_conn_arr', bias_conn_lis) newchromo4.__setattr__('node_arr', node_lis) newchromo4.__setattr__('dob', dob) newchromo4.set_node_ctr(node_ctr) for_node = [(i, 'I') for i in range(1, 4)] for_node += [(i, 'O') for i in range(4, 6)] st = '2212211' for_node += [(i + 6, 'H' + st[i]) for i in range(len(st))] node_ctr = 13 innov_num = 25 dob = 0 indim = 3 outdim = 2 node_lis = [gene.Node(x, y) for x, y in for_node] for_conn = [ (1, (1, 4), 0.3, False), (2, (1, 5), 0.25, False), (3, (2, 4), 0.25, False), (4, (2, 5), 0.5, False), (5, (3, 4), 0.7, False), (6, (3, 5), 0.5, True), (7, (1, 6), 0.2, True), (8, (6, 4), 0.1, True), (9, (2, 7), 0.1, True), (10, (7, 4), 0.15, True), (11, (1, 8), 0.5, True), (12, (8, 6), 0.7, True), (13, (1, 9), 0.3, False), (14, (9, 5), 1.0, True), (15, (3, 10), 0.33, True), (16, (10, 5), 0.77, True), (17, (1, 11), 0.25, True), (21, (3, 12), 0.8, True), (22, (2, 9), 0.9, True), (23, (12, 4), 0.75, True), (24, (11, 5), 0.25, True), ] conn_lis = [ gene.Conn(x, (node_lis[tup[0] - 1], node_lis[tup[1] - 1]), w, status) for x, tup, w, status in for_conn ] for_bias = [(4, 0.2), (5, 0.1)] bias_conn_lis = [gene.BiasConn(node_lis[x - 1], y) for x, y in for_bias] newchromo5 = Chromosome(indim, outdim) newchromo5.__setattr__('conn_arr', conn_lis) newchromo5.__setattr__('bias_conn_arr', bias_conn_lis) newchromo5.__setattr__('node_arr', node_lis) newchromo5.__setattr__('dob', dob) newchromo5.set_node_ctr(node_ctr) for_node = [(i, 'I') for i in range(1, 4)] for_node += [(i, 'O') for i in range(4, 6)] st = '22122' for_node += [(i + 6, 'H' + st[i]) for i in range(len(st))] node_ctr = 11 innov_num = 17 dob = 0 indim = 3 outdim = 2 node_lis = [gene.Node(x, y) for x, y in for_node] for_conn = [(1, (1, 4), 0.8, True), (2, (1, 5), 0.25, False), (3, (2, 4), 0.25, False), (4, (2, 5), 0.5, False), (5, (3, 4), 0.7, False), (6, (3, 5), 0.5, True), (7, (1, 6), 0.2, True), (8, (6, 4), 0.1, True), (9, (2, 7), 0.1, True), (10, (7, 4), 0.15, True), (11, (1, 8), 0.5, True), (12, (8, 6), 0.7, True), (13, (1, 9), 0.3, False), (14, (9, 5), 1.0, True), (15, (3, 10), 0.33, True), (16, (10, 5), 0.77, True)] conn_lis = [ gene.Conn(x, (node_lis[tup[0] - 1], node_lis[tup[1] - 1]), w, status) for x, tup, w, status in for_conn ] for_bias = [(4, 0.2), (5, 0.1)] bias_conn_lis = [gene.BiasConn(node_lis[x - 1], y) for x, y in for_bias] newchromo6 = Chromosome(indim, outdim) newchromo6.__setattr__('conn_arr', conn_lis) newchromo6.__setattr__('bias_conn_arr', bias_conn_lis) newchromo6.__setattr__('node_arr', node_lis) newchromo6.__setattr__('dob', dob) newchromo6.set_node_ctr(node_ctr) for_node = [(i, 'I') for i in range(1, 4)] for_node += [(i, 'O') for i in range(4, 6)] for_node += [(i, 'H2') for i in range(6, 8)] node_ctr = 8 indim = 3 outdim = 2 innov_num = 11 dob = 0 node_lis = [gene.Node(x, y) for x, y in for_node] for_conn = [(1, (1, 4), 0.4, False), (2, (1, 5), 0.25, True), (3, (2, 4), 0.25, True), (4, (2, 5), 0.5, True), (5, (3, 4), 0.7, True), (6, (3, 5), 0.6, False), (7, (1, 6), 0.5, True), (8, (6, 4), 0.4, True), (9, (3, 7), 0.3, True)] conn_lis = [ gene.Conn(x, (node_lis[tup[0] - 1], node_lis[tup[1] - 1]), w, status) for x, tup, w, status in for_conn ] for_bias = [(4, 0.2), (5, 0.1)] bias_conn_lis = [gene.BiasConn(node_lis[x - 1], y) for x, y in for_bias] newchromo7 = Chromosome(indim, outdim) newchromo7.__setattr__('conn_arr', conn_lis) newchromo7.__setattr__('bias_conn_arr', bias_conn_lis) newchromo7.__setattr__('node_arr', node_lis) newchromo7.__setattr__('dob', dob) newchromo7.set_node_ctr(node_ctr) chromo_list = [ newchromo1, newchromo2, newchromo3, newchromo4, newchromo5, newchromo6, newchromo7 ] #print([item.pp() for item in chromo_list]) print(cluster.distance(newchromo3, newchromo2)) cluster.give_cluster_head(chromo_list, 2) inputarr = np.array([[0, 2, 1], [0.8, 1, 2]])