Skip to content
Snippets Groups Projects

change resolution_loss to a factory function

Merged Bas Nijholt requested to merge loss_functions into master
3 files
+ 25
40
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -89,7 +89,7 @@ def uniform_loss(ip):
return np.sqrt(areas(ip))
def resolution_loss(ip, min_distance=0, max_distance=1):
def resolution_loss_function(min_distance=0, max_distance=1):
"""Loss function that is similar to the `default_loss` function, but you
can set the maximimum and minimum size of a triangle.
@@ -104,27 +104,24 @@ def resolution_loss(ip, min_distance=0, max_distance=1):
... x, y = xy
... return x**2 + y**2
>>>
>>> from functools import partial
>>> loss = partial(resolution_loss, min_distance=0.01)
>>> loss = resolution_loss_function(min_distance=0.01, max_distance=1)
>>> learner = adaptive.Learner2D(f,
... bounds=[(-1, -1), (1, 1)],
... loss_per_triangle=loss)
>>>
"""
A = areas(ip)
dev = np.sum(deviations(ip), axis=0)
# similar to the default_loss
loss = np.sqrt(A) * dev + A
def resolution_loss(ip):
loss = default_loss(ip)
# Setting areas with a small area to zero such that they won't be chosen again
loss[A < min_distance**2] = 0
# Setting areas with a small area to zero such that they won't be chosen again
loss[A < min_distance**2] = 0
# Setting triangles that have a size larger than max_distance to infinite loss
# such that these triangles will be picked
loss[A > max_distance**2] = np.inf
# Setting triangles that have a size larger than max_distance to infinite loss
# such that these triangles will be picked
loss[A > max_distance**2] = np.inf
return loss
return loss
return resolution_loss
def minimize_triangle_surface_loss(ip):
Loading