|
1 | 1 | """
|
2 |
| -This backend holds draws in memory, managing them via NumPy arrays. |
| 2 | +This backend simply discards draws. There are not stored in memory. |
| 3 | +This can be used in situations where we want to run an MCMC but not permanently |
| 4 | +store its output. |
3 | 5 | """
|
4 | 6 |
|
| 7 | +# Code-wise, a NullChain is essentially just a NumpyChain without the underlying data array. |
| 8 | + |
5 | 9 | from typing import Dict, List, Mapping, Optional, Sequence, Tuple
|
6 | 10 |
|
7 | 11 | import numpy
|
|
12 | 16 | from .numpy import grow_append
|
13 | 17 |
|
14 | 18 | class NullChain(Chain):
|
15 |
| - """Stores value draws in NumPy arrays and can pre-allocate memory.""" |
| 19 | + """A null storage: discards values immediately and allocates no memory. |
16 | 20 |
|
17 |
| - def __init__(self, cmeta: ChainMeta, rmeta: RunMeta, *, preallocate: int=0) -> None: |
18 |
| - """Creates a null storage for draws from a chain: will gobble outputs without storing them |
| 21 | + Use cases are |
| 22 | +
|
| 23 | + - Online computations: Draws are used and discarded immediately, allowing for much larger sample spaces. |
| 24 | + - Profiling: To use as a baseline, to measure compute time & memory before allocating memory for draws. |
| 25 | + Comparing with another backend would then show how much overhead it adds. |
19 | 26 |
|
20 |
| - Use cases are |
| 27 | + Since draws are not stored, only a subset of the `Chain` interface is supported: |
21 | 28 |
|
22 |
| - - Online computations: Draws are used and discarded immediately, allowing for much larger sample spaces. |
23 |
| - - Profiling: To use as a baseline, to measure compute time & memory before allocating memory for draws. |
24 |
| - Comparing with another backend would then show how much overhead it adds. |
| 29 | + - Supported: `__len__`, `append`, `get_stats`, `get_stats_at` |
| 30 | + - Not supported: `get_draws`, `get_draws_at` |
25 | 31 |
|
26 |
| - .. Todo:: Allow to optionally store sampling stats. |
27 |
| - .. Todo:: Allow to retrieve the most recent draw? |
| 32 | + .. Todo:: Option to also sampling stats? |
| 33 | + .. Todo:: Allow retrieving the most recent draw? |
| 34 | +
|
| 35 | + """ |
| 36 | + |
| 37 | + def __init__(self, cmeta: ChainMeta, rmeta: RunMeta, *, preallocate: int) -> None: |
| 38 | + """Creates a null storage for draws from a chain: will gobble outputs without storing them |
28 | 39 |
|
29 | 40 | Parameters
|
30 | 41 | ----------
|
|
0 commit comments