Skip to content

Commit ef227b8

Browse files
committed
test all the different loss functions in each test
1 parent d82fbae commit ef227b8

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

adaptive/learner/learner1D.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def triangle_loss(xs, ys):
123123

124124

125125
def curvature_loss_function(area_factor=1, euclid_factor=0.02, horizontal_factor=0.02):
126+
# XXX: add a doc-string
126127
@uses_nth_neighbors(1)
127128
def curvature_loss(xs, ys):
128129
xs_middle = xs[1:3]

adaptive/tests/test_learners.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
import pytest
1616
import scipy.spatial
1717

18-
from ..learner import (AverageLearner, BalancingLearner, DataSaver,
18+
import adaptive
19+
from adaptive.learner import (AverageLearner, BalancingLearner, DataSaver,
1920
IntegratorLearner, Learner1D, Learner2D, LearnerND)
20-
from ..runner import simple
21+
from adaptive.runner import simple
2122

2223

2324
try:
2425
import skopt
25-
from ..learner import SKOptLearner
26+
from adaptive.learner import SKOptLearner
2627
except ModuleNotFoundError:
2728
SKOptLearner = None
2829

@@ -75,26 +76,37 @@ def maybe_skip(learner):
7576
# returns a random value for that parameter.
7677

7778

78-
@learn_with(Learner1D, bounds=(-1, 1))
79+
@learn_with(Learner1D, bounds=(-1, 1), loss_per_interval=adaptive.learner.learner1D.default_loss)
80+
@learn_with(Learner1D, bounds=(-1, 1), loss_per_interval=adaptive.learner.learner1D.uniform_loss)
81+
@learn_with(Learner1D, bounds=(-1, 1), loss_per_interval=adaptive.learner.learner1D.curvature_loss_function())
7982
def quadratic(x, m: uniform(0, 10), b: uniform(0, 1)):
8083
return m * x**2 + b
8184

8285

83-
@learn_with(Learner1D, bounds=(-1, 1))
86+
@learn_with(Learner1D, bounds=(-1, 1), loss_per_interval=adaptive.learner.learner1D.default_loss)
87+
@learn_with(Learner1D, bounds=(-1, 1), loss_per_interval=adaptive.learner.learner1D.uniform_loss)
88+
@learn_with(Learner1D, bounds=(-1, 1), loss_per_interval=adaptive.learner.learner1D.curvature_loss_function())
8489
def linear_with_peak(x, d: uniform(-1, 1)):
8590
a = 0.01
8691
return x + a**2 / (a**2 + (x - d)**2)
8792

8893

89-
@learn_with(LearnerND, bounds=((-1, 1), (-1, 1)))
90-
@learn_with(Learner2D, bounds=((-1, 1), (-1, 1)))
94+
@learn_with(LearnerND, bounds=((-1, 1), (-1, 1)), loss_per_simplex=adaptive.learner.learnerND.default_loss)
95+
@learn_with(LearnerND, bounds=((-1, 1), (-1, 1)), loss_per_simplex=adaptive.learner.learnerND.std_loss)
96+
@learn_with(LearnerND, bounds=((-1, 1), (-1, 1)), loss_per_simplex=adaptive.learner.learnerND.uniform_loss)
97+
@learn_with(Learner2D, bounds=((-1, 1), (-1, 1)), loss_per_triangle=adaptive.learner.learner2D.default_loss)
98+
@learn_with(Learner2D, bounds=((-1, 1), (-1, 1)), loss_per_triangle=adaptive.learner.learner2D.uniform_loss)
99+
@learn_with(Learner2D, bounds=((-1, 1), (-1, 1)), loss_per_triangle=adaptive.learner.learner2D.minimize_triangle_surface_loss)
100+
@learn_with(Learner2D, bounds=((-1, 1), (-1, 1)), loss_per_triangle=adaptive.learner.learner2D.resolution_loss_function())
91101
def ring_of_fire(xy, d: uniform(0.2, 1)):
92102
a = 0.2
93103
x, y = xy
94104
return x + math.exp(-(x**2 + y**2 - d**2)**2 / a**4)
95105

96106

97-
@learn_with(LearnerND, bounds=((-1, 1), (-1, 1), (-1, 1)))
107+
@learn_with(LearnerND, bounds=((-1, 1), (-1, 1), (-1, 1)), loss_per_simplex=adaptive.learner.learnerND.default_loss)
108+
@learn_with(LearnerND, bounds=((-1, 1), (-1, 1), (-1, 1)), loss_per_simplex=adaptive.learner.learnerND.std_loss)
109+
@learn_with(LearnerND, bounds=((-1, 1), (-1, 1), (-1, 1)), loss_per_simplex=adaptive.learner.learnerND.uniform_loss)
98110
def sphere_of_fire(xyz, d: uniform(0.2, 1)):
99111
a = 0.2
100112
x, y, z = xyz

0 commit comments

Comments
 (0)