Skip to content

Commit

Permalink
approaching heavywatal#20
Browse files Browse the repository at this point in the history
  • Loading branch information
hamazaki1990 committed May 17, 2017
1 parent 1274b2b commit 735afc7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
12 changes: 7 additions & 5 deletions hamazaki1990/individual.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ def get_fitness(self):
def __repr__(self):
return str(self._id)

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


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())


if __name__ == '__main__':
main()
38 changes: 38 additions & 0 deletions hamazaki1990/visualize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import pandas as pd
from population import Population


def calculate_ave(seq):
return sum(seq)/len(seq)


def calculate_var(seq):
ave = calculate_ave(seq)
sqd = [(seq[x] - ave)**2 for x in range(len(seq))]
return sum(sqd)/len(seq)


def change_allelewf(Population): # simulate fixation in Wrigft-Fisher model
time = 0
while Population.is_not_fixed():
Population.next_genwf()
Population.print_ids()
time += 1
else:
winner_id = Population._inds[0]
return time, winner_id


def simulate_fixmo(Population): # simulate fixation in Moran model
time = 0
while Population.is_not_fixed():
Population.next_genmo()
time += 1
else:
winner_id = Population._inds[0]
return time, winner_id


p1 = Population(10)
data = list(change_allelewf(p1))
data.to_csv()

0 comments on commit 735afc7

Please sign in to comment.