Skip to content

Commit be57552

Browse files
committed
[mode] move recurrent models in brainpy.dnn model into brainpy.dyn module
1 parent eab1c4f commit be57552

File tree

14 files changed

+87
-99
lines changed

14 files changed

+87
-99
lines changed

brainpy/_add_deprecations.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,30 @@
101101
}
102102
dyn.__getattr__ = deprecation_getattr2('brainpy.dyn', dyn.__deprecations)
103103

104+
dnn.__deprecations = {
105+
'NVAR': ('brainpy.dnn.NVAR', 'brainpy.dyn.NVAR', dyn.NVAR),
106+
'Reservoir': ('brainpy.dnn.Reservoir', 'brainpy.dyn.Reservoir', dyn.Reservoir),
107+
'RNNCell': ('brainpy.dnn.RNNCell', 'brainpy.dyn.RNNCell', dyn.RNNCell),
108+
'GRUCell': ('brainpy.dnn.GRUCell', 'brainpy.dyn.GRUCell', dyn.GRUCell),
109+
'LSTMCell': ('brainpy.dnn.LSTMCell', 'brainpy.dyn.LSTMCell', dyn.LSTMCell),
110+
'Conv1dLSTMCell': ('brainpy.dnn.Conv1dLSTMCell', 'brainpy.dyn.Conv1dLSTMCell', dyn.Conv1dLSTMCell),
111+
'Conv2dLSTMCell': ('brainpy.dnn.Conv2dLSTMCell', 'brainpy.dyn.Conv2dLSTMCell', dyn.Conv2dLSTMCell),
112+
'Conv3dLSTMCell': ('brainpy.dnn.Conv3dLSTMCell', 'brainpy.dyn.Conv3dLSTMCell', dyn.Conv3dLSTMCell),
113+
}
114+
dnn.__getattr__ = deprecation_getattr2('brainpy.dnn', dnn.__deprecations)
115+
116+
layers.__deprecations = {
117+
'NVAR': ('brainpy.layers.NVAR', 'brainpy.dyn.NVAR', dyn.NVAR),
118+
'Reservoir': ('brainpy.layers.Reservoir', 'brainpy.dyn.Reservoir', dyn.Reservoir),
119+
'RNNCell': ('brainpy.layers.RNNCell', 'brainpy.dyn.RNNCell', dyn.RNNCell),
120+
'GRUCell': ('brainpy.layers.GRUCell', 'brainpy.dyn.GRUCell', dyn.GRUCell),
121+
'LSTMCell': ('brainpy.layers.LSTMCell', 'brainpy.dyn.LSTMCell', dyn.LSTMCell),
122+
'Conv1dLSTMCell': ('brainpy.layers.Conv1dLSTMCell', 'brainpy.dyn.Conv1dLSTMCell', dyn.Conv1dLSTMCell),
123+
'Conv2dLSTMCell': ('brainpy.layers.Conv2dLSTMCell', 'brainpy.dyn.Conv2dLSTMCell', dyn.Conv2dLSTMCell),
124+
'Conv3dLSTMCell': ('brainpy.layers.Conv3dLSTMCell', 'brainpy.dyn.Conv3dLSTMCell', dyn.Conv3dLSTMCell),
125+
}
126+
layers.__getattr__ = deprecation_getattr2('brainpy.layers', layers.__deprecations)
127+
104128

105129
connect.__deprecations = {
106130
'one2one': ('brainpy.connect.one2one', 'brainpy.connect.One2One', connect.One2One),

brainpy/_src/dnn/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
from .base import *
44
from .activations import *
55
from .dropout import *
6-
from .nvar import *
7-
from .reservoir import *
8-
from .rnncells import *
96
from .conv import *
107
from .normalization import *
118
from .pooling import *

brainpy/_src/dyn/rates/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
# -*- coding: utf-8 -*-
22

33
from .populations import *
4+
from .reservoir import *
5+
from .nvar import *
6+
from .rnncells import *
7+
8+
File renamed without changes.

brainpy/_src/dnn/reservoir.py renamed to brainpy/_src/dyn/rates/reservoir.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717

1818

1919
class Reservoir(Layer):
20-
r"""Reservoir node, a pool of leaky-integrator neurons
21-
with random recurrent connections [1]_.
20+
r"""Reservoir node, a pool of leaky-integrator neurons with random recurrent connections [1]_.
2221
2322
Parameters
2423
----------
@@ -81,8 +80,6 @@ class Reservoir(Layer):
8180
Distribution of noise. Must be a random variable generator
8281
distribution (see :py:class:`brainpy.math.random.RandomState`),
8382
by default "normal".
84-
seed: optional, int
85-
The seed for random sampling in this node.
8683
8784
References
8885
----------
@@ -107,7 +104,6 @@ def __init__(
107104
noise_in: float = 0.,
108105
noise_rec: float = 0.,
109106
noise_type: str = 'normal',
110-
seed: Optional[int] = None,
111107
mode: Optional[bm.Mode] = None,
112108
name: Optional[str] = None
113109
):

brainpy/_src/dnn/rnncells.py renamed to brainpy/_src/dyn/rates/rnncells.py

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@
1818
variable_,
1919
Initializer)
2020
from brainpy.types import ArrayType
21-
from .conv import _GeneralConv
21+
from brainpy._src.dnn.conv import _GeneralConv
22+
2223

2324
__all__ = [
2425
'RNNCell', 'GRUCell', 'LSTMCell',
2526
'Conv1dLSTMCell', 'Conv2dLSTMCell', 'Conv3dLSTMCell',
26-
# deprecated
27-
'VanillaRNN', 'GRU', 'LSTM',
2827
]
2928

3029

@@ -404,50 +403,6 @@ def c(self, value):
404403
self.state[self.state.shape[0] // 2:, :] = value
405404

406405

407-
class VanillaRNN(RNNCell):
408-
"""Vanilla RNN.
409-
410-
.. deprecated:: 2.2.3.4
411-
Use :py:class:`~.RNNCell` instead. :py:class:`~.VanillaRNN` will be removed since version 2.4.0.
412-
413-
"""
414-
415-
def __init__(self, *args, **kwargs):
416-
super(VanillaRNN, self).__init__(*args, **kwargs)
417-
warnings.warn('Use "brainpy.layers.RNNCell" instead. '
418-
'"brainpy.layers.VanillaRNN" is deprecated and will be removed since 2.4.0.',
419-
UserWarning)
420-
421-
422-
class GRU(GRUCell):
423-
"""GRU.
424-
425-
.. deprecated:: 2.2.3.4
426-
Use :py:class:`~.GRUCell` instead. :py:class:`~.GRU` will be removed since version 2.4.0.
427-
428-
"""
429-
430-
def __init__(self, *args, **kwargs):
431-
super(GRU, self).__init__(*args, **kwargs)
432-
warnings.warn('Use "brainpy.layers.GRUCell" instead. '
433-
'"brainpy.layers.GRU" is deprecated and will be removed since 2.4.0.',
434-
UserWarning)
435-
436-
437-
class LSTM(LSTMCell):
438-
"""LSTM.
439-
440-
.. deprecated:: 2.2.3.4
441-
Use :py:class:`~.LSTMCell` instead. :py:class:`~.LSTM` will be removed since version 2.4.0.
442-
443-
"""
444-
445-
def __init__(self, *args, **kwargs):
446-
warnings.warn('Use "brainpy.layers.LSTMCell" instead. '
447-
'"brainpy.layers.LSTM" is deprecated and will be removed since 2.4.0.',
448-
UserWarning)
449-
super(LSTM, self).__init__(*args, **kwargs)
450-
451406

452407
class _ConvNDLSTMCell(Layer):
453408
r"""``num_spatial_dims``-D convolutional LSTM.
File renamed without changes.

brainpy/_src/dnn/tests/test_reservoir.py renamed to brainpy/_src/dyn/rates/tests/test_reservoir.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@ class Test_Reservoir(parameterized.TestCase):
1212
bm.BatchingMode(10),
1313
bm.NonBatchingMode()]
1414
)
15-
def test_Reservoir(self,mode):
15+
def test_Reservoir(self, mode):
1616
bm.random.seed()
17-
input=bm.random.randn(10,3)
18-
layer=bp.dnn.Reservoir(input_shape=3,
19-
num_out=5,
20-
mode=mode)
17+
input = bm.random.randn(10, 3)
18+
layer = bp.dnn.Reservoir(input_shape=3,
19+
num_out=5,
20+
mode=mode)
2121
if mode in [bm.NonBatchingMode()]:
2222
for i in input:
23-
output=layer(i)
23+
output = layer(i)
2424
else:
25-
output=layer(input)
25+
output = layer(input)
26+
2627

2728
if __name__ == '__main__':
2829
absltest.main()

brainpy/dnn/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@
66
from .normalization import *
77
from .others import *
88
from .pooling import *
9-
from .recurrent import *

0 commit comments

Comments
 (0)