-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
53 lines (41 loc) · 1.17 KB
/
main.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from evox import workflows, problems
import algorithms
from evox.monitors import PopMonitor
from evox.metrics import IGD
import jax
import jax.numpy as jnp
import numpy as np
import time
def run_moea(algorithm, key):
monitor = PopMonitor()
problem = problems.numerical.DTLZ2(m=3)
workflow = workflows.StdWorkflow(
algorithm=algorithm,
problem=problem,
monitor=monitor,
)
state = workflow.init(key)
true_pf = problem.pf()
igd = IGD(true_pf)
for i in range(100):
key, subkey = jax.random.split(key)
state = workflow.step(state)
fit = state.get_child_state("algorithm").fitness
non_nan_rows = fit[~np.isnan(fit).any(axis=1)]
print(f'Generation {i+1}, IGD: {igd(non_nan_rows)}')
fig = monitor.plot()
fig.show()
if __name__ == '__main__':
lb = jnp.full(shape=(12,), fill_value=0)
ub = jnp.full(shape=(12,), fill_value=1)
algorithm = algorithms.TensorRVEA(
lb=lb,
ub=ub,
n_objs=3,
pop_size=100,
)
key = jax.random.PRNGKey(42)
start = time.time()
run_moea(algorithm, key)
end = time.time()
print(f"time: {end-start}s")