|
24 | 24 | Learner1D,
|
25 | 25 | Learner2D,
|
26 | 26 | LearnerND,
|
| 27 | + SequenceLearner, |
27 | 28 | )
|
28 | 29 | from adaptive.runner import simple
|
29 | 30 |
|
@@ -116,26 +117,30 @@ def quadratic(x, m: uniform(0, 10), b: uniform(0, 1)):
|
116 | 117 |
|
117 | 118 |
|
118 | 119 | @learn_with(Learner1D, bounds=(-1, 1))
|
| 120 | +@learn_with(SequenceLearner, sequence=np.linspace(-1, 1, 201)) |
119 | 121 | def linear_with_peak(x, d: uniform(-1, 1)):
|
120 | 122 | a = 0.01
|
121 | 123 | return x + a ** 2 / (a ** 2 + (x - d) ** 2)
|
122 | 124 |
|
123 | 125 |
|
124 | 126 | @learn_with(LearnerND, bounds=((-1, 1), (-1, 1)))
|
125 | 127 | @learn_with(Learner2D, bounds=((-1, 1), (-1, 1)))
|
| 128 | +@learn_with(SequenceLearner, sequence=np.random.rand(1000, 2)) |
126 | 129 | def ring_of_fire(xy, d: uniform(0.2, 1)):
|
127 | 130 | a = 0.2
|
128 | 131 | x, y = xy
|
129 | 132 | return x + math.exp(-(x ** 2 + y ** 2 - d ** 2) ** 2 / a ** 4)
|
130 | 133 |
|
131 | 134 |
|
132 | 135 | @learn_with(LearnerND, bounds=((-1, 1), (-1, 1), (-1, 1)))
|
| 136 | +@learn_with(SequenceLearner, sequence=np.random.rand(1000, 3)) |
133 | 137 | def sphere_of_fire(xyz, d: uniform(0.2, 1)):
|
134 | 138 | a = 0.2
|
135 | 139 | x, y, z = xyz
|
136 | 140 | return x + math.exp(-(x ** 2 + y ** 2 + z ** 2 - d ** 2) ** 2 / a ** 4) + z ** 2
|
137 | 141 |
|
138 | 142 |
|
| 143 | +@learn_with(SequenceLearner, sequence=range(1000)) |
139 | 144 | @learn_with(AverageLearner, rtol=1)
|
140 | 145 | def gaussian(n):
|
141 | 146 | return random.gauss(0, 1)
|
@@ -247,7 +252,7 @@ def f(x):
|
247 | 252 | simple(learner, goal=lambda l: l.npoints > 10)
|
248 | 253 |
|
249 | 254 |
|
250 |
| -@run_with(Learner1D, Learner2D, LearnerND) |
| 255 | +@run_with(Learner1D, Learner2D, LearnerND, SequenceLearner) |
251 | 256 | def test_adding_existing_data_is_idempotent(learner_type, f, learner_kwargs):
|
252 | 257 | """Adding already existing data is an idempotent operation.
|
253 | 258 |
|
@@ -283,7 +288,7 @@ def test_adding_existing_data_is_idempotent(learner_type, f, learner_kwargs):
|
283 | 288 |
|
284 | 289 | # XXX: This *should* pass (https://github.com/python-adaptive/adaptive/issues/55)
|
285 | 290 | # but we xfail it now, as Learner2D will be deprecated anyway
|
286 |
| -@run_with(Learner1D, xfail(Learner2D), LearnerND, AverageLearner) |
| 291 | +@run_with(Learner1D, xfail(Learner2D), LearnerND, AverageLearner, SequenceLearner) |
287 | 292 | def test_adding_non_chosen_data(learner_type, f, learner_kwargs):
|
288 | 293 | """Adding data for a point that was not returned by 'ask'."""
|
289 | 294 | # XXX: learner, control and bounds are not defined
|
@@ -429,7 +434,12 @@ def test_learner_performance_is_invariant_under_scaling(
|
429 | 434 |
|
430 | 435 |
|
431 | 436 | @run_with(
|
432 |
| - Learner1D, Learner2D, LearnerND, AverageLearner, with_all_loss_functions=False |
| 437 | + Learner1D, |
| 438 | + Learner2D, |
| 439 | + LearnerND, |
| 440 | + AverageLearner, |
| 441 | + SequenceLearner, |
| 442 | + with_all_loss_functions=False, |
433 | 443 | )
|
434 | 444 | def test_balancing_learner(learner_type, f, learner_kwargs):
|
435 | 445 | """Test if the BalancingLearner works with the different types of learners."""
|
@@ -474,6 +484,7 @@ def test_balancing_learner(learner_type, f, learner_kwargs):
|
474 | 484 | AverageLearner,
|
475 | 485 | maybe_skip(SKOptLearner),
|
476 | 486 | IntegratorLearner,
|
| 487 | + SequenceLearner, |
477 | 488 | with_all_loss_functions=False,
|
478 | 489 | )
|
479 | 490 | def test_saving(learner_type, f, learner_kwargs):
|
@@ -504,6 +515,7 @@ def test_saving(learner_type, f, learner_kwargs):
|
504 | 515 | AverageLearner,
|
505 | 516 | maybe_skip(SKOptLearner),
|
506 | 517 | IntegratorLearner,
|
| 518 | + SequenceLearner, |
507 | 519 | with_all_loss_functions=False,
|
508 | 520 | )
|
509 | 521 | def test_saving_of_balancing_learner(learner_type, f, learner_kwargs):
|
@@ -541,6 +553,7 @@ def fname(learner):
|
541 | 553 | AverageLearner,
|
542 | 554 | maybe_skip(SKOptLearner),
|
543 | 555 | IntegratorLearner,
|
| 556 | + SequenceLearner, |
544 | 557 | with_all_loss_functions=False,
|
545 | 558 | )
|
546 | 559 | def test_saving_with_datasaver(learner_type, f, learner_kwargs):
|
|
0 commit comments