Skip to content

Commit f0c55a9

Browse files
committed
Make default optimizer for acv use differentialevolution to get initial guess
1 parent 9f6762d commit f0c55a9

File tree

16 files changed

+69
-42
lines changed

16 files changed

+69
-42
lines changed

environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ dependencies:
1919
- networkx
2020
- pytorch
2121
- numba
22+
- cvxpy
2223
# make html in docs folder
2324
- sphinx
2425
- sphinx-gallery

environment_w_extras.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ dependencies:
1919
- networkx
2020
- pytorch
2121
- numba
22+
- cvxpy
2223
# gpu support
2324
- torchvision
2425
- torchaudio

examples/expdesign/plot_bayesoed4params.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138

139139
# %%
140140
# Plot the OED
141-
# -----------
141+
# ------------
142142
axs = plt.subplots(1, 2, figsize=(8, 6), sharey=True)[1]
143143
# Reshape weights so that each row correspond to one of the OED states
144144
design_weights = design_weights.reshape((2, -1))

examples/expdesign/plot_bayesoed4pred.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@
170170

171171
# %%
172172
# Plot the OED
173-
# -----------
173+
# ------------
174174
fig, axs = plt.subplots(1, 2, figsize=(8, 6), sharey=True)
175175
# Reshape weights so that each row correspond to one of the OED states
176176
design_weights = design_weights.reshape((2, -1))

examples/interface/plot_model_timing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
r"""
22
Model Timing
33
------------
4-
It is often useful to be able to track the time needed to evaluate a function.
4+
It is often useful to be able to track the time needed to evaluate a function.
55
This tutorial demonstrats how to use model to time function calls.
66
All model class can track time.
77

examples/surrogates/plot_barycentric_interpolation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
marginals = [stats.uniform(-1, 2), stats.uniform(-1, 2)]
2828
quad_rules_1d = [GaussQuadratureRule(marginal) for marginal in marginals]
2929
bases_1d = [
30-
UnivariateLagrangeBasis(quad_rule, 1) for quad_rule in quad_rules_1d
30+
UnivariateLagrangeBasis(quad_rule, 2) for quad_rule in quad_rules_1d
3131
]
3232

3333

pyapprox/multifidelity/acv.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,12 +1364,16 @@ def plot_recursion_dag(self, ax):
13641364
# partition_ratios.grad.zero_()
13651365
# return val.item(), grad
13661366

1367-
def get_npartition_bounds(self) -> Array:
1367+
def get_npartition_bounds(self, total_cost: float) -> Array:
13681368
nunknowns = self._npartitions - 1
1369+
# tighter bounds helps global optimizer so insted of using inf,
1370+
# set upperbounds to be maximum number of samples if all samples
1371+
# were allocated to a single model, for each model
13691372
bounds = self._bkd.stack(
13701373
(
13711374
self._bkd.full((nunknowns,), self._npartitions_lower_bound),
1372-
self._bkd.full((nunknowns,), np.inf),
1375+
# self._bkd.full((nunknowns,), np.inf),
1376+
total_cost / self._costs[1:],
13731377
),
13741378
axis=1,
13751379
)
@@ -1384,9 +1388,17 @@ def get_default_optimizer(self) -> Optimizer:
13841388
# init_gen.set_bounds(self.get_npartition_bounds())
13851389
# optimizer = ConstrainedMultiStartOptimizer(local_optimizer)
13861390
# optimizer.set_initial_iterate_generator(init_gen)
1387-
global_optimizer = ScipyConstrainedNelderMeadOptimizer(
1388-
opts={"maxiter": 500}
1391+
# global_optimizer = ScipyConstrainedNelderMeadOptimizer(
1392+
# opts={"maxiter": 500}
1393+
# )
1394+
from pyapprox.optimization.scipy import (
1395+
ScipyConstrainedDifferentialEvolutionOptimizer,
1396+
)
1397+
1398+
global_optimizer = ScipyConstrainedDifferentialEvolutionOptimizer(
1399+
opts={"maxiter": 3}
13891400
)
1401+
13901402
local_optimizer = ScipyConstrainedOptimizer()
13911403
optimizer = ChainedOptimizer(global_optimizer, local_optimizer)
13921404
optimizer.set_verbosity(0)
@@ -1415,7 +1427,7 @@ def _allocate_samples_minimize(
14151427
self._optimizer.set_objective_function(objective)
14161428
constraints = [ACVPartitionConstraint(self, target_cost)]
14171429
self._optimizer.set_constraints(constraints)
1418-
self._optimizer.set_bounds(self.get_npartition_bounds())
1430+
self._optimizer.set_bounds(self.get_npartition_bounds(target_cost))
14191431
init_iterate = self._bkd.full((self._nmodels - 1, 1), 1.0)
14201432
result = self._optimizer.minimize(init_iterate)
14211433
return result

pyapprox/multifidelity/tests/test_acv.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -724,17 +724,6 @@ def test_best_model_subset_estimator(self):
724724
target_cost = 10
725725
est._save_candidate_estimators = True
726726
est.allocate_samples(target_cost)
727-
# {
728-
# "verbosity": 1,
729-
# "nprocs": 1,
730-
# "scaling": 1,
731-
# "init_guess": {
732-
# "disp": True,
733-
# "maxiter": 300,
734-
# "lower_bound": 1e-10,
735-
# },
736-
# },
737-
738727
criteria = bkd.array(
739728
[e[0]._optimized_criteria for e in est._candidate_estimators]
740729
)

pyapprox/surrogates/affine/linearsystemsolvers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,8 @@ class BasisPursuitDensoisingCVXRegressionSolver(
13581358
CVXOPTOptionsMixin, LinearSystemSolver
13591359
):
13601360
def __init__(self, penalty: float, backend: BackendMixin = NumpyMixin):
1361+
if not package_available("cvxopt"):
1362+
raise ImportError("cvxopt is not installed")
13611363
self._penalty = penalty
13621364
super().__init__(backend)
13631365

pyapprox/surrogates/affine/tests/test_linsolvers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ def test_linearly_constrained_lstsq_solver(self):
148148
assert bkd.allclose(C @ coef, d, atol=1e-15)
149149
assert bkd.allclose(A @ coef, y, atol=1e-1)
150150

151+
@unittest.skipIf(not package_available("cvxpy"), "cvxpy not installed")
151152
def test_quantile_regression(self):
152153
bkd = self.get_backend()
153154
quantile = 0.5

0 commit comments

Comments
 (0)