當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。