Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
The function values for each of the neighboring points.
Returns
-------
loss : float
"""
neighbors = [n for n in neighbors if n is not None]
neighbor_values = [v for v in neighbor_values if v is not None]
if len(neighbors) == 0:
return 0
s = [(*x, *to_list(y)) for x, y in zip(simplex, values)]
n = [(*x, *to_list(y)) for x, y in zip(neighbors, neighbor_values)]
return sum(simplex_volume_in_embedding([*s, neighbor]) for neighbor in n) / len(
neighbors
)
return 0
neighbor_points = set.union(*(set(n) - set(subdomain) for n in neighbors))
neighbor_points = [domain.triangulation.vertices[p] for p in neighbor_points]
simplex = [domain.triangulation.vertices[p] for p in subdomain]
z = data[simplex[0]]
if isinstance(z, Iterable):
s = [(*x, *data[x]) for x in simplex]
n = [(*x, *data[x]) for x in neighbor_points]
else:
s = [(*x, data[x]) for x in simplex]
n = [(*x, data[x]) for x in neighbor_points]
return sum(simplex_volume_in_embedding([*s, neigh]) for neigh in n) / len(
neighbors
)
simplex : list of tuples
Each entry is one point of the simplex.
values : list of values
The scaled function values of each of the simplex points.
value_scale : float
The scale of values, where ``values = function_values * value_scale``.
Returns
-------
loss : float
"""
if isinstance(values[0], Iterable):
pts = [(*x, *y) for x, y in zip(simplex, values)]
else:
pts = [(*x, y) for x, y in zip(simplex, values)]
return simplex_volume_in_embedding(pts)
def __call__(self, domain, subdomain, codomain_bounds, data):
assert isinstance(domain, ConvexHull)
xs = [tuple(domain.triangulation.vertices[x]) for x in subdomain]
ys = [data[x] for x in xs]
if isinstance(ys[0], Iterable):
pts = [(*x, *y) for x, y in zip(xs, ys)]
else:
pts = [(*x, y) for x, y in zip(xs, ys)]
return simplex_volume_in_embedding(pts)
def triangle_loss(xs, ys):
xs = [x for x in xs if x is not None]
ys = [y for y in ys if y is not None]
if len(xs) == 2: # we do not have enough points for a triangle
return xs[1] - xs[0]
N = len(xs) - 2 # number of constructed triangles
if isinstance(ys[0], Iterable):
pts = [(x, *y) for x, y in zip(xs, ys)]
vol = simplex_volume_in_embedding
else:
pts = [(x, y) for x, y in zip(xs, ys)]
vol = volume
return sum(vol(pts[i : i + 3]) for i in range(N)) / N
"""
tri = ip.tri
def get_neighbors(i, ip):
n = np.array([tri.simplices[n] for n in tri.neighbors[i] if n != -1])
# remove the vertices that are in the simplex
c = np.setdiff1d(n.reshape(-1), tri.simplices[i])
return np.concatenate((tri.points[c], ip.values[c]), axis=-1)
simplices = np.concatenate(
[tri.points[tri.simplices], ip.values[tri.simplices]], axis=-1
)
neighbors = [get_neighbors(i, ip) for i in range(len(tri.simplices))]
return [
sum(simplex_volume_in_embedding(np.vstack([simplex, n])) for n in neighbors[i])
/ len(neighbors[i])
for i, simplex in enumerate(simplices)
]