Add basic structure
This commit is contained in:
parent
494f3d530a
commit
8911665a3f
8 changed files with 136 additions and 0 deletions
10
connectiongene.py
Normal file
10
connectiongene.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
class ConnectionGene:
|
||||
def __init__(self, into: int, out: int, innovation: int, weight: float, enabled: bool):
|
||||
self.into: int = into
|
||||
self.out: int = out
|
||||
self.innovation: int = innovation
|
||||
self.weight: float = weight
|
||||
self.enabled: bool = enabled
|
||||
|
||||
def copy(self) -> 'ConnectionGene':
|
||||
return ConnectionGene(self.into, self.out, self.innovation, self.weight, self.enabled)
|
51
genome.py
Normal file
51
genome.py
Normal file
|
@ -0,0 +1,51 @@
|
|||
import math
|
||||
from typing import List
|
||||
|
||||
from connectiongene import ConnectionGene
|
||||
|
||||
|
||||
class Genome:
|
||||
def __init__(self, genome: 'Genome' = None):
|
||||
self.fitness: float = 0
|
||||
self.adjusted_fitness: float = 0
|
||||
self.connection_gene_list: List[ConnectionGene] = []
|
||||
if genome is not None:
|
||||
self.fitness: float = genome.fitness
|
||||
self.adjusted_fitness: float = genome.adjusted_fitness
|
||||
self.connection_gene_list: List[ConnectionGene] = genome.connection_gene_list
|
||||
|
||||
@staticmethod
|
||||
def cross_over(parent1: 'Genome', parent2: 'Genome') -> 'Genome':
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def is_same_species(genome1: 'Genome', genome2: 'Genome') -> 'Genome':
|
||||
pass
|
||||
|
||||
def generate_network(self):
|
||||
pass
|
||||
|
||||
def evaluate_network(self, inputs: List[float]) -> List[float]:
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def sigmoid(x: float) -> float:
|
||||
return 1 / (1 + math.exp(-x))
|
||||
|
||||
def mutate(self):
|
||||
pass
|
||||
|
||||
def mutate_weight(self):
|
||||
pass
|
||||
|
||||
def mutate_add_connection(self):
|
||||
pass
|
||||
|
||||
def mutate_add_node(self):
|
||||
pass
|
||||
|
||||
def mutate_enable(self):
|
||||
pass
|
||||
|
||||
def mutate_disable(self):
|
||||
pass
|
7
innovationcounter.py
Normal file
7
innovationcounter.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
class InnovationCounter:
|
||||
innovation: int = 0
|
||||
|
||||
@staticmethod
|
||||
def new_innovation():
|
||||
InnovationCounter.innovation += 1
|
||||
return InnovationCounter.innovation
|
1
neatconfig.py
Normal file
1
neatconfig.py
Normal file
|
@ -0,0 +1 @@
|
|||
POPULATION: int = 300
|
9
nodegene.py
Normal file
9
nodegene.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
from typing import List
|
||||
|
||||
from connectiongene import ConnectionGene
|
||||
|
||||
|
||||
class NodeGene:
|
||||
def __init__(self):
|
||||
self.value: float = 0
|
||||
self.incoming: List[ConnectionGene] = []
|
33
pool.py
Normal file
33
pool.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
from typing import List, Callable
|
||||
|
||||
from genome import Genome
|
||||
from neatconfig import *
|
||||
from species import Species
|
||||
|
||||
|
||||
class Pool:
|
||||
def __init__(self):
|
||||
self.species: List[Species] = []
|
||||
for _ in range(POPULATION):
|
||||
self.add_to_species(Genome())
|
||||
|
||||
def add_to_species(self, genome: Genome):
|
||||
pass
|
||||
|
||||
def evaluate_fitness(self, d: Callable[[Genome], float]):
|
||||
pass
|
||||
|
||||
def get_top_genome(self) -> Genome:
|
||||
pass
|
||||
|
||||
def calculate_global_adjusted_fitness(self) -> float:
|
||||
pass
|
||||
|
||||
def remove_weak_gnomes_from_species(self):
|
||||
pass
|
||||
|
||||
def calculate_gnome_adjusted_fitness(self) -> float:
|
||||
pass
|
||||
|
||||
def breed_new_generation(self):
|
||||
pass
|
25
species.py
Normal file
25
species.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
from typing import List
|
||||
|
||||
from genome import Genome
|
||||
|
||||
|
||||
class Species:
|
||||
def __init__(self, genome: Genome = None):
|
||||
self.genomes: List[Genome] = []
|
||||
if genome is not None:
|
||||
self.genomes.append(genome)
|
||||
|
||||
def calculate_genome_adjusted_fitness(self):
|
||||
pass
|
||||
|
||||
def get_total_adjusted_fitness(self) -> float:
|
||||
pass
|
||||
|
||||
def remove_weak_genomes(self):
|
||||
pass
|
||||
|
||||
def get_top_genome(self) -> Genome:
|
||||
pass
|
||||
|
||||
def breed_child(self) -> Genome:
|
||||
pass
|
0
xor.py
Normal file
0
xor.py
Normal file
Reference in a new issue