Skip to content
Snippets Groups Projects

Resolve "(Learner1D) add possibility to use the direct neighbors in the loss"

Merged Jorn Hoofwijk requested to merge 119-add-second-order-loss-to-adaptive into master
Compare and Show latest version
1 file
+ 5
5
Compare changes
  • Side-by-side
  • Inline
@@ -57,10 +57,10 @@ def default_loss(interval, scale, function_values):
return loss
def loss_of_multi_interval(xs, ys):
def _loss_of_multi_interval(xs, ys):
pts = list(zip(xs, ys))
vols = [volume(pts[i:i+3]) for i in range(len(pts)-2)]
return np.average(vols)
N = len(pts)-2
return sum(volume(pts[i:i+3]) for i in range(N)) / N
def triangle_loss(interval, neighbours, scale, function_values):
@@ -79,7 +79,7 @@ def triangle_loss(interval, neighbours, scale, function_values):
if len(xs) <= 2:
return dx
else:
return loss_of_multi_interval(xs, ys)
return _loss_of_multi_interval(xs, ys)
def get_curvature_loss(area_factor=1, euclid_factor=0.02, horizontal_factor=0.02):
@@ -307,7 +307,7 @@ class Learner1D(BaseLearner):
@staticmethod
def _find_neighbors(x, neighbors):
if x in neighbors:
return neighbors[x]
return neighbors
if x is None:
return None, None
pos = neighbors.bisect_left(x)
Loading