-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathind_sim_csv.py
More file actions
83 lines (68 loc) · 2.8 KB
/
ind_sim_csv.py
File metadata and controls
83 lines (68 loc) · 2.8 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# csv file form my Simulation
import csv
from Individual_based_sim import ipopulation, gametes, random, icount, \
pairing
def multiple_generations_diffent_mew(initalpop, n, num, mutation_rate):
count_n = 1
# fitness1 for (0,0), fitness2 for (0,1) and (1,0), fitness3 for (1,1)
fitness1 = 0.9
fitness2 = 0.9
fitness3 = 0.9
# reproduction is how many potential gametes per gene
repoduction = 100.0
pop = initalpop
# while loop keeps track of generations and changs the population from the
# intinal population to the next geration after the first generation
while count_n <= n:
nextgerneration = gametes(
pop, fitness1, fitness2, fitness3, repoduction)
genechosen, genechosen_change = random(
nextgerneration, num, mutation_rate)
newgeneration = (pairing(genechosen_change, num))
count_n = count_n + 1
pop = newgeneration
# to check count the amount of 1's and 0's
count0, count1 = icount(newgeneration)
return count0, count1
initalpop = ipopulation(1000)
# multiple_generations(ipop, number of generations, number of individuals)
def makCSV(initalpop, n, num, mr1, mr2, mr3, mr4, mr5):
myFile = open('ind_sim_diffu.csv', 'w')
n = 0
# run once 5 times but in one for loop instead of 5 had codeing mutation rate
# put into functon
with myFile:
myFields = ['population', 'mew', 'outcome', 'pace']
writer = csv.DictWriter(myFile, fieldnames=myFields)
writer.writeheader()
for i in range(0, 5):
a, b = multiple_generations_diffent_mew(
initalpop, n, num, mr1)
writer.writerow(
{'population': num, 'mew': mr1, 'outcome': b /
(a + b), 'pace': 1})
for i in range(0, 5):
a, b = multiple_generations_diffent_mew(
initalpop, n, num, mr2)
writer.writerow(
{'population': num, 'mew': mr2, 'outcome': b /
(a + b), 'pace': 2})
for i in range(0, 5):
a, b = multiple_generations_diffent_mew(
initalpop, n, num, mr3)
writer.writerow(
{'population': num, 'mew': mr3, 'outcome': b /
(a + b), 'pace': 3})
for i in range(0, 5):
a, b = multiple_generations_diffent_mew(
initalpop, n, num, mr4)
writer.writerow(
{'population': num, 'mew': mr4, 'outcome': b /
(a + b), 'pace': 4})
for i in range(0, 5):
a, b = multiple_generations_diffent_mew(
initalpop, n, num, mr5)
writer.writerow(
{'population': num, 'mew': mr5, 'outcome': b /
(a + b), 'pace': 5})
makCSV(initalpop, 1000, 1000, 1, 10, 100, 1000, 10000)