-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitialize_population_fast.py
47 lines (38 loc) · 1.38 KB
/
initialize_population_fast.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import sys
import random
import numpy as np
import gen_lib_fast as gl
print "Usage: <eve file name> <current generation file name> <previous generation file name> <population size> <genome size> <mutation rate>"
# unloading
eve_file = open(sys.argv[1],'w')
f = open(sys.argv[2], 'w')
t = open(sys.argv[3], 'w')
population_size = int (sys.argv[4])
genome_size = int (sys.argv[5])
mutation_rate = float (sys.argv[6])
base_pairs = np.array([1, 2, 3, 4])
eve = {}
for i in xrange(population_size):
num_mutations = np.random.binomial(genome_size, mutation_rate)
mutation_indecies = random.sample(xrange(0,genome_size), num_mutations)
if (mutation_indecies):
mutation_indecies.sort()
for j in mutation_indecies:
if j in eve:
temp_array = np.array([eve[j]])
temp_array = np.setdiff1d(base_pairs, temp_array) # make sure mutations are true mutations
mutation_value = np.random.choice(temp_array,1)[0]
f.write(str(j) + " " + str(mutation_value) + " ")
else:
eve[j] = np.random.choice(base_pairs,1)[0]
temp_array = np.array([eve[j]])
temp_array = np.setdiff1d(base_pairs, temp_array) # make sure mutations are true mutations
mutation_value = np.random.choice(temp_array,1)[0]
f.write(str(j) + " " + str(mutation_value) + " ")
f.write("\n")
f.close()
t.write("Intentionally Left Blank")
t.close()
for i in eve:
eve_file.write(str(i) + " " + str(eve[i]) + " ")
eve_file.close()