I was trying to optimize the following example function.
evaluate_fcmaes.py :
import sys
from fcmaes import cmaescpp
from numpy.random import Generator, PCG64
from scipy.optimize import Bounds
import numpy as np
def cost_nse(obs, sim):
return 1.0 - np.sum((obs - sim) ** 2.0) / np.sum((obs - np.mean(obs)) ** 2.0)
def costhand(param_scalar):
sim = []
for p_val in param_scalar:
sim.append(p_val * 0.1 + p_val * 0.2 + p_val * 0.3)
obs = [0.25, 0.11, 0.76, 0.45, 0.98, 1.2]
nse = cost_nse(np.array(obs), np.array(sim))
return 1.0 - (1.0 / (2.0 - nse))
def run_cmaes():
bnds = Bounds([0.0] * 6, [1.0] * 6)
WORKERS = sys.argv[1]
ret = cmaescpp.minimize(
fun=costhand,
bounds=bnds,
x0=[0.5] * 6,
input_sigma=0.1,
popsize=1000,
max_evaluations=20000,
stop_fitness=1e-6,
rg=Generator(PCG64(43)),
workers=WORKERS,
)
if I set the workers to None, and run python -mtimeit -s 'import evaluate_fcmaes' 'evaluate_fcmaes.run_cmaes()' None, I am getting: 2000 loops, best of 5: 106 usec per loop
if I set the workers to 6, and run python -mtimeit -s 'import evaluate_fcmaes' 'evaluate_fcmaes.run_cmaes()' 6, I am getting: 2000 loops, best of 5: 107 usec per loop
Why I am not getting a significant reduction in time when using more workers? am I using cmaescpp correctly if I want to parallel evaluate costhand and optimize its parameters?
I was trying to optimize the following example function.
evaluate_fcmaes.py :
if I set the
workerstoNone, and runpython -mtimeit -s 'import evaluate_fcmaes' 'evaluate_fcmaes.run_cmaes()' None, I am getting:2000 loops, best of 5: 106 usec per loopif I set the
workersto6, and runpython -mtimeit -s 'import evaluate_fcmaes' 'evaluate_fcmaes.run_cmaes()' 6, I am getting:2000 loops, best of 5: 107 usec per loopWhy I am not getting a significant reduction in time when using more workers? am I using
cmaescppcorrectly if I want to parallel evaluatecosthandand optimize its parameters?