odify genome for the official release

This commit is contained in:
root
2024-07-10 11:24:11 +08:00
parent 075460f896
commit ee8ec84202
83 changed files with 588 additions and 611 deletions

50
examples/func_fit/xor.py Normal file
View File

@@ -0,0 +1,50 @@
from pipeline import Pipeline
from algorithm.neat import *
from problem.func_fit import XOR3d
from tensorneat.common import ACT_ALL, AGG_ALL, Act, Agg
if __name__ == "__main__":
pipeline = Pipeline(
algorithm=NEAT(
species=DefaultSpecies(
genome=DenseInitialize(
num_inputs=3,
num_outputs=1,
max_nodes=50,
max_conns=100,
node_gene=DefaultNodeGene(
activation_default=Act.tanh,
# activation_options=(Act.tanh,),
activation_options=ACT_ALL,
aggregation_default=Agg.sum,
# aggregation_options=(Agg.sum,),
aggregation_options=AGG_ALL,
),
output_transform=Act.standard_sigmoid, # the activation function for output node
mutation=DefaultMutation(
node_add=0.1,
conn_add=0.1,
node_delete=0,
conn_delete=0,
),
),
pop_size=10000,
species_size=20,
compatibility_threshold=2,
survival_threshold=0.01, # magic
),
),
problem=XOR3d(),
generation_limit=10000,
fitness_target=-1e-3,
)
# initialize state
state = pipeline.setup()
# print(state)
# run until terminate
state, best = pipeline.auto_run(state)
# show result
pipeline.show(state, best)
pipeline.save(state=state)

View File

@@ -0,0 +1,63 @@
from pipeline import Pipeline
from algorithm.neat import *
from algorithm.hyperneat import *
from tensorneat.common import Act
from problem.func_fit import XOR3d
if __name__ == "__main__":
pipeline = Pipeline(
algorithm=HyperNEAT(
substrate=FullSubstrate(
input_coors=[(-1, -1), (0.333, -1), (-0.333, -1), (1, -1)], # 3(XOR3d inputs) + 1(bias)
hidden_coors=[
(-1, -0.5), (0.333, -0.5), (-0.333, -0.5),
(1, -0.5),
(-1, 0),
(0.333, 0),
(-0.333, 0),
(1, 0),
(-1, 0.5),
(0.333, 0.5),
(-0.333, 0.5),
(1, 0.5),
],
output_coors=[
(0, 1), # one output
],
),
neat=NEAT(
species=DefaultSpecies(
genome=DefaultGenome(
num_inputs=4, # [*coor1, *coor2]
num_outputs=1, # the weight of connection between two coor1 and coor2
max_nodes=50,
max_conns=100,
node_gene=DefaultNodeGene(
activation_default=Act.tanh,
activation_options=(Act.tanh,),
),
output_transform=Act.tanh, # the activation function for output node in NEAT
),
pop_size=1000,
species_size=10,
compatibility_threshold=2,
survival_threshold=0.03,
),
),
activation=Act.tanh,
activate_time=10,
output_transform=Act.sigmoid, # the activation function for output node in HyperNEAT
),
problem=XOR3d(),
generation_limit=300,
fitness_target=-1e-6,
)
# initialize state
state = pipeline.setup()
# print(state)
# run until terminate
state, best = pipeline.auto_run(state)
# show result
pipeline.show(state, best)

View File

@@ -0,0 +1,47 @@
from pipeline import Pipeline
from algorithm.neat import *
from algorithm.neat.gene.node.default_without_response import NodeGeneWithoutResponse
from problem.func_fit import XOR3d
from utils.activation import ACT_ALL, Act
if __name__ == "__main__":
pipeline = Pipeline(
seed=0,
algorithm=NEAT(
species=DefaultSpecies(
genome=RecurrentGenome(
num_inputs=3,
num_outputs=1,
max_nodes=50,
max_conns=100,
activate_time=5,
node_gene=NodeGeneWithoutResponse(
activation_options=ACT_ALL, activation_replace_rate=0.2
),
output_transform=Act.sigmoid,
mutation=DefaultMutation(
node_add=0.05,
conn_add=0.2,
node_delete=0,
conn_delete=0,
),
),
pop_size=10000,
species_size=10,
compatibility_threshold=3.5,
survival_threshold=0.03,
),
),
problem=XOR3d(),
generation_limit=10000,
fitness_target=-1e-8,
)
# initialize state
state = pipeline.setup()
# print(state)
# run until terminate
state, best = pipeline.auto_run(state)
# show result
pipeline.show(state, best)