Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MOO mode for 1+1 + fix DE uniform sampling #1058

Merged
merged 17 commits into from
Feb 23, 2021
Prev Previous commit
Next Next commit
skip
jrapin committed Feb 23, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit e4d217365d07bb06676deb8ac07e8fb51cddc3bc
8 changes: 6 additions & 2 deletions nevergrad/functions/images/core.py
Original file line number Diff line number Diff line change
@@ -3,10 +3,11 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

import cv2
from pathlib import Path
import os
import itertools
from pathlib import Path

import cv2
import numpy as np
import PIL.Image
import torch.nn as nn
@@ -17,6 +18,7 @@

import nevergrad as ng
import nevergrad.common.typing as tp
from nevergrad.common import errors
from .. import base
from . import imagelosses

@@ -259,6 +261,8 @@ def __init__(
if not torch.cuda.is_available():
use_gpu = False
# Storing high level information..
if os.environ("CIRCLECI", False):
raise errors.UnsupportedExperiment("ImageFromPGAN is not well supported in CircleCI")
self.pgan_model = torch.hub.load(
"facebookresearch/pytorch_GAN_zoo:hub",
"PGAN",
7 changes: 5 additions & 2 deletions nevergrad/optimization/differentialevolution.py
Original file line number Diff line number Diff line change
@@ -119,8 +119,11 @@ def _internal_ask_candidate(self) -> p.Parameter:
if self.sampler is None and init not in ["gaussian", "parametrization"]:
assert init in ["LHS", "QR"]
self.sampler = oneshot.SamplingSearch(
sampler=init if init == "LHS" else "Hammersley", scrambled=init == "QR"
)(self.parametrization, budget=self.llambda)
sampler=init if init == "LHS" else "Hammersley", scrambled=init == "QR", scale=self.scale
)(
self.parametrization,
budget=self.llambda,
)
if init == "parametrization":
candidate = self.parametrization.sample()
elif self.sampler is not None:
8 changes: 3 additions & 5 deletions nevergrad/optimization/oneshot.py
Original file line number Diff line number Diff line change
@@ -75,14 +75,12 @@ def avg_of_k_best(archive: utils.Archive[utils.MultiValue], method: str = "dimfo
raise ValueError(f"{method} not implemented as a method for choosing k in avg_of_k_best.")
k = 1 if k < 1 else int(k)
# Wasted time.
first_k_individuals = [
k for k in sorted(items, key=lambda indiv: archive[indiv[0]].get_estimation("pessimistic"))[:k]
]
first_k_individuals = sorted(items, key=lambda indiv: archive[indiv[0]].get_estimation("pessimistic"))[:k]
assert len(first_k_individuals) == k
return np.array(sum(p[0] for p in first_k_individuals) / k)


# # # # # classes of optimizers # # # # #
# # # # # classes of optimizers # # # # #


class OneShotOptimizer(base.Optimizer):
@@ -99,7 +97,7 @@ class OneShotOptimizer(base.Optimizer):
# - Some variants use a rescaling depending on the budget and the dimension.


# # # # # One-shot optimizers: all fitness evaluations are in parallel. # # # # #
# # # # # One-shot optimizers: all fitness evaluations are in parallel. # # # # #


# pylint: disable=too-many-arguments,too-many-instance-attributes