Skip to content

Commit 999ca35

Browse files
committed
2D: improve docs
1 parent 0366c44 commit 999ca35

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed

adaptive/learner/learner2D.py

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def deviations(ip):
2727
2828
Returns
2929
-------
30-
numpy array
30+
deviations : numpy.ndarray
3131
The deviation per triangle.
3232
"""
3333
values = ip.values / (ip.values.ptp(axis=0).max() or 1)
@@ -65,7 +65,7 @@ def areas(ip):
6565
6666
Returns
6767
-------
68-
numpy array
68+
areas : numpy.ndarray
6969
The area per triangle in ``ip.tri``.
7070
"""
7171
p = ip.tri.points[ip.tri.vertices]
@@ -79,6 +79,15 @@ def uniform_loss(ip):
7979
8080
Works with `~adaptive.Learner2D` only.
8181
82+
Parameters
83+
----------
84+
ip : `scipy.interpolate.LinearNDInterpolator` instance
85+
86+
Returns
87+
-------
88+
losses : numpy.ndarray
89+
Loss per triangle in ``ip.tri``.
90+
8291
Examples
8392
--------
8493
>>> from adaptive.learner.learner2D import uniform_loss
@@ -103,6 +112,10 @@ def resolution_loss_function(min_distance=0, max_distance=1):
103112
The arguments `min_distance` and `max_distance` should be in between 0 and 1
104113
because the total area is normalized to 1.
105114
115+
Returns
116+
-------
117+
loss_function : callable
118+
106119
Examples
107120
--------
108121
>>> def f(xy):
@@ -133,12 +146,21 @@ def resolution_loss(ip):
133146

134147

135148
def minimize_triangle_surface_loss(ip):
136-
"""Loss function that is similar to the default loss function in the
149+
"""Loss function that is similar to the distance loss function in the
137150
`~adaptive.Learner1D`. The loss is the area spanned by the 3D
138151
vectors of the vertices.
139152
140153
Works with `~adaptive.Learner2D` only.
141154
155+
Parameters
156+
----------
157+
ip : `scipy.interpolate.LinearNDInterpolator` instance
158+
159+
Returns
160+
-------
161+
losses : numpy.ndarray
162+
Loss per triangle in ``ip.tri``.
163+
142164
Examples
143165
--------
144166
>>> from adaptive.learner.learner2D import minimize_triangle_surface_loss
@@ -170,6 +192,19 @@ def _get_vectors(points):
170192

171193

172194
def default_loss(ip):
195+
"""Loss function that combines
196+
197+
Works with `~adaptive.Learner2D` only.
198+
199+
Parameters
200+
----------
201+
ip : `scipy.interpolate.LinearNDInterpolator` instance
202+
203+
Returns
204+
-------
205+
losses : numpy.ndarray
206+
Loss per triangle in ``ip.tri``.
207+
"""
173208
dev = np.sum(deviations(ip), axis=0)
174209
A = areas(ip)
175210
losses = dev * np.sqrt(A) + 0.3 * A
@@ -425,6 +460,12 @@ def interpolator(self, *, scaled=False):
425460
Returns
426461
-------
427462
interpolate : `scipy.interpolate.LinearNDInterpolator`
463+
464+
Examples
465+
--------
466+
>>> xs, ys = [np.linspace(*b, n=100) for b in learner.bounds]
467+
>>> ip = learner.interpolator()
468+
>>> zs = ip(xs[:, None], ys[None, :])
428469
"""
429470
if scaled:
430471
if self._ip is None:

0 commit comments

Comments
 (0)