diff --git a/hamazaki1990/individual.py b/hamazaki1990/individual.py index c46a3d7..e4bd463 100644 --- a/hamazaki1990/individual.py +++ b/hamazaki1990/individual.py @@ -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() diff --git a/hamazaki1990/visualize.py b/hamazaki1990/visualize.py new file mode 100644 index 0000000..75a427e --- /dev/null +++ b/hamazaki1990/visualize.py @@ -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()