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


Python individual.Individual类代码示例

本文整理汇总了Python中individual.Individual的典型用法代码示例。如果您正苦于以下问题:Python Individual类的具体用法?Python Individual怎么用?Python Individual使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: __init__

 def __init__(self, size, initialize=False):
     self.individuals = []
     
     if initialize:
         for i in range(0, size):
             individual = Individual()
             individual.generate_individual()
             self.individuals.append(individual)
开发者ID:akaptur,项目名称:genetic-algorithm-experiments,代码行数:8,代码来源:population.py

示例2: test_fight

 def test_fight(self):
     ind1 = Individual("01101110")
     ind2 = Individual("00111000")
     fight1 = ind2.fight(ind1)
     self.assertEqual(ind1.fitness, 1)
     self.assertEqual(ind2.fitness, 0)
     fight2 = ind1.fight(ind2)
     self.assertEqual(fight1, False)
     self.assertEqual(fight2, False)
开发者ID:gitter-badger,项目名称:bit-ai-algen-alg1,代码行数:9,代码来源:ind_test.py

示例3: crossover_pt

 def crossover_pt(self, individual_1, individual_2):
     crossover_individual = Individual()
     
     uniform_rate = uniform(3, 7) * .1
     crossover_point =  int(uniform_rate * len(crossover_individual.genes))
     
     crossover_individual.genes = individual_1.genes[0:crossover_point]
     crossover_individual.genes += individual_2.genes[crossover_point:]
     
     return crossover_individual
开发者ID:akaptur,项目名称:genetic-algorithm-experiments,代码行数:10,代码来源:algorithm.py

示例4: setup

class TestEvaluateAgainst:
    def setup(self):
        self.individual_a = Individual('0123456789')

    def test_identical(self):
        chars = self.individual_a.chars
        assert_true(self.individual_a.evaluate_against(chars) == len(chars))

    def test_no_similarity(self):
        assert_true(self.individual_a.evaluate_against('a tallship') == 0)
开发者ID:HarryCutts,项目名称:like-a-weasel,代码行数:10,代码来源:test_individual.py

示例5: crossover_random

 def crossover_random(self, individual_1, individual_2):
     crossover_individual = Individual()
     
     for i in range(0, len(crossover_individual.genes)):
         # crossover
         if random() <= self.uniform_rate:
             crossover_individual.genes[i] = individual_1.genes[i]
         else:
             crossover_individual.genes[i] = individual_2.genes[i]
     
     return crossover_individual
开发者ID:akaptur,项目名称:genetic-algorithm-experiments,代码行数:11,代码来源:algorithm.py

示例6: run_once

 def run_once(self):
     newpop = []
     # Elitism, keep the best chromosome to the next generation
     newpop = self.population[:3]
     for i in range(3, self.popsize):
         tmpchrom = Individual(mother=self.__my_choice(), father=self.__my_choice())
         tmpchrom.mutate()
         newpop.append(tmpchrom)
     self.population = newpop
     self.evaluate_all()
     self.randomize_duplicates()
     self.apply_max()
     self.evaluate_all()
     self.population.sort(key=attrgetter("fitness"), reverse=True)
     self.inc_mutation_rate(MUTATION_RATE_INC)
开发者ID:maxme,项目名称:genetic-parser-gen,代码行数:15,代码来源:ga.py

示例7: init_children_test

    def init_children_test(self, num_children):

        self.clear_test_state()
        player1 = Individual()
        testee = player1.get_robot()
        testee.location = constants.testee_loc
        self.robots = [testee]
        self.gamestate.add_robot(testee.location, testee.player_id)
        
        # Force the prime rule to be the move rule so direction is returned
        while testee.eval_order[0].action != 'move':
            random.shuffle(testee.eval_order)
        
        rule = self.robots[0].eval_order[0]
        rule.insert_random_parent()
        for x in range(num_children):
            self.insert_random_root_child(rule)
开发者ID:andrewgailey,项目名称:robogen,代码行数:17,代码来源:robogentest.py

示例8: setUp

 def setUp(self):
     self.indi = Individual()
     self.indi.addID('@[email protected]')
     self.indi.addName('John Rivas')
     self.indi.addSex('M')
     self.indi.addBirt('9 MAY 1978')
     self.indi.addDeat('12 APR 2013')
     self.indi.addFams('@[email protected]')
     self.indi.addFamc('@[email protected]')
开发者ID:Gosin,项目名称:gedcom,代码行数:9,代码来源:individualTest.py

示例9: __init__

 def __init__(self, size):
     self.size = size
     self.pop = []
     self.selected = []
     self.selected_indexes = []
     self.fitness_table = []
     Individual.mutation_factor = 5
     for i in xrange(size):
         self.pop.append(Individual.random_ind())
开发者ID:gitter-badger,项目名称:bit-ai-algen-alg1,代码行数:9,代码来源:population.py

示例10: make_json_record

def make_json_record(case_name=CASE_NAME, seed=0, lineage=0, age=0):
    input_filepath = os.path.join(RESULT_DIR, case_name)
    output_file = os.path.join(
        ensure_exists(os.path.join(ANALYSIS_DIR, case_name, "seed-{}".format(seed))), "game.json"
    )

    params = load("params", input_filepath, seed)

    TASKS = [(task[0], int(task[1][::-1], 2)) for task in params["TASKS"]]
    hit_multipliers, patterns = zip(*TASKS)

    lineages = load("lineages", input_filepath, seed)

    def i2s(i):
        return tuple((i >> n) & 1 for n in range(params["NUM_NODES"]))

    ind = Individual(lineages[lineage][age].genome)
    transitions = ind.play_game(hit_multipliers, patterns)
    states = [
        ps[: params["NUM_SENSORS"]] + cs[params["NUM_SENSORS"] :]
        for ps, cs in zip(map(i2s, transitions[0]), map(i2s, transitions[1]))
    ]

    trial_length = params["WORLD_HEIGHT"]

    block_sizes = []
    for pattern in patterns:
        block_sizes += [sum(i2s(pattern))] * int(params["NUM_TRIALS"] / len(patterns))

    json_dict = {
        "generation": params["NGEN"] - age,
        "connectivityMatrix": ind.cm.T.tolist(),
        "nodeTypes": {"sensors": [0, 1], "hidden": [2, 3, 4, 5], "motors": [6, 7]},
        "blockSize": block_sizes,
        "Trial": [
            {"trialNum": i, "lifeTable": states[(i * trial_length) : ((i + 1) * trial_length)]}
            for i in range(params["NUM_TRIALS"])
        ],
    }
    with open(output_file, "w") as f:
        json.dump(json_dict, f)
    print("Saved game representation to `{}`.".format(output_file))

    return json_dict
开发者ID:slipperyhank,项目名称:pyanimats,代码行数:44,代码来源:analyze.py

示例11: __init__

 def __init__(
     self, data, expected_result, popsize=50, mut_rate=20, GA_printers=None
 ):
     Individual.expected_result = {"rowdata": expected_result}
     Individual.mutation_rate = mut_rate
     Individual.data = data
     self.popsize = popsize
     self.population = []
     for i in range(0, popsize):
         c = Individual()
         c.randomize()
         self.population.append(c)
     self.population.sort(key=attrgetter("fitness"), reverse=True)
     self.GA_printers = GA_printers
     self.generation = 0
     self.wheel_size = sum(range(1, popsize + 1))
     self.wheel = []
     self.__init_wheel()
     self.test = [0 for i in range(0, self.popsize)]
开发者ID:maxme,项目名称:genetic-parser-gen,代码行数:19,代码来源:ga.py

示例12: test_addSex

 def test_addSex(self):
     indi = Individual()
     value = "M"
     indi.addSex(value)
     self.assertEqual(indi.getSex(), value)  
     
     value = "F"
     indi.addSex(value)
     self.assertEqual(indi.getSex(), value)      
开发者ID:Gosin,项目名称:gedcom,代码行数:9,代码来源:individualTest.py

示例13: mutate

def mutate(indiv: individual.Individual):
    # for i in range(individual.Individual.gene_length):
        # if elitism and i == 0:
            # continue
        # if random.random() <= mutation_rate:
            # indiv.genes[i // 8] ^= 1 << (i % 8)
    for i, _ in enumerate(indiv.genes):
        # if elitism and i == 0:
            # continue
        if random.random() <= mutation_rate:
            indiv.genes[i] = random.randint(0, 255)
开发者ID:gtdrakeley,项目名称:Genetic,代码行数:11,代码来源:evolution.py

示例14: init_node_type_test

    def init_node_type_test(self):
        """Puts Test in known state for Node type tests."""

        self.clear_test_state()
        player1 = Individual()
        player2 = Individual()
        testee = player1.get_robot()
        testee.location = constants.testee_loc
        ally = player1.get_robot()
        ally.location = constants.ally_loc
        enemy = player2.get_robot()
        enemy.location = constants.enemy_loc
        enemy.player_id = 1
        self.robots = [testee, ally, enemy]
        for bot in self.robots:
            self.gamestate.add_robot(bot.location, bot.player_id)
            
        # I use the default 'guard' action to determine when a rule evaluates 
        #     False, so the test rule must not be the guard rule
        while testee.eval_order[0].action == 'guard':
            random.shuffle(testee.eval_order)
        testee.eval_order[0].insert_random_parent()
开发者ID:andrewgailey,项目名称:robogen,代码行数:22,代码来源:robogentest.py

示例15: setUp

    def setUp(self):
        self.indi = Individual()
        self.indi.addID('@[email protected]')
        self.indi.addName('John Rivas')
        self.indi.addSex('M')
        self.indi.addBirt('9 MAY 1978')
        self.indi.addDeat('12 APR 2013')
        self.indi.addFams('@[email protected]')
        self.indi.addFamc('@[email protected]')
        
        self.fam1 = Family()
        self.fam1.addFamID('@[email protected]')
        self.fam1.addHusb('@[email protected]')
        self.fam1.addWife('@[email protected]')
        self.fam1.addChil('@[email protected]')
        self.fam1.addChil('@[email protected]')

        self.individuals =  dict()
        self.individuals["one"] = self.indi
                
        self.families =  dict()
        self.families["one"] = self.fam1
开发者ID:Gosin,项目名称:gedcom,代码行数:22,代码来源:outputTest.py


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