Skip to content

Commit

Permalink
modified heavywatal#15
Browse files Browse the repository at this point in the history
  • Loading branch information
hamazaki1990 committed May 5, 2017
1 parent 350904a commit 8ab7b07
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 45 deletions.
17 changes: 11 additions & 6 deletions hamazaki1990/individual.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ def __repr__(self):
return str(self._id)


ind = Individual(42)
print(ind.get_id())
print(ind.get_fitness())
def main():
ind = Individual(42)
print(ind.get_id())
print(ind.get_fitness())

ind2 = Individual(30, 0.8)
print(ind2.get_id())
print(ind2.get_fitness())
ind2 = Individual(30, 0.8)
print(ind2.get_id())
print(ind2.get_fitness())


if __name__ == '__main__':
main()
18 changes: 4 additions & 14 deletions hamazaki1990/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,9 @@
from population import Population


def get_heterogeneity(Population): # fixed or not
Population_ids = [x.get_id() for x in Population._inds]
for x in range(1, len(Population_ids)):
if Population_ids[0] != Population_ids[x]:
return True
break
else:
return False


def simulate_fixwf(Population): # simulate fixation in Wrigft-Fisher model
time = 0
while get_heterogeneity(Population):
while Population.is_not_fixed():
Population.next_genwf()
time += 1
else:
Expand All @@ -25,7 +15,7 @@ def simulate_fixwf(Population): # simulate fixation in Wrigft-Fisher model

def simulate_fixmo(Population): # simulate fixation in Moran model
time = 0
while get_heterogeneity(Population):
while Population.is_not_fixed():
Population.next_genmo()
time += 1
else:
Expand Down Expand Up @@ -80,7 +70,7 @@ def repeat_simmo(trials, n, mutantrate=0, s=0):
p1 = Population(10, 0.1, 0.5)
p1.print_ids()
print(p1._inds.count(1))
print(get_heterogeneity(p1))
print(p1.is_not_fixed())
print(simulate_fixwf(p1))

trial1 = Repeat_simwf(5, 10)
Expand All @@ -92,6 +82,6 @@ def repeat_simmo(trials, n, mutantrate=0, s=0):

p2 = Population(10, 0.1, 0.5)
p2.print_ids()
print(get_heterogeneity(p2))
print(p2.is_not_fixed())
print(simulate_fixmo(p2))
print(repeat_simmo(5, 10, 0.1, 0.5))
63 changes: 38 additions & 25 deletions hamazaki1990/population.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,40 +39,53 @@ def next_genmo(self):
i_dying = random.randrange(size)
self._inds[i_dying] = roulettechoice(self._inds, cumsum_fitness)

def is_not_fixed(self):
for x in range(1, len(self._inds)):
if self._inds[0] != self._inds[x]:
return True
else:
return False

p1_1 = Population(10)
p1_1.print_ids()
p1_1.print_fitness()

for x in range(20):
p1_1.next_genwf()
def main():
p1_1 = Population(10)
p1_1.print_ids()
p1_1.print_fitness()
p1_1.print_fitness()
print(p1_1.is_not_fixed())

p1_2 = Population(10, 0.3, 0.2)
p1_2.print_ids()
p1_2.print_fitness()
for x in range(20):
p1_1.next_genwf()
p1_1.print_ids()
p1_1.print_fitness()
print(p1_1.is_not_fixed())

for x in range(20):
p1_2.next_genwf()
p1_2 = Population(10, 0.3, 0.2)
p1_2.print_ids()
p1_2.print_fitness()
p1_2.print_fitness()

for x in range(20):
p1_2.next_genwf()
p1_2.print_ids()
p1_2.print_fitness()

p2_1 = Population(10)
p2_1.print_ids()
p2_1.print_fitness()

for x in range(20):
p2_1.next_genmo()
p2_1 = Population(10)
p2_1.print_ids()
p2_1.print_fitness()
p2_1.print_fitness()

p2_2 = Population(10, 0.3, 0.2)
p2_2.print_ids()
p2_2.print_fitness()
for x in range(20):
p2_1.next_genmo()
p2_1.print_ids()
p2_1.print_fitness()

for x in range(20):
p2_2.next_genmo()
p2_2 = Population(10, 0.3, 0.2)
p2_2.print_ids()
p2_2.print_fitness()
p2_2.print_fitness()

for x in range(20):
p2_2.next_genmo()
p2_2.print_ids()
p2_2.print_fitness()


if __name__ == '__main__':
main()

0 comments on commit 8ab7b07

Please sign in to comment.