当前位置: 首页>>代码示例>>Python>>正文


Python Population.generation方法代码示例

本文整理汇总了Python中population.Population.generation方法的典型用法代码示例。如果您正苦于以下问题:Python Population.generation方法的具体用法?Python Population.generation怎么用?Python Population.generation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在population.Population的用法示例。


在下文中一共展示了Population.generation方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: transpogen

# 需要导入模块: from population import Population [as 别名]
# 或者: from population.Population import generation [as 别名]
def transpogen(cipher, generations, individuals, size):
    start = time.time()
    print '[*] Genetic algorithm of {} individuals over {} generations'.format(individuals, generations)
    print '[*] Start at {}\n'.format(time.strftime('%X'))
    p = Population(cipher, individuals, size)

    for i in range(generations):
        p.generation()
        print '[+] ### Generation {} ### {}'.format(i, p)

    print '\n[*] End at {} ({} seconds)'.format(time.strftime('%X'), round(time.time() - start, 2))
    print '[*] Best solution is {}'.format(p.best())
    with open('plain.text', 'w') as solution_file:
        solution_file.write(p.plaintext())
开发者ID:ggranjus,项目名称:transpogen,代码行数:16,代码来源:transpogen.py

示例2: __main__

# 需要导入模块: from population import Population [as 别名]
# 或者: from population.Population import generation [as 别名]
def __main__():
    try: 
        opts, args = getopt.getopt(sys.argv[1:],"hT:l:N:G:u:x:g:t:X:s:r:K:S:b:c:e:z:v:")
    except getopt.GetoptError:
        usage()
    
    for opt, arg in opts:
        if opt == "-h":
            details()
            sys.exit(0)
        elif opt == "-T":
            global _T
            _T = int(arg)
        elif opt == "-l":
            global _l
            _l = map(float, arg.split(","))
        elif opt == "-N":
            global _N
            _N = int(arg)
        elif opt == "-G":
            global _G
            _G = int(arg)
        elif opt == "-u":
            global _u
            _u = float(arg)
        elif opt == "-x":
            global _x
            _x = float(arg)
        elif opt == "-t":
            global _t
            _t = float(arg)
        elif opt == "-X":
            global _X
            _X = int(arg)
        elif opt == "-s":
            global _s
            _s = float(arg)
        elif opt == "-r":
            global _r
            _r = float(arg)
        elif opt == "-K":
            global _K
            _K = int(arg)
        elif opt == "-c":
            global _c
            _c = float(arg)
        elif opt == "-b":
            global _b
            _b = int(arg)
        elif opt == "-e":
            global _e
            _e = float(arg)
        elif opt == "-z":
            global _z
            _z = float(arg)
        elif opt == "-v":
            global _v
            _v = float(arg)
        elif opt == "-g":
            global _g
            if arg not in ['ALL', 'HOMO', 'HET']:
                print("Invlaid selection calculation type: -g "+arg)
                sys.exit(0)
            _g = arg
        elif opt == "-S":
            global _S
            if arg not in ['R', 'T', 'O', 'P']:
                print("Invlaid selection type: -S "+arg)
                sys.exit(0)
            _S = arg
        else:
            sys.stderr.write("Unrecognized option: "+opt+"\n")
            usage()
    
    start = time.time()
    printParams()
        
    #initialize population    
    pop = Population(size = _N, selfing = _r, silence = _l, numCrosses = _X, selection = (_x, _z), t = _t, mode = _g, transRate = _u, maxClasses = _b, classMutation = _c, silenceMutation = _s, epsilon = _e, excision = _v)
    pop.firstGen(loci = _G, numTEs = _T)
     
    #phase 1 initial population stabilization   
    for gen in range(1, _K):
        pop.generation(_S, gen)
        
    sys.stderr.write("Run time (min): "+str((time.time()-start)/60.0)+"\n")
开发者ID:fabbyrob,项目名称:science,代码行数:88,代码来源:TEsim.py

示例3: run_simulation

# 需要导入模块: from population import Population [as 别名]
# 或者: from population.Population import generation [as 别名]
	def run_simulation(self, save_to_dot=True, save_to_json=True):
		#import Seed and lifetable data
		this_generation_population = Population()
		next_generation_population = None

		seed_group = seed.load_group(this_generation_population)
		table_data = loader.load_data()
		lifetable = table_data.life_table
		dispersal_table =\
		 table_data.dispersal_table
		random_module = RandomModule()

		#create analytics lists
		age_record_list = []
		population_record_list = []
		male_population_record_list = []
		female_population_record_list = []

		real_birth_rate_list = []
		real_death_rate_list = []

		edges_per_agent_list = []
		adult_males_list = []
		adult_females_list = []
		adult_females_per_males_list = []

		total_agent_relationships_list = []

		group_composition_list = []

		death_counter = Counter() #used to make sure the correct number
		#of deaths occur
		birth_counter = Counter() #used to make sure the correct number 
		#of births take place

		#assign all_groups by creating several copies of the 
		#seed generation
		for i in range(0, self.NUMBER_OF_SEED_GROUPS + 1):
			this_generation_population.add_group(copy.deepcopy(seed_group))
		
		"""
		I was having a strange error where the 0th group 
		was loaded incorrectly. This is a temporary fix

		"""
		del this_generation_population.groups[0]

		for i in range (0, self.NUMBER_OF_GENERATIONS):
			self.per_generation_printout(i)
			#analytics
			this_age_record = []
			this_population_record = 0
			this_male_population_record = 0
			this_female_population_record = 0
			this_edges_per_agent = 0
			this_generation_adult_males = 0
			this_generation_adult_females = 0
			this_generation_group_composition_list = []

			#reset counters
			death_counter.reset()
			birth_counter.reset()

			#make the next gen population a copy of this gen's pop
			this_generation_population.generation = i

			next_generation_population =\
			 copy.deepcopy(this_generation_population)

			#run the simulation for each sub_group.
			for j in range(0, len(this_generation_population.groups)):	
				this_generation = this_generation_population.groups[j]
				new_generation = next_generation_population.groups[j]

				females_to_male =\
				 this_generation.get_females_to_male()

				for agent_index in this_generation.whole_set:
					#print str(agent_index) + ", " + str(len(this_generation.agent_array))

					this_agent =\
					 this_generation.agent_dict[agent_index]
					new_agent =\
					 new_generation.agent_dict[agent_index]

					#increment age
					new_generation.promote_agent(new_agent)

					#check birth_rate
					if this_agent.index in this_generation.female_set:
						chance_of_birth =\
						 lifetable.chance_of_birth(females_to_male, 
						 	this_agent.age)

					#check for birth
					self.check_for_birth(this_generation, new_generation,
						this_agent, new_agent, females_to_male,
						agent_index, lifetable, random_module,
						birth_counter, male_population_record_list)

#.........这里部分代码省略.........
开发者ID:adeeshaek,项目名称:primate-social-network,代码行数:103,代码来源:simulation.py


注:本文中的population.Population.generation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。