Skip to content

Commit 01aa0c8

Browse files
authored
docs: convert public-API docstrings to NumPy style + enforce convention (#856)
Convert all Google-style (`Args:`/`Returns:`) and broken-RST (`Parameters::`/`Returns::`/`:param:`) docstrings of public APIs to NumPy-doc style across 142 modules. Reformat the shared parameter fragments in `brainpy/dyn/_docs.py` and align their `%s`/`{}` injection indentation (lif.py, base.py) so napoleon parses every injected `Parameters` section correctly. Config: - docs/conf.py: pin napoleon to NumPy style (google off, numpy on, plus use_param/use_rtype/preprocess_types). - pyproject.toml: record `[tool.pydocstyle] convention = "numpy"` as the single source of truth for the docstring convention. Format-only change: with docstrings stripped, the AST of every one of the 141 touched source modules is byte-identical to before. napoleon parses all 1256 public `Parameters` sections with zero errors and zero empty sections.
1 parent 6acb75e commit 01aa0c8

144 files changed

Lines changed: 5737 additions & 4126 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

brainpy/algorithms/offline.py

Lines changed: 51 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -60,42 +60,46 @@ def __init__(self, name=None):
6060
def __call__(self, targets, inputs, outputs=None):
6161
"""The training procedure.
6262
63-
Parameters::
63+
Parameters
64+
----------
6465
65-
targets: ArrayType
66+
targets : ArrayType
6667
The 2d target data with the shape of `(num_batch, num_output)`.
67-
inputs: ArrayType
68+
inputs : ArrayType
6869
The 2d input data with the shape of `(num_batch, num_input)`.
69-
outputs: ArrayType
70+
outputs : ArrayType
7071
The 2d output data with the shape of `(num_batch, num_output)`.
7172
72-
Returns::
73+
Returns
74+
-------
7375
74-
weight: ArrayType
76+
weight : ArrayType
7577
The weights after fit.
7678
"""
7779
return self.call(targets, inputs, outputs)
7880

7981
def call(self, targets, inputs, outputs=None) -> ArrayType:
8082
"""The training procedure.
8183
82-
Parameters::
84+
Parameters
85+
----------
8386
84-
inputs: ArrayType
87+
inputs : ArrayType
8588
The 3d input data with the shape of `(num_batch, num_time, num_input)`,
8689
or, the 2d input data with the shape of `(num_time, num_input)`.
8790
88-
targets: ArrayType
91+
targets : ArrayType
8992
The 3d target data with the shape of `(num_batch, num_time, num_output)`,
9093
or the 2d target data with the shape of `(num_time, num_output)`.
9194
92-
outputs: ArrayType
95+
outputs : ArrayType
9396
The 3d output data with the shape of `(num_batch, num_time, num_output)`,
9497
or the 2d output data with the shape of `(num_time, num_output)`.
9598
96-
Returns::
99+
Returns
100+
-------
97101
98-
weight: ArrayType
102+
weight : ArrayType
99103
The weights after fit.
100104
"""
101105
raise NotImplementedError('Must implement the __call__ function by the subclass itself.')
@@ -117,11 +121,12 @@ class RegressionAlgorithm(OfflineAlgorithm):
117121
""" Base regression model. Models the relationship between a scalar dependent variable y and the independent
118122
variables X.
119123
120-
Parameters::
124+
Parameters
125+
----------
121126
122-
max_iter: int
127+
max_iter : int
123128
The number of training iterations the algorithm will tune the weights for.
124-
learning_rate: float
129+
learning_rate : float
125130
The step length that will be used when updating the weights.
126131
"""
127132

@@ -178,9 +183,10 @@ def predict(self, W, X):
178183
class LinearRegression(RegressionAlgorithm):
179184
"""Training algorithm of least-square regression.
180185
181-
Parameters::
186+
Parameters
187+
----------
182188
183-
name: str
189+
name : str
184190
The name of the algorithm.
185191
"""
186192

@@ -221,20 +227,21 @@ def call(self, targets, inputs, outputs=None):
221227
class RidgeRegression(RegressionAlgorithm):
222228
"""Training algorithm of ridge regression.
223229
224-
Parameters::
230+
Parameters
231+
----------
225232
226-
alpha: float
233+
alpha : float
227234
The regularization coefficient.
228235
229236
.. versionadded:: 2.2.0
230237
231-
beta: float
238+
beta : float
232239
The regularization coefficient.
233240
234241
.. deprecated:: 2.2.0
235242
Please use `alpha` to set regularization factor.
236243
237-
name: str
244+
name : str
238245
The name of the algorithm.
239246
"""
240247

@@ -295,16 +302,17 @@ def __repr__(self):
295302
class LassoRegression(RegressionAlgorithm):
296303
"""Lasso regression method for offline training.
297304
298-
Parameters::
305+
Parameters
306+
----------
299307
300-
alpha: float
308+
alpha : float
301309
Constant that multiplies the L1 term. Defaults to 1.0.
302310
`alpha = 0` is equivalent to an ordinary least square.
303-
max_iter: int
311+
max_iter : int
304312
The maximum number of iterations.
305-
degree: int
313+
degree : int
306314
The degree of the polynomial that the independent variable X will be transformed to.
307-
name: str
315+
name : str
308316
The name of the algorithm.
309317
"""
310318

@@ -350,17 +358,18 @@ def predict(self, W, X):
350358
class LogisticRegression(RegressionAlgorithm):
351359
"""Logistic regression method for offline training.
352360
353-
Parameters::
361+
Parameters
362+
----------
354363
355-
learning_rate: float
364+
learning_rate : float
356365
The step length that will be taken when following the negative gradient during
357366
training.
358-
gradient_descent: boolean
367+
gradient_descent : boolean
359368
True or false depending on if gradient descent should be used when training. If
360369
false then we use batch optimization by least squares.
361-
max_iter: int
370+
max_iter : int
362371
The number of iteration to optimize the parameters.
363-
name: str
372+
name : str
364373
The name of the algorithm.
365374
"""
366375

@@ -498,18 +507,19 @@ def predict(self, W, X):
498507
class ElasticNetRegression(RegressionAlgorithm):
499508
"""
500509
501-
Parameters:
510+
Parameters
511+
----------
502512
-----------
503-
degree: int
513+
degree : int
504514
The degree of the polynomial that the independent variable X will be transformed to.
505-
reg_factor: float
515+
reg_factor : float
506516
The factor that will determine the amount of regularization and feature
507517
shrinkage.
508-
l1_ration: float
518+
l1_ration : float
509519
Weighs the contribution of l1 and l2 regularization.
510-
n_iterations: float
520+
n_iterations : float
511521
The number of training iterations the algorithm will tune the weights for.
512-
learning_rate: float
522+
learning_rate : float
513523
The step length that will be used when updating the weights.
514524
"""
515525

@@ -563,11 +573,12 @@ def get_supported_offline_methods():
563573
def register_offline_method(name: str, method: OfflineAlgorithm):
564574
"""Register a new offline learning method.
565575
566-
Parameters::
576+
Parameters
577+
----------
567578
568-
name: str
579+
name : str
569580
The method name.
570-
method: OfflineAlgorithm
581+
method : OfflineAlgorithm
571582
The function method.
572583
"""
573584
if name in name2func:

brainpy/algorithms/online.py

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,22 @@ def __init__(self, name=None):
4545
def __call__(self, *args, **kwargs):
4646
"""The training procedure.
4747
48-
Parameters::
48+
Parameters
49+
----------
4950
50-
identifier: str
51+
identifier : str
5152
The variable name.
52-
target: ArrayType
53+
target : ArrayType
5354
The 2d target data with the shape of `(num_batch, num_output)`.
54-
input: ArrayType
55+
input : ArrayType
5556
The 2d input data with the shape of `(num_batch, num_input)`.
56-
output: ArrayType
57+
output : ArrayType
5758
The 2d output data with the shape of `(num_batch, num_output)`.
5859
59-
Returns::
60+
Returns
61+
-------
6062
61-
weight: ArrayType
63+
weight : ArrayType
6264
The weights after fit.
6365
"""
6466
return self.call(*args, **kwargs)
@@ -69,20 +71,22 @@ def register_target(self, *args, **kwargs):
6971
def call(self, target, input, output, identifier: str = ''):
7072
"""The training procedure.
7173
72-
Parameters::
74+
Parameters
75+
----------
7376
74-
identifier: str
77+
identifier : str
7578
The variable name.
76-
target: ArrayType
79+
target : ArrayType
7780
The 2d target data with the shape of `(num_batch, num_output)`.
78-
input: ArrayType
81+
input : ArrayType
7982
The 2d input data with the shape of `(num_batch, num_input)`.
80-
output: ArrayType
83+
output : ArrayType
8184
The 2d output data with the shape of `(num_batch, num_output)`.
8285
83-
Returns::
86+
Returns
87+
-------
8488
85-
weight: ArrayType
89+
weight : ArrayType
8690
The weights after fit.
8791
"""
8892
raise NotImplementedError('Must implement the call() function by the subclass itself.')
@@ -100,15 +104,17 @@ class RLS(OnlineAlgorithm):
100104
contrast to other algorithms such as the least mean squares
101105
(LMS) that aim to reduce the mean square error.
102106
103-
See Also::
107+
See Also
108+
--------
104109
105110
LMS, ForceLearning
106111
107-
Parameters::
112+
Parameters
113+
----------
108114
109-
alpha: float
115+
alpha : float
110116
The learning rate.
111-
name: str
117+
name : str
112118
The algorithm name.
113119
114120
"""
@@ -176,11 +182,12 @@ class LMS(OnlineAlgorithm):
176182
based on the error at the current time. It was invented in 1960 by
177183
Stanford University professor Bernard Widrow and his first Ph.D. student, Ted Hoff.
178184
179-
Parameters::
185+
Parameters
186+
----------
180187
181-
alpha: float
188+
alpha : float
182189
The learning rate.
183-
name: str
190+
name : str
184191
The target name.
185192
"""
186193

@@ -211,11 +218,12 @@ def get_supported_online_methods():
211218
def register_online_method(name: str, method: OnlineAlgorithm):
212219
"""Register a new oneline learning method.
213220
214-
Parameters::
221+
Parameters
222+
----------
215223
216-
name: str
224+
name : str
217225
The method name.
218-
method: callable
226+
method : callable
219227
The function method.
220228
"""
221229
if name in name2func:

0 commit comments

Comments
 (0)