-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevaluation.py
31 lines (23 loc) · 1.13 KB
/
evaluation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""Examples module for users on how to create fitness functions and testing"""
import numpy as np
from gevopy.fitness import FitnessModel
# ------------------------------------------------------------------
# Most Ones --------------------------------------------------------
# This fitness object scores each phenotypes with the amount of ones
# the phenotype has in it's chromosome attribute.
class MostOnes(FitnessModel):
"""Fitness model count amount of '1' in the chromosome"""
def score(self, phenotype):
return phenotype.chromosome.count(1)
# ------------------------------------------------------------------
# Random -----------------------------------------------------------
# This fitness object scores each phenotypes completelly random.
class Random(FitnessModel):
"""Fitness model assigns a random score between 0-1"""
# pylint: disable=attribute-defined-outside-init
def setup(self, phenotypes):
"""Set up method to run once per generation"""
self.executed = True
def score(self, phenotype):
"""Method to use for evaluation phenotypes"""
return np.random.random()