'Constraints for objective function in Pymoo
I have a dataset when i used lstm as a metamodel in pymoo using nsga2. I have 4 objective functions where some are negative values and some are positive values. The goal is to bring the 4 objective functions as close to 0 as possible. However I'm not sure how what to change for pymoo. My code is below. Thank you
...
class MyProblem(Problem):
def __init__(self):
super().__init__(n_var=6,
n_obj=4,
xl=np.array([xl0[i],xl1[i],xl2[i],np.min(xl3),xl4[i],xl5[i],np.min(xl6)]),
xu=np.array([xl0[i]+0.01,xl1[i]+0.01,xl2[i]+0.01,np.max(xl3),xl4[i]+0.01,xl5[i]+0.01,np.max(xl6)]))
def _evaluate(self, X, out, *args, **kwargs):
f1 = model_o1.predict(X.reshape(X.shape[0], 1, X.shape[1]))
f2 = model_o2.predict(X.reshape(X.shape[0], 1, X.shape[1]))
f3 = model_o3.predict(X.reshape(X.shape[0], 1, X.shape[1]))
f4 = model_o4.predict(X.reshape(X.shape[0], 1, X.shape[1]))
out["F"] = np.column_stack([f1, f2, f3,f4])
vectorized_problem = MyProblem()
res_interval = []
algorithm = NSGA2(
pop_size=200,
n_offsprings=200,
sampling=get_sampling("real_random"),
crossover=get_crossover("real_sbx", prob=0.8, eta=15),
mutation=get_mutation("real_pm", eta=20),
eliminate_duplicates=True
)
termination1 = MultiObjectiveDefaultTermination(
x_tol=1e-8,
cv_tol=1e-6,
f_tol=0.0025,
nth_gen=5,
n_last=30,
n_max_gen=500,
n_max_evals=100000)
res = minimize(vectorized_problem,
algorithm,
termination1,
seed=1,
save_history=False,
verbose=False)
...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
