update some examples
This commit is contained in:
@@ -1,39 +0,0 @@
|
||||
from pipeline import Pipeline
|
||||
from algorithm.neat import *
|
||||
|
||||
from problem.rl_env import BraxEnv
|
||||
from tensorneat.common import Act
|
||||
|
||||
if __name__ == "__main__":
|
||||
pipeline = Pipeline(
|
||||
algorithm=NEAT(
|
||||
species=DefaultSpecies(
|
||||
genome=DefaultGenome(
|
||||
num_inputs=27,
|
||||
num_outputs=8,
|
||||
max_nodes=100,
|
||||
max_conns=200,
|
||||
node_gene=DefaultNodeGene(
|
||||
activation_options=(Act.tanh,),
|
||||
activation_default=Act.tanh,
|
||||
),
|
||||
output_transform=Act.tanh,
|
||||
),
|
||||
pop_size=1000,
|
||||
species_size=10,
|
||||
compatibility_threshold=3.5,
|
||||
survival_threshold=0.01,
|
||||
),
|
||||
),
|
||||
problem=BraxEnv(
|
||||
env_name="ant",
|
||||
),
|
||||
generation_limit=10000,
|
||||
fitness_target=5000,
|
||||
)
|
||||
|
||||
# initialize state
|
||||
state = pipeline.setup()
|
||||
# print(state)
|
||||
# run until terminate
|
||||
state, best = pipeline.auto_run(state)
|
||||
@@ -1,48 +0,0 @@
|
||||
import jax
|
||||
|
||||
from pipeline import Pipeline
|
||||
from algorithm.neat import *
|
||||
|
||||
from problem.rl_env import BraxEnv
|
||||
from tensorneat.common import Act
|
||||
|
||||
|
||||
def sample_policy(randkey, obs):
|
||||
return jax.random.uniform(randkey, (6,), minval=-1, maxval=1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pipeline = Pipeline(
|
||||
algorithm=NEAT(
|
||||
species=DefaultSpecies(
|
||||
genome=DefaultGenome(
|
||||
num_inputs=17,
|
||||
num_outputs=6,
|
||||
max_nodes=50,
|
||||
max_conns=100,
|
||||
node_gene=DefaultNodeGene(
|
||||
activation_options=(Act.tanh,),
|
||||
activation_default=Act.tanh,
|
||||
),
|
||||
output_transform=Act.tanh,
|
||||
),
|
||||
pop_size=1000,
|
||||
species_size=10,
|
||||
),
|
||||
),
|
||||
problem=BraxEnv(
|
||||
env_name="halfcheetah",
|
||||
max_step=1000,
|
||||
obs_normalization=True,
|
||||
sample_episodes=1000,
|
||||
sample_policy=sample_policy,
|
||||
),
|
||||
generation_limit=10000,
|
||||
fitness_target=5000,
|
||||
)
|
||||
|
||||
# initialize state
|
||||
state = pipeline.setup()
|
||||
# print(state)
|
||||
# run until terminate
|
||||
state, best = pipeline.auto_run(state)
|
||||
51
examples/brax/halfcheetah.py
Normal file
51
examples/brax/halfcheetah.py
Normal file
@@ -0,0 +1,51 @@
|
||||
from tensorneat.pipeline import Pipeline
|
||||
from tensorneat.algorithm.neat import NEAT
|
||||
from tensorneat.genome import DefaultGenome, BiasNode
|
||||
|
||||
from tensorneat.problem.rl import BraxEnv
|
||||
from tensorneat.common import Act, Agg
|
||||
|
||||
import jax
|
||||
|
||||
|
||||
def random_sample_policy(randkey, obs):
|
||||
return jax.random.uniform(randkey, (6,), minval=-1.0, maxval=1.0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pipeline = Pipeline(
|
||||
algorithm=NEAT(
|
||||
pop_size=1000,
|
||||
species_size=20,
|
||||
survival_threshold=0.1,
|
||||
compatibility_threshold=1.0,
|
||||
genome=DefaultGenome(
|
||||
max_nodes=100,
|
||||
max_conns=200,
|
||||
num_inputs=17,
|
||||
num_outputs=6,
|
||||
init_hidden_layers=(),
|
||||
node_gene=BiasNode(
|
||||
activation_options=Act.tanh,
|
||||
aggregation_options=Agg.sum,
|
||||
),
|
||||
output_transform=Act.standard_tanh,
|
||||
),
|
||||
),
|
||||
problem=BraxEnv(
|
||||
env_name="halfcheetah",
|
||||
max_step=1000,
|
||||
obs_normalization=True,
|
||||
sample_episodes=1000,
|
||||
sample_policy=random_sample_policy,
|
||||
),
|
||||
seed=42,
|
||||
generation_limit=100,
|
||||
fitness_target=8000,
|
||||
)
|
||||
|
||||
# initialize state
|
||||
state = pipeline.setup()
|
||||
# print(state)
|
||||
# run until terminate
|
||||
state, best = pipeline.auto_run(state)
|
||||
@@ -1,37 +0,0 @@
|
||||
from pipeline import Pipeline
|
||||
from algorithm.neat import *
|
||||
|
||||
from problem.rl_env import BraxEnv
|
||||
from tensorneat.common import Act
|
||||
|
||||
if __name__ == "__main__":
|
||||
pipeline = Pipeline(
|
||||
algorithm=NEAT(
|
||||
species=DefaultSpecies(
|
||||
genome=DefaultGenome(
|
||||
num_inputs=11,
|
||||
num_outputs=2,
|
||||
max_nodes=50,
|
||||
max_conns=100,
|
||||
node_gene=DefaultNodeGene(
|
||||
activation_options=(Act.tanh,),
|
||||
activation_default=Act.tanh,
|
||||
),
|
||||
output_transform=Act.tanh,
|
||||
),
|
||||
pop_size=100,
|
||||
species_size=10,
|
||||
),
|
||||
),
|
||||
problem=BraxEnv(
|
||||
env_name="reacher",
|
||||
),
|
||||
generation_limit=10000,
|
||||
fitness_target=5000,
|
||||
)
|
||||
|
||||
# initialize state
|
||||
state = pipeline.setup()
|
||||
# print(state)
|
||||
# run until terminate
|
||||
state, best = pipeline.auto_run(state)
|
||||
@@ -1,19 +0,0 @@
|
||||
import jax
|
||||
from problem.rl_env import BraxEnv
|
||||
|
||||
|
||||
def random_policy(randkey, forward_func, obs):
|
||||
return jax.random.uniform(randkey, (6,), minval=-1, maxval=1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
problem = BraxEnv(env_name="walker2d", max_step=1000, action_policy=random_policy)
|
||||
state = problem.setup()
|
||||
randkey = jax.random.key(0)
|
||||
problem.show(
|
||||
state,
|
||||
randkey,
|
||||
act_func=lambda state, params, obs: obs,
|
||||
params=None,
|
||||
save_path="walker2d_random_policy",
|
||||
)
|
||||
@@ -9,7 +9,7 @@ import jax, jax.numpy as jnp
|
||||
|
||||
|
||||
def random_sample_policy(randkey, obs):
|
||||
return jax.random.uniform(randkey, (6,))
|
||||
return jax.random.uniform(randkey, (6,), minval=-1.0, maxval=1.0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user