Skip to content

Commit

Permalink
Remove types in doc-strings in learner2D.py
Browse files Browse the repository at this point in the history
  • Loading branch information
basnijholt committed Nov 28, 2022
1 parent 4d10f2f commit 7f26f51
Showing 1 changed file with 38 additions and 38 deletions.
76 changes: 38 additions & 38 deletions adaptive/learner/learner2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ def deviations(ip: LinearNDInterpolator) -> list[np.ndarray]:
Parameters
----------
ip : `scipy.interpolate.LinearNDInterpolator` instance
ip
Returns
-------
deviations : list
deviations
The deviation per triangle.
"""
values = ip.values / (ip.values.ptp(axis=0).max() or 1)
Expand Down Expand Up @@ -79,11 +79,11 @@ def areas(ip: LinearNDInterpolator) -> np.ndarray:
Parameters
----------
ip : `scipy.interpolate.LinearNDInterpolator` instance
ip
Returns
-------
areas : numpy.ndarray
areas
The area per triangle in ``ip.tri``.
"""
p = ip.tri.points[ip.tri.simplices]
Expand All @@ -99,11 +99,11 @@ def uniform_loss(ip: LinearNDInterpolator) -> np.ndarray:
Parameters
----------
ip : `scipy.interpolate.LinearNDInterpolator` instance
ip
Returns
-------
losses : numpy.ndarray
losses
Loss per triangle in ``ip.tri``.
Examples
Expand Down Expand Up @@ -136,7 +136,7 @@ def resolution_loss_function(
Returns
-------
loss_function : callable
loss_function
Examples
--------
Expand Down Expand Up @@ -173,11 +173,11 @@ def minimize_triangle_surface_loss(ip: LinearNDInterpolator) -> np.ndarray:
Parameters
----------
ip : `scipy.interpolate.LinearNDInterpolator` instance
ip
Returns
-------
losses : numpy.ndarray
losses
Loss per triangle in ``ip.tri``.
Examples
Expand Down Expand Up @@ -217,11 +217,11 @@ def default_loss(ip: LinearNDInterpolator) -> np.ndarray:
Parameters
----------
ip : `scipy.interpolate.LinearNDInterpolator` instance
ip
Returns
-------
losses : numpy.ndarray
losses
Loss per triangle in ``ip.tri``.
"""
dev = np.sum(deviations(ip), axis=0)
Expand All @@ -241,15 +241,15 @@ def choose_point_in_triangle(triangle: np.ndarray, max_badness: int) -> np.ndarr
Parameters
----------
triangle : numpy.ndarray
triangle
The coordinates of a triangle with shape (3, 2).
max_badness : int
max_badness
The badness at which the point is either chosen on a edge or
in the middle.
Returns
-------
point : numpy.ndarray
point
The x and y coordinate of the suggested new point.
"""
a, b, c = triangle
Expand All @@ -267,17 +267,17 @@ def choose_point_in_triangle(triangle: np.ndarray, max_badness: int) -> np.ndarr
return point


def triangle_loss(ip):
def triangle_loss(ip: LinearNDInterpolator) -> list[float]:
r"""Computes the average of the volumes of the simplex combined with each
neighbouring point.
Parameters
----------
ip : `scipy.interpolate.LinearNDInterpolator` instance
ip
Returns
-------
triangle_loss : list
triangle_loss
The mean volume per triangle.
Notes
Expand Down Expand Up @@ -311,13 +311,13 @@ class Learner2D(BaseLearner):
Parameters
----------
function : callable
function
The function to learn. Must take a tuple of two real
parameters and return a real number.
bounds : list of 2-tuples
bounds
A list ``[(a1, b1), (a2, b2)]`` containing bounds,
one per dimension.
loss_per_triangle : callable, optional
loss_per_triangle
A function that returns the loss for every triangle.
If not provided, then a default is used, which uses
the deviation from a linear estimate, as well as
Expand Down Expand Up @@ -424,19 +424,19 @@ def to_dataframe(
Parameters
----------
with_default_function_args : bool, optional
with_default_function_args
Include the ``learner.function``'s default arguments as a
column, by default True
function_prefix : str, optional
function_prefix
Prefix to the ``learner.function``'s default arguments' names,
by default "function."
seed_name : str, optional
seed_name
Name of the seed parameter, by default "seed"
x_name : str, optional
x_name
Name of the input x value, by default "x"
y_name : str, optional
y_name
Name of the input y value, by default "y"
z_name : str, optional
z_name
Name of the output value, by default "z"
Returns
Expand Down Expand Up @@ -475,18 +475,18 @@ def load_dataframe(
Parameters
----------
df : pandas.DataFrame
df
The data to load.
with_default_function_args : bool, optional
with_default_function_args
The ``with_default_function_args`` used in ``to_dataframe()``,
by default True
function_prefix : str, optional
function_prefix
The ``function_prefix`` used in ``to_dataframe``, by default "function."
x_name : str, optional
x_name
The ``x_name`` used in ``to_dataframe``, by default "x"
y_name : str, optional
y_name
The ``y_name`` used in ``to_dataframe``, by default "y"
z_name : str, optional
z_name
The ``z_name`` used in ``to_dataframe``, by default "z"
"""
data = df.set_index([x_name, y_name])[z_name].to_dict()
Expand Down Expand Up @@ -538,7 +538,7 @@ def interpolated_on_grid(
Parameters
----------
n : int, optional
n
Number of points in x and y. If None (default) this number is
evaluated by looking at the size of the smallest triangle.
Expand Down Expand Up @@ -611,14 +611,14 @@ def interpolator(self, *, scaled: bool = False) -> LinearNDInterpolator:
Parameters
----------
scaled : bool
scaled
Use True if all points are inside the
unit-square [(-0.5, 0.5), (-0.5, 0.5)] or False if
the data points are inside the ``learner.bounds``.
Returns
-------
interpolator : `scipy.interpolate.LinearNDInterpolator`
interpolator
Examples
--------
Expand Down Expand Up @@ -755,7 +755,7 @@ def remove_unfinished(self) -> None:
if p not in self.data:
self._stack[p] = np.inf

def plot(self, n=None, tri_alpha=0):
def plot(self, n: int = None, tri_alpha: float = 0):
r"""Plot the Learner2D's current state.
This plot function interpolates the data on a regular grid.
Expand All @@ -764,10 +764,10 @@ def plot(self, n=None, tri_alpha=0):
Parameters
----------
n : int
n
Number of points in x and y. If None (default) this number is
evaluated by looking at the size of the smallest triangle.
tri_alpha : float
tri_alpha
The opacity ``(0 <= tri_alpha <= 1)`` of the triangles overlayed
on top of the image. By default the triangulation is not visible.
Expand Down

0 comments on commit 7f26f51

Please sign in to comment.