Skip to content

Commit 49d67d7

Browse files
committed
rename 'function_values' to 'data' because its more obvious
Because data is now in the 'BaseLearner'
1 parent 8816287 commit 49d67d7

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

adaptive/learner/learner1D.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from ..utils import cache_latest
1616

1717

18-
def uniform_loss(interval, scale, function_values, neighbors):
18+
def uniform_loss(interval, scale, data, neighbors):
1919
"""Loss function that samples the domain uniformly.
2020
2121
Works with `~adaptive.Learner1D` only.
@@ -36,15 +36,15 @@ def uniform_loss(interval, scale, function_values, neighbors):
3636
return dx
3737

3838

39-
def default_loss(interval, scale, function_values, neighbors):
39+
def default_loss(interval, scale, data, neighbors):
4040
"""Calculate loss on a single interval.
4141
4242
Currently returns the rescaled length of the interval. If one of the
4343
y-values is missing, returns 0 (so the intervals with missing data are
4444
never touched. This behavior should be improved later.
4545
"""
4646
x_left, x_right = interval
47-
y_right, y_left = function_values[x_right], function_values[x_left]
47+
y_right, y_left = data[x_right], data[x_left]
4848
x_scale, y_scale = scale
4949
dx = (x_right - x_left) / x_scale
5050
if y_scale == 0:
@@ -70,7 +70,7 @@ def _loss_of_multi_interval(xs, ys):
7070
return sum(vol(pts[i:i+3]) for i in range(N)) / N
7171

7272

73-
def triangle_loss(interval, scale, function_values, neighbors):
73+
def triangle_loss(interval, scale, data, neighbors):
7474
x_left, x_right = interval
7575
xs = [neighbors[x_left][0], x_left, x_right, neighbors[x_right][1]]
7676
xs = [x for x in xs if x is not None]
@@ -79,15 +79,15 @@ def triangle_loss(interval, scale, function_values, neighbors):
7979
return (x_right - x_left) / scale[0]
8080
else:
8181
y_scale = scale[1] or 1
82-
ys_scaled = [function_values[x] / y_scale for x in xs]
82+
ys_scaled = [data[x] / y_scale for x in xs]
8383
xs_scaled = [x / scale[0] for x in xs]
8484
return _loss_of_multi_interval(xs_scaled, ys_scaled)
8585

8686

8787
def get_curvature_loss(area_factor=1, euclid_factor=0.02, horizontal_factor=0.02):
88-
def curvature_loss(interval, scale, function_values, neighbors):
89-
triangle_loss_ = triangle_loss(interval, scale, function_values, neighbors)
90-
default_loss_ = default_loss(interval, scale, function_values, neighbors)
88+
def curvature_loss(interval, scale, data, neighbors):
89+
triangle_loss_ = triangle_loss(interval, scale, data, neighbors)
90+
default_loss_ = default_loss(interval, scale, data, neighbors)
9191
dx = (interval[1] - interval[0]) / scale[0]
9292
return (area_factor * (triangle_loss_**0.5)
9393
+ euclid_factor * default_loss_
@@ -163,11 +163,13 @@ class Learner1D(BaseLearner):
163163
scale : (float, float)
164164
The x and y scale over all the intervals, useful for rescaling the
165165
interval loss.
166-
function_values : dict(float → float)
166+
data : dict(float → float)
167167
A map containing evaluated function values. It is guaranteed
168168
to have values for both of the points in 'interval'.
169169
neighbors : dict(float → (float, float))
170170
A map containing points as keys to its neighbors as a tuple.
171+
At the left ``x_left`` and right ``x_left`` most boundary it has
172+
``x_left: (None, float)`` and ``x_right: (float, None)``.
171173
"""
172174

173175
def __init__(self, function, bounds, loss_per_interval=None, nn_neighbors=0):

docs/source/tutorial/tutorial.custom_loss.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ simple (but naive) strategy is to *uniformly* sample the domain:
6060

6161
.. jupyter-execute::
6262

63-
def uniform_sampling_1d(interval, scale, function_values):
64-
# Note that we never use 'function_values'; the loss is just the size of the subdomain
63+
def uniform_sampling_1d(interval, scale, data):
64+
# Note that we never use 'data'; the loss is just the size of the subdomain
6565
x_left, x_right = interval
6666
x_scale, _ = scale
6767
dx = (x_right - x_left) / x_scale

learner.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,8 +559,8 @@
559559
"metadata": {},
560560
"outputs": [],
561561
"source": [
562-
"def uniform_sampling_1d(interval, scale, function_values):\n",
563-
" # Note that we never use 'function_values'; the loss is just the size of the subdomain\n",
562+
"def uniform_sampling_1d(interval, scale, data):\n",
563+
" # Note that we never use 'data'; the loss is just the size of the subdomain\n",
564564
" x_left, x_right = interval\n",
565565
" x_scale, _ = scale\n",
566566
" dx = (x_right - x_left) / x_scale\n",

0 commit comments

Comments
 (0)