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
+ 7
11
Compare changes
  • Side-by-side
  • Inline
@@ -72,11 +72,7 @@ def _loss_of_multi_interval(xs, ys):
def triangle_loss(interval, scale, data, neighbors):
x_left, x_right = interval
xs = [x_left, x_right]
if x_left in neighbors:
xs.insert(0, neighbors[x_left][0])
if x_right in neighbors:
xs.append(neighbors[x_right][1])
xs = [neighbors[x_left][0], x_left, x_right, neighbors[x_right][1]]
xs = [x for x in xs if x is not None]
if len(xs) <= 2:
@@ -123,12 +119,12 @@ def _get_neighbors_from_list(xs):
def _get_intervals(x, neighbors, nn_neighbors):
n = nn_neighbors
index = neighbors.bisect_left(x)
points = [neighbors.iloc[i] for i in range(index - n - 1, index + 2 + n)
if 0 <= i < len(neighbors)]
intervals = zip(points, points[1:])
return list(intervals)
nn = nn_neighbors
i = neighbors.index(x)
start = max(0, i - nn - 1)
end = min(len(neighbors), i + nn + 2)
points = neighbors.keys()[start:end]
return list(zip(points, points[1:]))
class Learner1D(BaseLearner):
Loading