Skip to content

Commit

Permalink
adding_plotting_curve (#1564)
Browse files Browse the repository at this point in the history
* adding_plotting_curve

* addgomea (#1565)

* addgomea

* fix_missing_import

* fix_missing_import

* fix_missing_import

* fix_missing_import

* fix_missing_import

* fix_missing_import

* Update test_optimizerlib.py

* fix

* fix

* fix
  • Loading branch information
teytaud authored Oct 10, 2023
1 parent a4016ae commit ff30e20
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 4 deletions.
7 changes: 7 additions & 0 deletions examples/example_for_plotting_optim_curve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import nevergrad as ng

def f(x):
return sum((x-1.234)**2)
opt = ng.optimizers.TwoPointsDE(3, 500)
opt.minimize(f)
print(opt.optim_curve)
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[mypy]

#[mypy-scipy.*,requests,smac,smac.*,pandas,compiler_gym,compiler_gym.*,gym,gym.*,gym_anm,matplotlib.*,pytest,cma,bayes_opt.*,torchvision.models,torch.*,mpl_toolkits.*,fcmaes.*,tqdm,pillow,PIL,PIL.Image,sklearn.*,pyomo.*,pyproj,IOHexperimenter.*,tensorflow,koncept.models,cv2,imquality,imquality.brisque,lpips,mixsimulator.*,networkx.*,cdt.*,]
[mypy-scipy.*,requests,pandas,compiler_gym,compiler_gym.*,gym_anm,matplotlib.*,pytest,cma,bayes_opt.*,torchvision.models,torch.*,mpl_toolkits.*,fcmaes.*,tqdm,pillow,PIL,PIL.Image,sklearn.*,pyomo.*,pyproj,IOHexperimenter.*,tensorflow,koncept.models,cv2,imquality,imquality.brisque,lpips,mixsimulator.*,networkx.*,cdt.*,pymoo,pymoo.*,bayes_optim.*,olympus.*,pymoo,pymoo.*,pybullet,pybullet_envs,pybulletgym,pyvirtualdisplay,nlopt,aquacrop.*]
[mypy-scipy.*,requests,pandas,compiler_gym,compiler_gym.*,gym_anm,matplotlib.*,pytest,cma,bayes_opt.*,torchvision.models,torch.*,mpl_toolkits.*,fcmaes.*,tqdm,pillow,PIL,PIL.Image,sklearn.*,pyomo.*,pyproj,IOHexperimenter.*,tensorflow,koncept.models,cv2,imquality,imquality.brisque,lpips,mixsimulator.*,networkx.*,cdt.*,pymoo,pymoo.*,bayes_optim.*,olympus.*,pymoo,pymoo.*,pybullet,pybullet_envs,pybulletgym,pyvirtualdisplay,nlopt,aquacrop.*,gomea]
ignore_missing_imports = True

[mypy-nevergrad.functions.rl.*,torchvision,torchvision.*,nevergrad.functions.games.*,nevergrad.functions.multiobjective.pyhv,nevergrad.optimization.test_doc,nevergrad.functions.gym.multigym,nevergrad.functions.gym.tuple_gym_env,nevergrad.common.sphere,nevergrad.examples.*]
Expand Down
2 changes: 1 addition & 1 deletion nevergrad/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
__all__ = ["optimizers", "families", "callbacks", "p", "typing", "errors", "ops"]


__version__ = "0.14.0"
__version__ = "1.0.0"
2 changes: 1 addition & 1 deletion nevergrad/common/sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ def quasi_randomize(pointset, method):
if len(shape) > 1 and shape[0] > 5:
x = dispersion(n, shape, conv=[int(s / 3) for s in list(shape)[:-1]])
else:
x = rs_metric_all(n, shape)
x = rs_ng_DiagonalCMA(n, shape)
else:
x = get_a_point_set(n, shape, method)
x = normalize(x)
Expand Down
5 changes: 5 additions & 0 deletions nevergrad/optimization/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def __init__(
# you can also replace or reinitialize this random state
self.num_workers = int(num_workers)
self.budget = budget
self.optim_curve: tp.List[tp.Any] = []

# How do we deal with cheap constraints i.e. constraints which are fast and use low resources and easy ?
# True ==> we penalize them (infinite values for candidates which violate the constraint).
Expand Down Expand Up @@ -348,6 +349,10 @@ def tell(
raise TypeError(
f'"tell" method only supports float values but the passed loss was: {loss} (type: {type(loss)}.'
)
if isinstance(loss, float) and (
len(self.optim_curve) == 0 or self.num_tell > self.optim_curve[-1][0] * 1.1
):
self.optim_curve += [(self.num_tell, loss)]
# check Parameter
if not isinstance(candidate, p.Parameter):
raise TypeError(
Expand Down
32 changes: 32 additions & 0 deletions nevergrad/optimization/recastlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ def __init__(
method
in [
"CmaFmin2",
"gomea",
"gomeablock",
"gomeatree",
"SMAC3",
"BFGS",
"LBFGSB",
Expand Down Expand Up @@ -362,6 +365,32 @@ def smac2_obj(p, seed: int = 0):
# best_res = cost
# best_x = weakself._normalizer.backward(np.asarray(x, dtype=float))
#

elif "gomea" in weakself.method:
import gomea

class gomea_function(gomea.fitness.BBOFitnessFunctionRealValued):
def objective_function(self, objective_index, data): # type: ignore
if weakself._normalizer is not None:
data = weakself._normalizer.backward(np.asarray(data, dtype=np.float32))
return objective_function(data)

gomea_f = gomea_function(weakself.dimension)
lm = {
"gomea": gomea.linkage.Univariate(),
"gomeablock": gomea.linkage.BlockMarginalProduct(2),
"gomeatree": gomea.linkage.LinkageTree("NMI".encode(), True, 0),
}[weakself.method]
rvgom = gomea.RealValuedGOMEA(
fitness=gomea_f,
linkage_model=lm,
lower_init_range=0.0,
upper_init_range=1.0,
max_number_of_evaluations=budget,
)
rvgom.run()
best_x = gomea_f.best_x

elif weakself.method == "CmaFmin2":
import cma # type: ignore

Expand Down Expand Up @@ -469,6 +498,9 @@ def __init__(self, *, method: str = "Nelder-Mead", random_restart: bool = False)
BOBYQA = NonObjectOptimizer(method="BOBYQA").set_name("BOBYQA", register=True)
NelderMead = NonObjectOptimizer(method="Nelder-Mead").set_name("NelderMead", register=True)
CmaFmin2 = NonObjectOptimizer(method="CmaFmin2").set_name("CmaFmin2", register=True)
GOMEA = NonObjectOptimizer(method="gomea").set_name("GOMEA", register=True)
GOMEABlock = NonObjectOptimizer(method="gomeablock").set_name("GOMEABlock", register=True)
GOMEATree = NonObjectOptimizer(method="gomeatree").set_name("GOMEATree", register=True)
# NLOPT = NonObjectOptimizer(method="NLOPT").set_name("NLOPT", register=True)
Powell = NonObjectOptimizer(method="Powell").set_name("Powell", register=True)
RPowell = NonObjectOptimizer(method="Powell", random_restart=True).set_name("RPowell", register=True)
Expand Down
5 changes: 5 additions & 0 deletions nevergrad/optimization/test_optimizerlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ def check_optimizer(
"NLOPT_GN_CRS2_LM",
"NLOPT_GN_ISRES",
"NLOPT_GN_ESCH",
"GOMEABlock",
"GOMEA",
"GOMEATree",
]


Expand Down Expand Up @@ -299,6 +302,7 @@ def test_optimizers_minimal(name: str) -> None:
"CMAbounded",
"Tiny",
"iscrete",
"GOMEA",
"para",
"SPSA",
"EDA",
Expand All @@ -314,6 +318,7 @@ def test_optimizers_minimal(name: str) -> None:
"Small",
"small",
"Chain",
"Tree",
"Mix",
"Micro",
"Naive",
Expand Down
3 changes: 2 additions & 1 deletion nevergrad/optimization/test_suggest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

def suggestable(name: str) -> bool:
# Some methods are not good with suggestions.
keywords = ["TBPSA", "BO", "EMNA", "EDA", "BO", "Stupid", "Pymoo"]
keywords = ["TBPSA", "BO", "EMNA", "EDA", "BO", "Stupid", "Pymoo", "GOMEA"]
return not any(x in name for x in keywords)


Expand Down Expand Up @@ -75,6 +75,7 @@ def good_at_suggest(name: str) -> bool:
"Multi",
"Anisotropic",
"BSO",
"GOMEA",
"Sparse",
"Adaptive",
"Doerr",
Expand Down
1 change: 1 addition & 0 deletions requirements/bench.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ pytest-circleci-parallelized
Py-BOBYQA>=1.2
ax-platform
loguru # for fcmaes
gomea

0 comments on commit ff30e20

Please sign in to comment.