Skip to content

Commit

Permalink
Update Parameters syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
patnr committed Oct 29, 2024
1 parent 9b864e6 commit e4fc860
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 140 deletions.
61 changes: 31 additions & 30 deletions dapper/mods/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,36 +49,37 @@ class HiddenMarkovModel(struct_tools.NicePrint):
imports all configurations, which might then unintentionally interact.
To avoid this, you should use the `copy` method of the `HMM`
before making any changes to it.
Parameters
----------
Dyn: `Operator` or dict
Operator for the dynamics.
Obs: `Operator` or dict
Operator for the observations
Can also be time-dependent, ref `TimeDependentOperator`.
tseq: [`tools.chronos.Chronology`][]
Time sequence of the HMM process.
X0: [`tools.randvars.RV`][]
Random distribution of initial condition
liveplotters: `list`, optional
A list of tuples. See example use in function `LPs` of [`mods.Lorenz63`][].
- The first element of the tuple determines if the liveplotter
is shown by default. If `False`, the liveplotter is only shown when
included among the `liveplots` argument of `assimilate`
- The second element in the tuple gives the corresponding liveplotter
function/class.
sectors: `dict`, optional
Labelled indices referring to parts of the state vector.
When defined, field-mean statistics are computed for each sector.
Example use can be found in `examples/param_estim.py`
and `dapper/mods/Lorenz96/miyoshi2011.py`
name: str, optional
Label for the `HMM`.
"""

def __init__(self, *args, **kwargs):
"""Initialize.
Parameters
----------
Dyn : Operator or dict
Operator for the dynamics.
Obs : Operator or dict
Operator for the observations
Can also be time-dependent, ref `TimeDependentOperator`.
tseq : tools.chronos.Chronology
Time sequence of the HMM process.
X0 : tools.randvars.RV
Random distribution of initial condition
liveplotters : list, optional
A list of tuples. See example use in function `LPs` of [`mods.Lorenz63`][].
- The first element of the tuple determines if the liveplotter
is shown by default. If `False`, the liveplotter is only shown when
included among the `liveplots` argument of `assimilate`
- The second element in the tuple gives the corresponding liveplotter
function/class.
sectors : dict, optional
Labelled indices referring to parts of the state vector.
When defined, field-mean statistics are computed for each sector.
Example use can be found in `examples/param_estim.py`
and `dapper/mods/Lorenz96/miyoshi2011.py`
name : str, optional
Label for the `HMM`.
"""
# Expected args/kwargs, along with type and default.
attrs = dict(
Dyn=(Operator, None),
Expand Down Expand Up @@ -216,11 +217,11 @@ class Operator(struct_tools.NicePrint):
Parameters
----------
M: int
M : int
Length of output vectors.
model: function
model : function
The actual operator.
noise: RV, optional
noise : RV, optional
The associated additive noise. The noise can also be a scalar or an
array, producing `GaussRV(C=noise)`.
Expand Down
24 changes: 12 additions & 12 deletions dapper/mods/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ def direct_obs_matrix(Nx, obs_inds):
Parameters
----------
Nx: int
Nx : int
Length of state vector
obs_inds: ndarray
obs_inds : ndarray
Indices of elements of the state vector that are (directly) observed.
Returns
-------
H: ndarray
H : ndarray
The observation matrix for direct partial observations.
"""
Ny = len(obs_inds)
Expand All @@ -143,14 +143,14 @@ def partial_Id_Obs(Nx, obs_inds):
Parameters
----------
Nx: int
Nx : int
Length of state vector
obs_inds: ndarray
obs_inds : ndarray
The observed indices.
Returns
-------
Obs: dict
Obs : dict
Observation operator including size of the observation space,
observation operator/model and tangent linear observation operator
"""
Expand Down Expand Up @@ -181,12 +181,12 @@ def Id_Obs(Nx):
Parameters
----------
Nx: int
Nx : int
Length of state vector
Returns
-------
Obs: dict
Obs : dict
Observation operator including size of the observation space,
observation operator/model and tangent linear observation operator
"""
Expand All @@ -198,18 +198,18 @@ def linspace_int(Nx, Ny, periodic=True):
Parameters
----------
Nx: int
Nx : int
Range of integers
Ny: int
Ny : int
Number of integers
periodic: bool, optional
periodic : bool, optional
Whether the vector is periodic.
Determines if `Nx == 0`.
Default: True
Returns
-------
integers: ndarray
integers : ndarray
The list of integers.
Examples
Expand Down
28 changes: 14 additions & 14 deletions dapper/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,10 +631,10 @@ def unpack_uqs(uq_list, decimals=None):
Parameters
----------
uq_list: list
uq_list : list
List of `uq`s.
decimals: int
decimals : int
Desired number of decimals.
Used for (only) the columns "val" and "prec".
Default: `None`. In this case, the formatting is left to the `uq`s.
Expand Down Expand Up @@ -707,23 +707,23 @@ def center(E, axis=0, rescale=False):
Parameters
----------
E: ndarray
E : ndarray
Ensemble which going to be inflated
axis: int, optional
axis : int, optional
The axis to be centered. Default: 0
rescale: bool, optional
rescale : bool, optional
If True, inflate to compensate for reduction in the expected variance.
The inflation factor is \(\sqrt{\frac{N}{N - 1}}\)
where N is the ensemble size. Default: False
Returns
-------
X: ndarray
X : ndarray
Ensemble anomaly
x: ndarray
x : ndarray
Mean of the ensemble
"""
x = np.mean(E, axis=axis, keepdims=True)
Expand Down Expand Up @@ -755,7 +755,7 @@ def inflate_ens(E, factor):
E : ndarray
Ensemble which going to be inflated
factor: `float`
factor : `float`
Inflation factor
Returns
Expand All @@ -777,10 +777,10 @@ def weight_degeneracy(w, prec=1e-10):
Parameters
----------
w: ndarray
w : ndarray
Importance weights. Must sum to 1.
prec: float, optional
prec : float, optional
Tolerance of the distance between w and one. Default:1e-10
Returns
Expand All @@ -796,21 +796,21 @@ def unbias_var(w=None, N_eff=None, avoid_pathological=False):
Parameters
----------
w: ndarray, optional
w : ndarray, optional
Importance weights. Must sum to 1.
Only one of `w` and `N_eff` can be `None`. Default: `None`
N_eff: float, optional
N_eff : float, optional
The "effective" size of the weighted ensemble.
If not provided, it is computed from the weights.
The unbiasing factor is $$ N_{eff} / (N_{eff} - 1) $$.
avoid_pathological: bool, optional
avoid_pathological : bool, optional
Avoid weight collapse. Default: `False`
Returns
-------
ub: float
ub : float
factor used to unbiasing variance
Reference
Expand Down
4 changes: 2 additions & 2 deletions dapper/tools/linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ def tsvd(A, threshold=0.99999, avoid_pathological=True):
Parameters
----------
avoid_pathological: bool
avoid_pathological : bool
Avoid truncating (e.g.) the identity matrix.
NB: only applies for float threshold.
threshold: float or int
threshold : float or int
- if `float`, `< 1.0` then "rank" = lowest number
such that the "energy" retained >= threshold
Expand Down
10 changes: 5 additions & 5 deletions dapper/tools/localization.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ def pairwise_distances(A, B=None, domain=None):
Parameters
----------
A: array of shape `(nPoints, nDims)`.
A : array of shape `(nPoints, nDims)`.
A collection of points.
B:
B :
Same as `A`, but `nPoints` can differ.
domain: tuple
domain : tuple
Assume the domain is a **periodic** hyper-rectangle whose
edges along dimension `i` span from 0 to `domain[i]`.
NB: Behaviour not defined if `any(A.max(0) > domain)`, and likewise for `B`.
Expand Down Expand Up @@ -221,8 +221,8 @@ def rectangular_partitioning(shape, steps, do_ind=True):
Parameters
----------
shape: (len(grid[dim]) for dim in range(ndim))
steps: (step_len[dim] for dim in range(ndim))
shape : (len(grid[dim]) for dim in range(ndim))
steps : (step_len[dim] for dim in range(ndim))
Returns
-------
Expand Down
10 changes: 5 additions & 5 deletions dapper/tools/rounding.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ def np_vectorize(f):
Parameters
----------
f: callable
f : callable
Your function.
Returns
-------
vectorized: callable
vectorized : callable
Your function, now element-wise applicable to an iterable.
"""
vectorized = np.vectorize(f)
Expand Down Expand Up @@ -192,7 +192,7 @@ def round2(x, prec=1.0):
----------
x : array_like
Value to be rounded.
prec: float
prec : float
Precision, before prettify, which is given by
$$ \text{prec} = 10^{\text{floor}(-\log_{10}|\text{prec}|)} $$
Expand Down Expand Up @@ -259,12 +259,12 @@ def is_whole(x, **kwargs):
Parameters
----------
x: float or ndarray
x : float or ndarray
Values to be checked
Returns
-------
l: bool
l : bool
True if rounded x is close to x, otherwise False
"""
return np.isclose(x, round(x), **kwargs)
Loading

0 comments on commit e4fc860

Please sign in to comment.