Skip to content

Commit 5e3edf4

Browse files
committed
documentation improvements
1 parent b03302a commit 5e3edf4

22 files changed

+216
-85
lines changed

AUTHORS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Adaptive Authors
1+
## Authors
22
Below is a list of the contributors to Adaptive:
33

44
+ [Anton Akhmerov](<https://antonakhmerov.org>)

README.rst

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
.. summary-start
22
3-
.. _logo-adaptive:
3+
|logo| adaptive
4+
===============
45

5-
|image0| adaptive
6-
=================
7-
8-
|PyPI| |Conda| |Downloads| |pipeline status| |DOI| |Binder| |Join the
9-
chat at https://gitter.im/python-adaptive/adaptive| |Documentation Status|
6+
|PyPI| |Conda| |Downloads| |Pipeline status| |DOI| |Binder| |Gitter|
7+
|Documentation| |GitHub|
108

119
**Tools for adaptive parallel sampling of mathematical functions.**
1210

@@ -126,7 +124,9 @@ We would like to give credits to the following people:
126124
Mathematical Software, 37 (3), art. no. 26, 2010.
127125
- Pauli Virtanen for his ``AdaptiveTriSampling`` script (no longer
128126
available online since SciPy Central went down) which served as
129-
inspiration for the ``~adaptive.Learner2D``.
127+
inspiration for the `~adaptive.Learner2D`.
128+
129+
.. credits-end
130130
131131
For general discussion, we have a `Gitter chat
132132
channel <https://gitter.im/python-adaptive/adaptive>`_. If you find any
@@ -136,21 +136,23 @@ or submit a `merge
136136
request <https://gitlab.kwant-project.org/qt/adaptive/merge_requests>`_.
137137

138138
.. references-start
139-
.. |image0| image:: https://gitlab.kwant-project.org/qt/adaptive/uploads/d20444093920a4a0499e165b5061d952/logo.png
139+
.. |logo| image:: https://adaptive.readthedocs.io/en/latest/_static/logo.png
140140
.. |PyPI| image:: https://img.shields.io/pypi/v/adaptive.svg
141141
:target: https://pypi.python.org/pypi/adaptive
142-
.. |Conda| image:: https://anaconda.org/conda-forge/adaptive/badges/installer/conda.svg
142+
.. |Conda| image:: https://img.shields.io/badge/install%20with-conda-green.svg
143143
:target: https://anaconda.org/conda-forge/adaptive
144-
.. |Downloads| image:: https://anaconda.org/conda-forge/adaptive/badges/downloads.svg
144+
.. |Downloads| image:: https://img.shields.io/conda/dn/conda-forge/adaptive.svg
145145
:target: https://anaconda.org/conda-forge/adaptive
146-
.. |pipeline status| image:: https://gitlab.kwant-project.org/qt/adaptive/badges/master/pipeline.svg
146+
.. |Pipeline status| image:: https://gitlab.kwant-project.org/qt/adaptive/badges/master/pipeline.svg
147147
:target: https://gitlab.kwant-project.org/qt/adaptive/pipelines
148148
.. |DOI| image:: https://zenodo.org/badge/113714660.svg
149-
:target: https://zenodo.org/badge/latestdoi/113714660
149+
:target: https://doi.org/10.5281/zenodo.1446400
150150
.. |Binder| image:: https://mybinder.org/badge.svg
151151
:target: https://mybinder.org/v2/gh/python-adaptive/adaptive/master?filepath=learner.ipynb
152-
.. |Join the chat at https://gitter.im/python-adaptive/adaptive| image:: https://img.shields.io/gitter/room/nwjs/nw.js.svg
152+
.. |Gitter| image:: https://img.shields.io/gitter/room/nwjs/nw.js.svg
153153
:target: https://gitter.im/python-adaptive/adaptive
154-
.. |Documentation Status| image:: https://readthedocs.org/projects/adaptive/badge/?version=latest
154+
.. |Documentation| image:: https://readthedocs.org/projects/adaptive/badge/?version=latest
155155
:target: https://adaptive.readthedocs.io/en/latest/?badge=latest
156+
.. |GitHub| image:: https://img.shields.io/github/stars/python-adaptive/adaptive.svg?style=social
157+
:target: https://github.com/python-adaptive/adaptive/stargazers
156158
.. references-end

adaptive/learner/average_learner.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class AverageLearner(BaseLearner):
2727
Sampled points and values.
2828
pending_points : set
2929
Points that still have to be evaluated.
30+
npoints : int
31+
Number of evaluated points.
3032
"""
3133

3234
def __init__(self, function, atol=None, rtol=None):
@@ -48,7 +50,7 @@ def __init__(self, function, atol=None, rtol=None):
4850

4951
@property
5052
def n_requested(self):
51-
return len(self.data) + len(self.pending_points)
53+
return self.npoints + len(self.pending_points)
5254

5355
def ask(self, n, tell_pending=True):
5456
points = list(range(self.n_requested, self.n_requested + n))
@@ -59,7 +61,7 @@ def ask(self, n, tell_pending=True):
5961
- set(self.data)
6062
- set(self.pending_points))[:n]
6163

62-
loss_improvements = [self.loss_improvement(n) / n] * n
64+
loss_improvements = [self._loss_improvement(n) / n] * n
6365
if tell_pending:
6466
for p in points:
6567
self.tell_pending(p)
@@ -81,10 +83,13 @@ def tell_pending(self, n):
8183

8284
@property
8385
def mean(self):
86+
"""The average of all values in `data`."""
8487
return self.sum_f / self.npoints
8588

8689
@property
8790
def std(self):
91+
"""The corrected sample standard deviation of the values
92+
in `data`."""
8893
n = self.npoints
8994
if n < 2:
9095
return np.inf
@@ -106,7 +111,7 @@ def loss(self, real=True, *, n=None):
106111
return max(standard_error / self.atol,
107112
standard_error / abs(self.mean) / self.rtol)
108113

109-
def loss_improvement(self, n):
114+
def _loss_improvement(self, n):
110115
loss = self.loss()
111116
if np.isfinite(loss):
112117
return loss - self.loss(n=self.npoints + n)
@@ -118,6 +123,12 @@ def remove_unfinished(self):
118123
self.pending_points = set()
119124

120125
def plot(self):
126+
"""Returns a histogram of the evaluated data.
127+
128+
Returns
129+
-------
130+
holoviews.element.Histogram
131+
A histogram of the evaluated data."""
121132
hv = ensure_holoviews()
122133
vals = [v for v in self.data.values() if v is not None]
123134
if not vals:

adaptive/learner/balancing_learner.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class BalancingLearner(BaseLearner):
2222
2323
Parameters
2424
----------
25-
learners : sequence of `BaseLearner`
25+
learners : sequence of `~adaptive.BaseLearner`\s
2626
The learners from which to choose. These must all have the same type.
2727
cdims : sequence of dicts, or (keys, iterable of values), optional
2828
Constant dimensions; the parameters that label the learners. Used
@@ -42,6 +42,13 @@ class BalancingLearner(BaseLearner):
4242
>>> cdims = (['A', 'B'], [(True, 0), (True, 1),
4343
... (False, 0), (False, 1)])
4444
45+
Attributes
46+
----------
47+
learners : list
48+
The sequence of `~adaptive.BaseLearner`\s.
49+
function : callable
50+
A function that calls the functions of the underlying learners.
51+
Its signature is ``function(learner_index, point)``.
4552
strategy : 'loss_improvements' (default), 'loss', or 'npoints'
4653
The points that the `BalancingLearner` choses can be either based on:
4754
the best 'loss_improvements', the smallest total 'loss' of the
@@ -51,13 +58,13 @@ class BalancingLearner(BaseLearner):
5158
5259
Notes
5360
-----
54-
This learner compares the 'loss' calculated from the "child" learners.
61+
This learner compares the `loss` calculated from the "child" learners.
5562
This requires that the 'loss' from different learners *can be meaningfully
5663
compared*. For the moment we enforce this restriction by requiring that
5764
all learners are the same type but (depending on the internals of the
5865
learner) it may be that the loss cannot be compared *even between learners
59-
of the same type*. In this case the `BalancingLearner` will behave in an
60-
undefined way.
66+
of the same type*. In this case the `~adaptive.BalancingLearner` will
67+
behave in an undefined way. Change the `strategy` in that case.
6168
"""
6269

6370
def __init__(self, learners, *, cdims=None, strategy='loss_improvements'):
@@ -81,6 +88,12 @@ def __init__(self, learners, *, cdims=None, strategy='loss_improvements'):
8188

8289
@property
8390
def strategy(self):
91+
"""Can be either 'loss_improvements' (default), 'loss', or 'npoints'
92+
The points that the `BalancingLearner` choses can be either based on:
93+
the best 'loss_improvements', the smallest total 'loss' of the
94+
child learners, or the number of points per learner, using 'npoints'.
95+
One can dynamically change the strategy while the simulation is
96+
running by changing the ``learner.strategy`` attribute."""
8497
return self._strategy
8598

8699
@strategy.setter
@@ -122,7 +135,7 @@ def _ask_and_tell_based_on_loss(self, n):
122135
points = []
123136
loss_improvements = []
124137
for _ in range(n):
125-
losses = self.losses(real=False)
138+
losses = self._losses(real=False)
126139
max_ind = np.argmax(losses)
127140
xs, ls = self.learners[max_ind].ask(1)
128141
points.append((max_ind, xs[0]))
@@ -165,7 +178,7 @@ def tell_pending(self, x):
165178
self._loss.pop(index, None)
166179
self.learners[index].tell_pending(x)
167180

168-
def losses(self, real=True):
181+
def _losses(self, real=True):
169182
losses = []
170183
loss_dict = self._loss if real else self._pending_loss
171184

@@ -178,7 +191,7 @@ def losses(self, real=True):
178191

179192
@cache_latest
180193
def loss(self, real=True):
181-
losses = self.losses(real)
194+
losses = self._losses(real)
182195
return max(losses)
183196

184197
def plot(self, cdims=None, plotter=None, dynamic=True):
@@ -215,8 +228,8 @@ def plot(self, cdims=None, plotter=None, dynamic=True):
215228
Returns
216229
-------
217230
dm : `holoviews.core.DynamicMap` (default) or `holoviews.core.HoloMap`
218-
A `DynamicMap` (dynamic=True) or `HoloMap` (dynamic=False) with
219-
sliders that are defined by `cdims`.
231+
A `DynamicMap` ``(dynamic=True)`` or `HoloMap`
232+
``(dynamic=False)`` with sliders that are defined by `cdims`.
220233
"""
221234
hv = ensure_holoviews()
222235
cdims = cdims or self._cdims_default
@@ -295,7 +308,7 @@ def from_product(cls, f, learner_type, learner_kwargs, combos):
295308
Notes
296309
-----
297310
The order of the child learners inside `learner.learners` is the same
298-
as `adaptive.utils.named_product(**combos)`.
311+
as ``adaptive.utils.named_product(**combos)``.
299312
"""
300313
learners = []
301314
arguments = named_product(**combos)
@@ -313,7 +326,7 @@ def save(self, folder, compress=True):
313326
folder : str
314327
Directory in which the learners's data will be saved.
315328
compress : bool, default True
316-
Compress the data upon saving using 'gzip'. When saving
329+
Compress the data upon saving using `gzip`. When saving
317330
using compression, one must load it with compression too.
318331
319332
Notes
@@ -364,7 +377,7 @@ def load(self, folder, compress=True):
364377
365378
Example
366379
-------
367-
See the example in the 'BalancingLearner.save' doc-string.
380+
See the example in the `BalancingLearner.save` doc-string.
368381
"""
369382
for l in self.learners:
370383
l.load(os.path.join(folder, l.fname), compress=compress)

adaptive/learner/base_learner.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class BaseLearner(metaclass=abc.ABCMeta):
2020
npoints : int, optional
2121
The number of evaluated points that have been added to the learner.
2222
Subclasses do not *have* to implement this attribute.
23+
pending_points : set, optional
24+
Points that have been requested but have not been evaluated yet.
25+
Subclasses do not *have* to implement this attribute.
2326
2427
Notes
2528
-----
@@ -118,10 +121,11 @@ def save(self, fname=None, compress=True):
118121
119122
Notes
120123
-----
121-
There are __two ways__ of naming the files:
122-
1. Using the 'fname' argument in 'learner.save(fname='example.p')
123-
2. Setting the 'fname' attribute, like
124-
'learner.fname = "data/example.p"' and then 'learner.save()'.
124+
There are **two ways** of naming the files:
125+
126+
1. Using the ``fname`` argument in ``learner.save(fname='example.p')``
127+
2. Setting the ``fname`` attribute, like
128+
``learner.fname = "data/example.p"`` and then ``learner.save()``.
125129
"""
126130
fname = fname or self.fname
127131
data = self._get_data()
@@ -142,7 +146,7 @@ def load(self, fname=None, compress=True):
142146
143147
Notes
144148
-----
145-
See the notes in the 'BaseLearner.save' doc-string.
149+
See the notes in the `save` doc-string.
146150
"""
147151
fname = fname or self.fname
148152
with suppress(FileNotFoundError, EOFError):
@@ -157,6 +161,9 @@ def __setstate__(self, state):
157161

158162
@property
159163
def fname(self):
164+
"""Filename for the learner when it is saved (or loaded) using
165+
`~adaptive.BaseLearner.save` (or `~adaptive.BaseLearner.load` ).
166+
"""
160167
# This is a property because then it will be availible in the DataSaver
161168
try:
162169
return self._fname

adaptive/learner/data_saver.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ def __init__(self, learner, arg_picker):
3535
def __getattr__(self, attr):
3636
return getattr(self.learner, attr)
3737

38+
@copy_docstring_from(BaseLearner.tell)
3839
def tell(self, x, result):
3940
y = self.arg_picker(result)
4041
self.extra_data[x] = result
4142
self.learner.tell(x, y)
4243

44+
@copy_docstring_from(BaseLearner.tell_pending)
4345
def tell_pending(self, x):
4446
self.learner.tell_pending(x)
4547

adaptive/learner/integrator_learner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ def _fill_stack(self):
487487

488488
@property
489489
def npoints(self):
490+
"""Number of evaluated points."""
490491
return len(self.done_points)
491492

492493
@property

0 commit comments

Comments
 (0)