Browse code

2D: scale the deviation and return areas instead of sqrt(areas)

Bas Nijholt authored on 15/11/2017 22:29:39
Showing 1 changed files
... ...
@@ -12,11 +12,12 @@ from .utils import restore
12 12
 # Learner2D and helper functions.
13 13
 
14 14
 def deviations(ip):
15
+    values = ip.values / (ip.values.ptp() or 1)
15 16
     gradients = interpolate.interpnd.estimate_gradients_2d_global(
16
-        ip.tri, ip.values, tol=1e-6)
17
+        ip.tri, values, tol=1e-6)
17 18
 
18 19
     p = ip.tri.points[ip.tri.vertices]
19
-    vs = ip.values[ip.tri.vertices]
20
+    vs = values[ip.tri.vertices]
20 21
     gs = gradients[ip.tri.vertices]
21 22
 
22 23
     def deviation(p, v, g):
... ...
@@ -36,13 +37,12 @@ def areas(ip):
36 37
     p = ip.tri.points[ip.tri.vertices]
37 38
     q = p[:, :-1, :] - p[:, -1, None, :]
38 39
     areas = abs(q[:, 0, 0] * q[:, 1, 1] - q[:, 0, 1] * q[:, 1, 0]) / 2
39
-    areas = np.sqrt(areas)
40 40
     return areas
41 41
 
42 42
 
43 43
 def _default_loss_per_triangle(ip):
44 44
     devs = deviations(ip)
45
-    area_per_triangle = areas(ip)
45
+    area_per_triangle = np.sqrt(areas(ip))
46 46
     losses = np.sum([dev * area_per_triangle for dev in devs], axis=0)
47 47
     return losses
48 48