Skip to content

Commit

Permalink
add algorithm clpso
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoyuWang141 committed Jul 24, 2023
1 parent 8ab1abb commit 73f7be0
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions examples/algorithm/so/pso_variants/eg_clpso.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from evox import algorithms, problems, pipelines, monitors
import jax
import jax.numpy as jnp

algorithm = algorithms.so.pso_vatients.CLPSO(
lb=jnp.full(shape=(10,), fill_value=-32),
ub=jnp.full(shape=(10,), fill_value=32),
pop_size=100,
inertia_weight=0.4,
const_coefficient=0.6,
learning_probability=jnp.full(shape=(100,), fill_value=0.5),
)

problem = problems.classic.Ackley()

monitor = monitors.FitnessMonitor()

# create a pipeline

pipeline = pipelines.StdPipeline(
algorithm=algorithm,
problem=problem,
fitness_transform=monitor.update,
)

# init the pipeline
key = jax.random.PRNGKey(42)
state = pipeline.init(key)

# run the pipeline for 100 steps
for i in range(100):
state = pipeline.step(state)
print(monitor.get_min_fitness())

0 comments on commit 73f7be0

Please sign in to comment.