brainstate 0.1.10__py2.py3-none-any.whl → 0.2.1__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- brainstate/__init__.py +169 -58
- brainstate/_compatible_import.py +340 -148
- brainstate/_compatible_import_test.py +681 -0
- brainstate/_deprecation.py +210 -0
- brainstate/_deprecation_test.py +2319 -0
- brainstate/{util/error.py → _error.py} +45 -55
- brainstate/_state.py +1652 -1605
- brainstate/_state_test.py +52 -52
- brainstate/_utils.py +47 -47
- brainstate/environ.py +1495 -563
- brainstate/environ_test.py +1223 -62
- brainstate/graph/__init__.py +22 -29
- brainstate/graph/_node.py +240 -0
- brainstate/graph/_node_test.py +589 -0
- brainstate/graph/{_graph_operation.py → _operation.py} +1624 -1738
- brainstate/graph/_operation_test.py +1147 -0
- brainstate/mixin.py +1433 -365
- brainstate/mixin_test.py +1017 -77
- brainstate/nn/__init__.py +137 -135
- brainstate/nn/_activations.py +1100 -808
- brainstate/nn/_activations_test.py +354 -331
- brainstate/nn/_collective_ops.py +633 -514
- brainstate/nn/_collective_ops_test.py +774 -43
- brainstate/nn/_common.py +226 -178
- brainstate/nn/_common_test.py +154 -0
- brainstate/nn/_conv.py +2010 -501
- brainstate/nn/_conv_test.py +849 -238
- brainstate/nn/_delay.py +575 -588
- brainstate/nn/_delay_test.py +243 -238
- brainstate/nn/_dropout.py +618 -426
- brainstate/nn/_dropout_test.py +477 -100
- brainstate/nn/_dynamics.py +1267 -1343
- brainstate/nn/_dynamics_test.py +67 -78
- brainstate/nn/_elementwise.py +1298 -1119
- brainstate/nn/_elementwise_test.py +830 -169
- brainstate/nn/_embedding.py +408 -58
- brainstate/nn/_embedding_test.py +156 -0
- brainstate/nn/{_fixedprob.py → _event_fixedprob.py} +233 -239
- brainstate/nn/{_fixedprob_test.py → _event_fixedprob_test.py} +115 -114
- brainstate/nn/{_linear_mv.py → _event_linear.py} +83 -83
- brainstate/nn/{_linear_mv_test.py → _event_linear_test.py} +121 -120
- brainstate/nn/_exp_euler.py +254 -92
- brainstate/nn/_exp_euler_test.py +377 -35
- brainstate/nn/_linear.py +744 -424
- brainstate/nn/_linear_test.py +475 -107
- brainstate/nn/_metrics.py +1070 -0
- brainstate/nn/_metrics_test.py +611 -0
- brainstate/nn/_module.py +384 -377
- brainstate/nn/_module_test.py +40 -40
- brainstate/nn/_normalizations.py +1334 -975
- brainstate/nn/_normalizations_test.py +699 -73
- brainstate/nn/_paddings.py +1020 -0
- brainstate/nn/_paddings_test.py +723 -0
- brainstate/nn/_poolings.py +2239 -1177
- brainstate/nn/_poolings_test.py +953 -217
- brainstate/nn/{_rate_rnns.py → _rnns.py} +946 -554
- brainstate/nn/_rnns_test.py +593 -0
- brainstate/nn/_utils.py +216 -89
- brainstate/nn/_utils_test.py +402 -0
- brainstate/{init/_random_inits.py → nn/init.py} +809 -553
- brainstate/{init/_random_inits_test.py → nn/init_test.py} +180 -149
- brainstate/random/__init__.py +270 -24
- brainstate/random/_rand_funs.py +3938 -3616
- brainstate/random/_rand_funs_test.py +640 -567
- brainstate/random/_rand_seed.py +675 -210
- brainstate/random/_rand_seed_test.py +48 -48
- brainstate/random/_rand_state.py +1617 -1409
- brainstate/random/_rand_state_test.py +551 -0
- brainstate/transform/__init__.py +59 -0
- brainstate/transform/_ad_checkpoint.py +176 -0
- brainstate/{compile → transform}/_ad_checkpoint_test.py +49 -49
- brainstate/{augment → transform}/_autograd.py +1025 -778
- brainstate/{augment → transform}/_autograd_test.py +1289 -1289
- brainstate/transform/_conditions.py +316 -0
- brainstate/{compile → transform}/_conditions_test.py +220 -220
- brainstate/{compile → transform}/_error_if.py +94 -92
- brainstate/{compile → transform}/_error_if_test.py +52 -52
- brainstate/transform/_eval_shape.py +145 -0
- brainstate/{augment → transform}/_eval_shape_test.py +38 -38
- brainstate/{compile → transform}/_jit.py +399 -346
- brainstate/{compile → transform}/_jit_test.py +143 -143
- brainstate/{compile → transform}/_loop_collect_return.py +675 -536
- brainstate/{compile → transform}/_loop_collect_return_test.py +58 -58
- brainstate/{compile → transform}/_loop_no_collection.py +283 -184
- brainstate/{compile → transform}/_loop_no_collection_test.py +50 -50
- brainstate/transform/_make_jaxpr.py +2016 -0
- brainstate/transform/_make_jaxpr_test.py +1510 -0
- brainstate/transform/_mapping.py +529 -0
- brainstate/transform/_mapping_test.py +194 -0
- brainstate/{compile → transform}/_progress_bar.py +255 -202
- brainstate/{augment → transform}/_random.py +171 -151
- brainstate/{compile → transform}/_unvmap.py +256 -159
- brainstate/transform/_util.py +286 -0
- brainstate/typing.py +837 -304
- brainstate/typing_test.py +780 -0
- brainstate/util/__init__.py +27 -50
- brainstate/util/_others.py +1025 -0
- brainstate/util/_others_test.py +962 -0
- brainstate/util/_pretty_pytree.py +1301 -0
- brainstate/util/_pretty_pytree_test.py +675 -0
- brainstate/util/{pretty_repr.py → _pretty_repr.py} +462 -328
- brainstate/util/_pretty_repr_test.py +696 -0
- brainstate/util/filter.py +945 -469
- brainstate/util/filter_test.py +912 -0
- brainstate/util/struct.py +910 -523
- brainstate/util/struct_test.py +602 -0
- {brainstate-0.1.10.dist-info → brainstate-0.2.1.dist-info}/METADATA +108 -91
- brainstate-0.2.1.dist-info/RECORD +111 -0
- {brainstate-0.1.10.dist-info → brainstate-0.2.1.dist-info}/licenses/LICENSE +202 -202
- brainstate/augment/__init__.py +0 -30
- brainstate/augment/_eval_shape.py +0 -99
- brainstate/augment/_mapping.py +0 -1060
- brainstate/augment/_mapping_test.py +0 -597
- brainstate/compile/__init__.py +0 -38
- brainstate/compile/_ad_checkpoint.py +0 -204
- brainstate/compile/_conditions.py +0 -256
- brainstate/compile/_make_jaxpr.py +0 -888
- brainstate/compile/_make_jaxpr_test.py +0 -156
- brainstate/compile/_util.py +0 -147
- brainstate/functional/__init__.py +0 -27
- brainstate/graph/_graph_node.py +0 -244
- brainstate/graph/_graph_node_test.py +0 -73
- brainstate/graph/_graph_operation_test.py +0 -563
- brainstate/init/__init__.py +0 -26
- brainstate/init/_base.py +0 -52
- brainstate/init/_generic.py +0 -244
- brainstate/init/_regular_inits.py +0 -105
- brainstate/init/_regular_inits_test.py +0 -50
- brainstate/nn/_inputs.py +0 -608
- brainstate/nn/_ltp.py +0 -28
- brainstate/nn/_neuron.py +0 -705
- brainstate/nn/_neuron_test.py +0 -161
- brainstate/nn/_others.py +0 -46
- brainstate/nn/_projection.py +0 -486
- brainstate/nn/_rate_rnns_test.py +0 -63
- brainstate/nn/_readout.py +0 -209
- brainstate/nn/_readout_test.py +0 -53
- brainstate/nn/_stp.py +0 -236
- brainstate/nn/_synapse.py +0 -505
- brainstate/nn/_synapse_test.py +0 -131
- brainstate/nn/_synaptic_projection.py +0 -423
- brainstate/nn/_synouts.py +0 -162
- brainstate/nn/_synouts_test.py +0 -57
- brainstate/nn/metrics.py +0 -388
- brainstate/optim/__init__.py +0 -38
- brainstate/optim/_base.py +0 -64
- brainstate/optim/_lr_scheduler.py +0 -448
- brainstate/optim/_lr_scheduler_test.py +0 -50
- brainstate/optim/_optax_optimizer.py +0 -152
- brainstate/optim/_optax_optimizer_test.py +0 -53
- brainstate/optim/_sgd_optimizer.py +0 -1104
- brainstate/random/_random_for_unit.py +0 -52
- brainstate/surrogate.py +0 -1957
- brainstate/transform.py +0 -23
- brainstate/util/caller.py +0 -98
- brainstate/util/others.py +0 -540
- brainstate/util/pretty_pytree.py +0 -945
- brainstate/util/pretty_pytree_test.py +0 -159
- brainstate/util/pretty_table.py +0 -2954
- brainstate/util/scaling.py +0 -258
- brainstate-0.1.10.dist-info/RECORD +0 -130
- {brainstate-0.1.10.dist-info → brainstate-0.2.1.dist-info}/WHEEL +0 -0
- {brainstate-0.1.10.dist-info → brainstate-0.2.1.dist-info}/top_level.txt +0 -0
@@ -1,567 +1,640 @@
|
|
1
|
-
# Copyright 2024
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
-
# you may not use this file except in compliance with the License.
|
5
|
-
# You may obtain a copy of the License at
|
6
|
-
#
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
#
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
# See the License for the specific language governing permissions and
|
13
|
-
# limitations under the License.
|
14
|
-
# ==============================================================================
|
15
|
-
|
16
|
-
|
17
|
-
import platform
|
18
|
-
import unittest
|
19
|
-
|
20
|
-
import jax.numpy as jnp
|
21
|
-
import jax.random as jr
|
22
|
-
import numpy as np
|
23
|
-
import pytest
|
24
|
-
|
25
|
-
import brainstate
|
26
|
-
|
27
|
-
|
28
|
-
class
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
self.
|
57
|
-
self.assertTrue((
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
self.
|
64
|
-
|
65
|
-
def
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
self.
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
self.
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
self.
|
91
|
-
self.assertTrue(0 <=
|
92
|
-
|
93
|
-
|
94
|
-
brainstate.random.
|
95
|
-
|
96
|
-
self.
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
brainstate.random.
|
122
|
-
|
123
|
-
self.
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
brainstate.random.
|
129
|
-
self.assertTupleEqual(a.shape, (
|
130
|
-
self.
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
a
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
brainstate.random.
|
163
|
-
|
164
|
-
self.
|
165
|
-
|
166
|
-
def
|
167
|
-
brainstate.random.seed()
|
168
|
-
a = brainstate.random.
|
169
|
-
self.assertTupleEqual(a.shape, (3,
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
brainstate.random.
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
self.assertTupleEqual(a.shape, (
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
self.
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
brainstate.random.
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
brainstate.random.
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
brainstate.random.
|
252
|
-
a
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
self.
|
279
|
-
|
280
|
-
def
|
281
|
-
brainstate.random.seed()
|
282
|
-
a = brainstate.random.
|
283
|
-
self.assertTupleEqual(a.shape, (3, 2))
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
brainstate.random.
|
288
|
-
a
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
brainstate.random.
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
brainstate.random.
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
brainstate.random.
|
303
|
-
a
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
brainstate.random.
|
344
|
-
a
|
345
|
-
self.
|
346
|
-
|
347
|
-
def
|
348
|
-
brainstate.random.seed()
|
349
|
-
a = brainstate.random.
|
350
|
-
self.assertTupleEqual(a.shape, (
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
def
|
375
|
-
brainstate.random.seed()
|
376
|
-
a = brainstate.random.
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
brainstate.random.
|
386
|
-
a
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
self.
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
self.assertTupleEqual(a.shape, (
|
409
|
-
|
410
|
-
def
|
411
|
-
brainstate.random.seed()
|
412
|
-
a =
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
a
|
464
|
-
self.assertTupleEqual(
|
465
|
-
|
466
|
-
def
|
467
|
-
brainstate.random.seed()
|
468
|
-
a = brainstate.random.
|
469
|
-
self.assertTupleEqual(a.shape, (
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
a
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
brainstate.random.
|
496
|
-
a
|
497
|
-
b
|
498
|
-
self.assertTupleEqual(a.shape, b.shape)
|
499
|
-
self.assertTupleEqual(b.shape, (
|
500
|
-
|
501
|
-
def
|
502
|
-
brainstate.random.seed()
|
503
|
-
a =
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
self.assertTupleEqual(a.shape,
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
1
|
+
# Copyright 2024 BrainX Ecosystem Limited. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
# ==============================================================================
|
15
|
+
|
16
|
+
|
17
|
+
import platform
|
18
|
+
import unittest
|
19
|
+
|
20
|
+
import jax.numpy as jnp
|
21
|
+
import jax.random as jr
|
22
|
+
import numpy as np
|
23
|
+
import pytest
|
24
|
+
|
25
|
+
import brainstate
|
26
|
+
|
27
|
+
|
28
|
+
class TestRandomExamples(unittest.TestCase):
|
29
|
+
"""Test cases that demonstrate usage examples from docstrings."""
|
30
|
+
|
31
|
+
def test_rand_examples(self):
|
32
|
+
"""Test examples from rand function docstring."""
|
33
|
+
# Generate random values in a 3x2 array
|
34
|
+
arr = brainstate.random.rand(3, 2)
|
35
|
+
self.assertEqual(arr.shape, (3, 2))
|
36
|
+
self.assertTrue((arr >= 0).all() and (arr < 1).all())
|
37
|
+
|
38
|
+
def test_randint_examples(self):
|
39
|
+
"""Test examples from randint function docstring."""
|
40
|
+
# Generate 10 random integers from 0 to 1 (exclusive)
|
41
|
+
arr = brainstate.random.randint(2, size=10)
|
42
|
+
self.assertEqual(arr.shape, (10,))
|
43
|
+
self.assertTrue((arr >= 0).all() and (arr < 2).all())
|
44
|
+
|
45
|
+
# Generate a 2x4 array of integers from 0 to 4 (exclusive)
|
46
|
+
arr = brainstate.random.randint(5, size=(2, 4))
|
47
|
+
self.assertEqual(arr.shape, (2, 4))
|
48
|
+
self.assertTrue((arr >= 0).all() and (arr < 5).all())
|
49
|
+
|
50
|
+
# Generate integers with different upper bounds using broadcasting
|
51
|
+
arr = brainstate.random.randint(1, [3, 5, 10])
|
52
|
+
self.assertEqual(arr.shape, (3,))
|
53
|
+
|
54
|
+
# Generate integers with different lower bounds
|
55
|
+
arr = brainstate.random.randint([1, 5, 7], 10)
|
56
|
+
self.assertEqual(arr.shape, (3,))
|
57
|
+
self.assertTrue((arr >= jnp.array([1, 5, 7])).all())
|
58
|
+
|
59
|
+
def test_randn_examples(self):
|
60
|
+
"""Test examples from randn function docstring."""
|
61
|
+
# Generate standard normal distributed values
|
62
|
+
arr = brainstate.random.randn(3, 2)
|
63
|
+
self.assertEqual(arr.shape, (3, 2))
|
64
|
+
|
65
|
+
def test_choice_examples(self):
|
66
|
+
"""Test examples from choice function docstring."""
|
67
|
+
# Choose from range
|
68
|
+
result = brainstate.random.choice(5)
|
69
|
+
self.assertTrue(0 <= result < 5)
|
70
|
+
|
71
|
+
# Choose multiple with probabilities
|
72
|
+
arr = brainstate.random.choice(5, 3, p=[0.1, 0.4, 0.2, 0.0, 0.3])
|
73
|
+
self.assertEqual(arr.shape, (3,))
|
74
|
+
self.assertTrue((arr >= 0).all() and (arr < 5).all())
|
75
|
+
|
76
|
+
def test_normal_examples(self):
|
77
|
+
"""Test examples from normal function docstring."""
|
78
|
+
# Standard normal
|
79
|
+
result = brainstate.random.normal()
|
80
|
+
self.assertEqual(result.shape, ())
|
81
|
+
|
82
|
+
# With different parameters
|
83
|
+
arr = brainstate.random.normal(loc=0.0, scale=1.0, size=(2, 3))
|
84
|
+
self.assertEqual(arr.shape, (2, 3))
|
85
|
+
|
86
|
+
def test_uniform_examples(self):
|
87
|
+
"""Test examples from uniform function docstring."""
|
88
|
+
# Standard uniform
|
89
|
+
result = brainstate.random.uniform()
|
90
|
+
self.assertEqual(result.shape, ())
|
91
|
+
self.assertTrue(0.0 <= result < 1.0)
|
92
|
+
|
93
|
+
# With custom range
|
94
|
+
arr = brainstate.random.uniform(low=2.0, high=5.0, size=(3, 2))
|
95
|
+
self.assertEqual(arr.shape, (3, 2))
|
96
|
+
self.assertTrue((arr >= 2.0).all() and (arr < 5.0).all())
|
97
|
+
|
98
|
+
|
99
|
+
class TestRandom(unittest.TestCase):
|
100
|
+
def setUp(self):
|
101
|
+
brainstate.environ.set(precision=32)
|
102
|
+
|
103
|
+
def test_rand(self):
|
104
|
+
brainstate.random.seed()
|
105
|
+
a = brainstate.random.rand(3, 2)
|
106
|
+
self.assertTupleEqual(a.shape, (3, 2))
|
107
|
+
self.assertTrue((a >= 0).all() and (a < 1).all())
|
108
|
+
|
109
|
+
key = jr.PRNGKey(123)
|
110
|
+
jres = jr.uniform(key, shape=(10, 100))
|
111
|
+
self.assertTrue(jnp.allclose(jres, brainstate.random.rand(10, 100, key=key)))
|
112
|
+
self.assertTrue(jnp.allclose(jres, brainstate.random.rand(10, 100, key=123)))
|
113
|
+
|
114
|
+
def test_randint1(self):
|
115
|
+
brainstate.random.seed()
|
116
|
+
a = brainstate.random.randint(5)
|
117
|
+
self.assertTupleEqual(a.shape, ())
|
118
|
+
self.assertTrue(0 <= a < 5)
|
119
|
+
|
120
|
+
def test_randint2(self):
|
121
|
+
brainstate.random.seed()
|
122
|
+
a = brainstate.random.randint(2, 6, size=(4, 3))
|
123
|
+
self.assertTupleEqual(a.shape, (4, 3))
|
124
|
+
self.assertTrue((a >= 2).all() and (a < 6).all())
|
125
|
+
|
126
|
+
def test_randint3(self):
|
127
|
+
brainstate.random.seed()
|
128
|
+
a = brainstate.random.randint([1, 2, 3], [10, 7, 8])
|
129
|
+
self.assertTupleEqual(a.shape, (3,))
|
130
|
+
self.assertTrue((a - jnp.array([1, 2, 3]) >= 0).all()
|
131
|
+
and (-a + jnp.array([10, 7, 8]) > 0).all())
|
132
|
+
|
133
|
+
def test_randint4(self):
|
134
|
+
brainstate.random.seed()
|
135
|
+
a = brainstate.random.randint([1, 2, 3], [10, 7, 8], size=(2, 3))
|
136
|
+
self.assertTupleEqual(a.shape, (2, 3))
|
137
|
+
|
138
|
+
def test_randn(self):
|
139
|
+
brainstate.random.seed()
|
140
|
+
a = brainstate.random.randn(3, 2)
|
141
|
+
self.assertTupleEqual(a.shape, (3, 2))
|
142
|
+
|
143
|
+
def test_random1(self):
|
144
|
+
brainstate.random.seed()
|
145
|
+
a = brainstate.random.random()
|
146
|
+
self.assertTrue(0. <= a < 1)
|
147
|
+
|
148
|
+
def test_random2(self):
|
149
|
+
brainstate.random.seed()
|
150
|
+
a = brainstate.random.random(size=(3, 2))
|
151
|
+
self.assertTupleEqual(a.shape, (3, 2))
|
152
|
+
self.assertTrue((a >= 0).all() and (a < 1).all())
|
153
|
+
|
154
|
+
def test_random_sample(self):
|
155
|
+
brainstate.random.seed()
|
156
|
+
a = brainstate.random.random_sample(size=(3, 2))
|
157
|
+
self.assertTupleEqual(a.shape, (3, 2))
|
158
|
+
self.assertTrue((a >= 0).all() and (a < 1).all())
|
159
|
+
|
160
|
+
def test_choice1(self):
|
161
|
+
brainstate.random.seed()
|
162
|
+
a = brainstate.random.choice(5)
|
163
|
+
self.assertTupleEqual(jnp.shape(a), ())
|
164
|
+
self.assertTrue(0 <= a < 5)
|
165
|
+
|
166
|
+
def test_choice2(self):
|
167
|
+
brainstate.random.seed()
|
168
|
+
a = brainstate.random.choice(5, 3, p=[0.1, 0.4, 0.2, 0., 0.3])
|
169
|
+
self.assertTupleEqual(a.shape, (3,))
|
170
|
+
self.assertTrue((a >= 0).all() and (a < 5).all())
|
171
|
+
|
172
|
+
def test_choice3(self):
|
173
|
+
brainstate.random.seed()
|
174
|
+
a = brainstate.random.choice(jnp.arange(2, 20), size=(4, 3), replace=False)
|
175
|
+
self.assertTupleEqual(a.shape, (4, 3))
|
176
|
+
self.assertTrue((a >= 2).all() and (a < 20).all())
|
177
|
+
self.assertEqual(len(jnp.unique(a)), 12)
|
178
|
+
|
179
|
+
def test_permutation1(self):
|
180
|
+
brainstate.random.seed()
|
181
|
+
a = brainstate.random.permutation(10)
|
182
|
+
self.assertTupleEqual(a.shape, (10,))
|
183
|
+
self.assertEqual(len(jnp.unique(a)), 10)
|
184
|
+
|
185
|
+
def test_permutation2(self):
|
186
|
+
brainstate.random.seed()
|
187
|
+
a = brainstate.random.permutation(jnp.arange(10))
|
188
|
+
self.assertTupleEqual(a.shape, (10,))
|
189
|
+
self.assertEqual(len(jnp.unique(a)), 10)
|
190
|
+
|
191
|
+
def test_shuffle1(self):
|
192
|
+
brainstate.random.seed()
|
193
|
+
a = jnp.arange(10)
|
194
|
+
brainstate.random.shuffle(a)
|
195
|
+
self.assertTupleEqual(a.shape, (10,))
|
196
|
+
self.assertEqual(len(jnp.unique(a)), 10)
|
197
|
+
|
198
|
+
def test_shuffle2(self):
|
199
|
+
brainstate.random.seed()
|
200
|
+
a = jnp.arange(12).reshape(4, 3)
|
201
|
+
brainstate.random.shuffle(a, axis=1)
|
202
|
+
self.assertTupleEqual(a.shape, (4, 3))
|
203
|
+
self.assertEqual(len(jnp.unique(a)), 12)
|
204
|
+
|
205
|
+
# test that a is only shuffled along axis 1
|
206
|
+
uni = jnp.unique(jnp.diff(a, axis=0))
|
207
|
+
self.assertEqual(uni, jnp.asarray([3]))
|
208
|
+
|
209
|
+
def test_beta1(self):
|
210
|
+
brainstate.random.seed()
|
211
|
+
a = brainstate.random.beta(2, 2)
|
212
|
+
self.assertTupleEqual(a.shape, ())
|
213
|
+
|
214
|
+
def test_beta2(self):
|
215
|
+
brainstate.random.seed()
|
216
|
+
a = brainstate.random.beta([2, 2, 3], 2, size=(3,))
|
217
|
+
self.assertTupleEqual(a.shape, (3,))
|
218
|
+
|
219
|
+
def test_exponential1(self):
|
220
|
+
brainstate.random.seed()
|
221
|
+
a = brainstate.random.exponential(10., size=[3, 2])
|
222
|
+
self.assertTupleEqual(a.shape, (3, 2))
|
223
|
+
|
224
|
+
def test_exponential2(self):
|
225
|
+
brainstate.random.seed()
|
226
|
+
a = brainstate.random.exponential([1., 2., 5.])
|
227
|
+
self.assertTupleEqual(a.shape, (3,))
|
228
|
+
|
229
|
+
def test_gamma(self):
|
230
|
+
brainstate.random.seed()
|
231
|
+
a = brainstate.random.gamma(2, 10., size=[3, 2])
|
232
|
+
self.assertTupleEqual(a.shape, (3, 2))
|
233
|
+
|
234
|
+
def test_gumbel(self):
|
235
|
+
brainstate.random.seed()
|
236
|
+
a = brainstate.random.gumbel(0., 2., size=[3, 2])
|
237
|
+
self.assertTupleEqual(a.shape, (3, 2))
|
238
|
+
|
239
|
+
def test_laplace(self):
|
240
|
+
brainstate.random.seed()
|
241
|
+
a = brainstate.random.laplace(0., 2., size=[3, 2])
|
242
|
+
self.assertTupleEqual(a.shape, (3, 2))
|
243
|
+
|
244
|
+
def test_logistic(self):
|
245
|
+
brainstate.random.seed()
|
246
|
+
a = brainstate.random.logistic(0., 2., size=[3, 2])
|
247
|
+
self.assertTupleEqual(a.shape, (3, 2))
|
248
|
+
|
249
|
+
def test_normal1(self):
|
250
|
+
brainstate.random.seed()
|
251
|
+
a = brainstate.random.normal()
|
252
|
+
self.assertTupleEqual(a.shape, ())
|
253
|
+
|
254
|
+
def test_normal2(self):
|
255
|
+
brainstate.random.seed()
|
256
|
+
a = brainstate.random.normal(loc=[0., 2., 4.], scale=[1., 2., 3.])
|
257
|
+
self.assertTupleEqual(a.shape, (3,))
|
258
|
+
|
259
|
+
def test_normal3(self):
|
260
|
+
brainstate.random.seed()
|
261
|
+
a = brainstate.random.normal(loc=[0., 2., 4.], scale=[[1., 2., 3.], [1., 1., 1.]])
|
262
|
+
print(a)
|
263
|
+
self.assertTupleEqual(a.shape, (2, 3))
|
264
|
+
|
265
|
+
def test_pareto(self):
|
266
|
+
brainstate.random.seed()
|
267
|
+
a = brainstate.random.pareto([1, 2, 2])
|
268
|
+
self.assertTupleEqual(a.shape, (3,))
|
269
|
+
|
270
|
+
def test_poisson(self):
|
271
|
+
brainstate.random.seed()
|
272
|
+
a = brainstate.random.poisson([1., 2., 2.], size=3)
|
273
|
+
self.assertTupleEqual(a.shape, (3,))
|
274
|
+
|
275
|
+
def test_standard_cauchy(self):
|
276
|
+
brainstate.random.seed()
|
277
|
+
a = brainstate.random.standard_cauchy(size=(3, 2))
|
278
|
+
self.assertTupleEqual(a.shape, (3, 2))
|
279
|
+
|
280
|
+
def test_standard_exponential(self):
|
281
|
+
brainstate.random.seed()
|
282
|
+
a = brainstate.random.standard_exponential(size=(3, 2))
|
283
|
+
self.assertTupleEqual(a.shape, (3, 2))
|
284
|
+
|
285
|
+
def test_standard_gamma(self):
|
286
|
+
brainstate.random.seed()
|
287
|
+
a = brainstate.random.standard_gamma(shape=[1, 2, 4], size=3)
|
288
|
+
self.assertTupleEqual(a.shape, (3,))
|
289
|
+
|
290
|
+
def test_standard_normal(self):
|
291
|
+
brainstate.random.seed()
|
292
|
+
a = brainstate.random.standard_normal(size=(3, 2))
|
293
|
+
self.assertTupleEqual(a.shape, (3, 2))
|
294
|
+
|
295
|
+
def test_standard_t(self):
|
296
|
+
brainstate.random.seed()
|
297
|
+
a = brainstate.random.standard_t(df=[1, 2, 4], size=3)
|
298
|
+
self.assertTupleEqual(a.shape, (3,))
|
299
|
+
|
300
|
+
def test_standard_uniform1(self):
|
301
|
+
brainstate.random.seed()
|
302
|
+
a = brainstate.random.uniform()
|
303
|
+
self.assertTupleEqual(a.shape, ())
|
304
|
+
self.assertTrue(0 <= a < 1)
|
305
|
+
|
306
|
+
def test_uniform2(self):
|
307
|
+
brainstate.random.seed()
|
308
|
+
a = brainstate.random.uniform(low=[-1., 5., 2.], high=[2., 6., 10.], size=3)
|
309
|
+
self.assertTupleEqual(a.shape, (3,))
|
310
|
+
self.assertTrue((a - jnp.array([-1., 5., 2.]) >= 0).all()
|
311
|
+
and (-a + jnp.array([2., 6., 10.]) > 0).all())
|
312
|
+
|
313
|
+
def test_uniform3(self):
|
314
|
+
brainstate.random.seed()
|
315
|
+
a = brainstate.random.uniform(low=-1., high=[2., 6., 10.], size=(2, 3))
|
316
|
+
self.assertTupleEqual(a.shape, (2, 3))
|
317
|
+
|
318
|
+
def test_uniform4(self):
|
319
|
+
brainstate.random.seed()
|
320
|
+
a = brainstate.random.uniform(low=[-1., 5., 2.], high=[[2., 6., 10.], [10., 10., 10.]])
|
321
|
+
self.assertTupleEqual(a.shape, (2, 3))
|
322
|
+
|
323
|
+
def test_truncated_normal1(self):
|
324
|
+
brainstate.random.seed()
|
325
|
+
a = brainstate.random.truncated_normal(-1., 1.)
|
326
|
+
self.assertTupleEqual(a.shape, ())
|
327
|
+
self.assertTrue(-1. <= a <= 1.)
|
328
|
+
|
329
|
+
def test_truncated_normal2(self):
|
330
|
+
brainstate.random.seed()
|
331
|
+
a = brainstate.random.truncated_normal(-1., [1., 2., 1.], size=(4, 3))
|
332
|
+
self.assertTupleEqual(a.shape, (4, 3))
|
333
|
+
|
334
|
+
def test_truncated_normal3(self):
|
335
|
+
brainstate.random.seed()
|
336
|
+
a = brainstate.random.truncated_normal([-1., 0., 1.], [[2., 2., 4.], [2., 2., 4.]])
|
337
|
+
self.assertTupleEqual(a.shape, (2, 3))
|
338
|
+
self.assertTrue((a - jnp.array([-1., 0., 1.]) >= 0.).all()
|
339
|
+
and (- a + jnp.array([2., 2., 4.]) >= 0.).all())
|
340
|
+
|
341
|
+
def test_bernoulli1(self):
|
342
|
+
brainstate.random.seed()
|
343
|
+
a = brainstate.random.bernoulli()
|
344
|
+
self.assertTupleEqual(a.shape, ())
|
345
|
+
self.assertTrue(a == 0 or a == 1)
|
346
|
+
|
347
|
+
def test_bernoulli2(self):
|
348
|
+
brainstate.random.seed()
|
349
|
+
a = brainstate.random.bernoulli([0.5, 0.6, 0.8])
|
350
|
+
self.assertTupleEqual(a.shape, (3,))
|
351
|
+
self.assertTrue(jnp.logical_xor(a == 1, a == 0).all())
|
352
|
+
|
353
|
+
def test_bernoulli3(self):
|
354
|
+
brainstate.random.seed()
|
355
|
+
a = brainstate.random.bernoulli([0.5, 0.6], size=(3, 2))
|
356
|
+
self.assertTupleEqual(a.shape, (3, 2))
|
357
|
+
self.assertTrue(jnp.logical_xor(a == 1, a == 0).all())
|
358
|
+
|
359
|
+
def test_lognormal1(self):
|
360
|
+
brainstate.random.seed()
|
361
|
+
a = brainstate.random.lognormal()
|
362
|
+
self.assertTupleEqual(a.shape, ())
|
363
|
+
|
364
|
+
def test_lognormal2(self):
|
365
|
+
brainstate.random.seed()
|
366
|
+
a = brainstate.random.lognormal(sigma=[2., 1.], size=[3, 2])
|
367
|
+
self.assertTupleEqual(a.shape, (3, 2))
|
368
|
+
|
369
|
+
def test_lognormal3(self):
|
370
|
+
brainstate.random.seed()
|
371
|
+
a = brainstate.random.lognormal([2., 0.], [[2., 1.], [3., 1.2]])
|
372
|
+
self.assertTupleEqual(a.shape, (2, 2))
|
373
|
+
|
374
|
+
def test_binomial1(self):
|
375
|
+
brainstate.random.seed()
|
376
|
+
a = brainstate.random.binomial(5, 0.5)
|
377
|
+
b = np.random.binomial(5, 0.5)
|
378
|
+
print(a)
|
379
|
+
print(b)
|
380
|
+
self.assertTupleEqual(a.shape, ())
|
381
|
+
self.assertTrue(a.dtype, int)
|
382
|
+
|
383
|
+
def test_binomial2(self):
|
384
|
+
brainstate.random.seed()
|
385
|
+
a = brainstate.random.binomial(5, 0.5, size=(3, 2))
|
386
|
+
self.assertTupleEqual(a.shape, (3, 2))
|
387
|
+
self.assertTrue((a >= 0).all() and (a <= 5).all())
|
388
|
+
|
389
|
+
def test_binomial3(self):
|
390
|
+
brainstate.random.seed()
|
391
|
+
a = brainstate.random.binomial(n=jnp.asarray([2, 3, 4]), p=jnp.asarray([[0.5, 0.5, 0.5], [0.6, 0.6, 0.6]]))
|
392
|
+
self.assertTupleEqual(a.shape, (2, 3))
|
393
|
+
|
394
|
+
def test_chisquare1(self):
|
395
|
+
brainstate.random.seed()
|
396
|
+
a = brainstate.random.chisquare(3)
|
397
|
+
self.assertTupleEqual(a.shape, ())
|
398
|
+
self.assertTrue(a.dtype, float)
|
399
|
+
|
400
|
+
def test_chisquare2(self):
|
401
|
+
brainstate.random.seed()
|
402
|
+
with self.assertRaises(NotImplementedError):
|
403
|
+
a = brainstate.random.chisquare(df=[2, 3, 4])
|
404
|
+
|
405
|
+
def test_chisquare3(self):
|
406
|
+
brainstate.random.seed()
|
407
|
+
a = brainstate.random.chisquare(df=2, size=100)
|
408
|
+
self.assertTupleEqual(a.shape, (100,))
|
409
|
+
|
410
|
+
def test_chisquare4(self):
|
411
|
+
brainstate.random.seed()
|
412
|
+
a = brainstate.random.chisquare(df=2, size=(100, 10))
|
413
|
+
self.assertTupleEqual(a.shape, (100, 10))
|
414
|
+
|
415
|
+
def test_dirichlet1(self):
|
416
|
+
brainstate.random.seed()
|
417
|
+
a = brainstate.random.dirichlet((10, 5, 3))
|
418
|
+
self.assertTupleEqual(a.shape, (3,))
|
419
|
+
|
420
|
+
def test_dirichlet2(self):
|
421
|
+
brainstate.random.seed()
|
422
|
+
a = brainstate.random.dirichlet((10, 5, 3), 20)
|
423
|
+
self.assertTupleEqual(a.shape, (20, 3))
|
424
|
+
|
425
|
+
def test_f(self):
|
426
|
+
brainstate.random.seed()
|
427
|
+
a = brainstate.random.f(1., 48., 100)
|
428
|
+
self.assertTupleEqual(a.shape, (100,))
|
429
|
+
|
430
|
+
def test_geometric(self):
|
431
|
+
brainstate.random.seed()
|
432
|
+
a = brainstate.random.geometric([0.7, 0.5, 0.2])
|
433
|
+
self.assertTupleEqual(a.shape, (3,))
|
434
|
+
|
435
|
+
def test_hypergeometric1(self):
|
436
|
+
brainstate.random.seed()
|
437
|
+
a = brainstate.random.hypergeometric(10, 10, 10, 20)
|
438
|
+
self.assertTupleEqual(a.shape, (20,))
|
439
|
+
|
440
|
+
@pytest.mark.skipif(platform.system() == 'Windows', reason='Windows jaxlib error')
|
441
|
+
def test_hypergeometric2(self):
|
442
|
+
brainstate.random.seed()
|
443
|
+
a = brainstate.random.hypergeometric(8, [10, 4], [[5, 2], [5, 5]])
|
444
|
+
self.assertTupleEqual(a.shape, (2, 2))
|
445
|
+
|
446
|
+
@pytest.mark.skipif(platform.system() == 'Windows', reason='Windows jaxlib error')
|
447
|
+
def test_hypergeometric3(self):
|
448
|
+
brainstate.random.seed()
|
449
|
+
a = brainstate.random.hypergeometric(8, [10, 4], [[5, 2], [5, 5]], size=(3, 2, 2))
|
450
|
+
self.assertTupleEqual(a.shape, (3, 2, 2))
|
451
|
+
|
452
|
+
def test_logseries(self):
|
453
|
+
brainstate.random.seed()
|
454
|
+
a = brainstate.random.logseries([0.7, 0.5, 0.2], size=[4, 3])
|
455
|
+
self.assertTupleEqual(a.shape, (4, 3))
|
456
|
+
|
457
|
+
def test_multinominal1(self):
|
458
|
+
brainstate.random.seed()
|
459
|
+
a = np.random.multinomial(100, (0.5, 0.2, 0.3), size=[4, 2])
|
460
|
+
print(a, a.shape)
|
461
|
+
b = brainstate.random.multinomial(100, (0.5, 0.2, 0.3), size=[4, 2])
|
462
|
+
print(b, b.shape)
|
463
|
+
self.assertTupleEqual(a.shape, b.shape)
|
464
|
+
self.assertTupleEqual(b.shape, (4, 2, 3))
|
465
|
+
|
466
|
+
def test_multinominal2(self):
|
467
|
+
brainstate.random.seed()
|
468
|
+
a = brainstate.random.multinomial(100, (0.5, 0.2, 0.3))
|
469
|
+
self.assertTupleEqual(a.shape, (3,))
|
470
|
+
self.assertTrue(a.sum() == 100)
|
471
|
+
|
472
|
+
def test_multivariate_normal1(self):
|
473
|
+
brainstate.random.seed()
|
474
|
+
# self.skipTest('Windows jaxlib error')
|
475
|
+
a = np.random.multivariate_normal([1, 2], [[1, 0], [0, 1]], size=3)
|
476
|
+
b = brainstate.random.multivariate_normal([1, 2], [[1, 0], [0, 1]], size=3)
|
477
|
+
print('test_multivariate_normal1')
|
478
|
+
print(a)
|
479
|
+
print(b)
|
480
|
+
self.assertTupleEqual(a.shape, b.shape)
|
481
|
+
self.assertTupleEqual(a.shape, (3, 2))
|
482
|
+
|
483
|
+
def test_multivariate_normal2(self):
|
484
|
+
brainstate.random.seed()
|
485
|
+
a = np.random.multivariate_normal([1, 2], [[1, 3], [3, 1]])
|
486
|
+
b = brainstate.random.multivariate_normal([1, 2], [[1, 3], [3, 1]], method='svd')
|
487
|
+
print(a)
|
488
|
+
print(b)
|
489
|
+
self.assertTupleEqual(a.shape, b.shape)
|
490
|
+
self.assertTupleEqual(a.shape, (2,))
|
491
|
+
|
492
|
+
def test_negative_binomial(self):
|
493
|
+
brainstate.random.seed()
|
494
|
+
a = np.random.negative_binomial([3., 10.], 0.5)
|
495
|
+
b = brainstate.random.negative_binomial([3., 10.], 0.5)
|
496
|
+
print(a)
|
497
|
+
print(b)
|
498
|
+
self.assertTupleEqual(a.shape, b.shape)
|
499
|
+
self.assertTupleEqual(b.shape, (2,))
|
500
|
+
|
501
|
+
def test_negative_binomial2(self):
|
502
|
+
brainstate.random.seed()
|
503
|
+
a = np.random.negative_binomial(3., 0.5, 10)
|
504
|
+
b = brainstate.random.negative_binomial(3., 0.5, 10)
|
505
|
+
print(a)
|
506
|
+
print(b)
|
507
|
+
self.assertTupleEqual(a.shape, b.shape)
|
508
|
+
self.assertTupleEqual(b.shape, (10,))
|
509
|
+
|
510
|
+
def test_noncentral_chisquare(self):
|
511
|
+
brainstate.random.seed()
|
512
|
+
a = np.random.noncentral_chisquare(3, [3., 2.], (4, 2))
|
513
|
+
b = brainstate.random.noncentral_chisquare(3, [3., 2.], (4, 2))
|
514
|
+
self.assertTupleEqual(a.shape, b.shape)
|
515
|
+
self.assertTupleEqual(b.shape, (4, 2))
|
516
|
+
|
517
|
+
def test_noncentral_chisquare2(self):
|
518
|
+
brainstate.random.seed()
|
519
|
+
a = brainstate.random.noncentral_chisquare(3, [3., 2.])
|
520
|
+
self.assertTupleEqual(a.shape, (2,))
|
521
|
+
|
522
|
+
def test_noncentral_f(self):
|
523
|
+
brainstate.random.seed()
|
524
|
+
a = brainstate.random.noncentral_f(3, 20, 3., 100)
|
525
|
+
self.assertTupleEqual(a.shape, (100,))
|
526
|
+
|
527
|
+
def test_power(self):
|
528
|
+
brainstate.random.seed()
|
529
|
+
a = np.random.power(2, (4, 2))
|
530
|
+
b = brainstate.random.power(2, (4, 2))
|
531
|
+
self.assertTupleEqual(a.shape, b.shape)
|
532
|
+
self.assertTupleEqual(b.shape, (4, 2))
|
533
|
+
|
534
|
+
def test_rayleigh(self):
|
535
|
+
brainstate.random.seed()
|
536
|
+
a = brainstate.random.power(2., (4, 2))
|
537
|
+
self.assertTupleEqual(a.shape, (4, 2))
|
538
|
+
|
539
|
+
def test_triangular(self):
|
540
|
+
brainstate.random.seed()
|
541
|
+
a = brainstate.random.triangular((2, 2))
|
542
|
+
self.assertTupleEqual(a.shape, (2, 2))
|
543
|
+
|
544
|
+
def test_vonmises(self):
|
545
|
+
brainstate.random.seed()
|
546
|
+
a = np.random.vonmises(2., 2.)
|
547
|
+
b = brainstate.random.vonmises(2., 2.)
|
548
|
+
print(a, b)
|
549
|
+
self.assertTupleEqual(np.shape(a), b.shape)
|
550
|
+
self.assertTupleEqual(b.shape, ())
|
551
|
+
|
552
|
+
def test_vonmises2(self):
|
553
|
+
brainstate.random.seed()
|
554
|
+
a = np.random.vonmises(2., 2., 10)
|
555
|
+
b = brainstate.random.vonmises(2., 2., 10)
|
556
|
+
print(a, b)
|
557
|
+
self.assertTupleEqual(a.shape, b.shape)
|
558
|
+
self.assertTupleEqual(b.shape, (10,))
|
559
|
+
|
560
|
+
def test_wald(self):
|
561
|
+
brainstate.random.seed()
|
562
|
+
a = np.random.wald([2., 0.5], 2.)
|
563
|
+
b = brainstate.random.wald([2., 0.5], 2.)
|
564
|
+
self.assertTupleEqual(a.shape, b.shape)
|
565
|
+
self.assertTupleEqual(b.shape, (2,))
|
566
|
+
|
567
|
+
def test_wald2(self):
|
568
|
+
brainstate.random.seed()
|
569
|
+
a = np.random.wald(2., 2., 100)
|
570
|
+
b = brainstate.random.wald(2., 2., 100)
|
571
|
+
self.assertTupleEqual(a.shape, b.shape)
|
572
|
+
self.assertTupleEqual(b.shape, (100,))
|
573
|
+
|
574
|
+
def test_weibull(self):
|
575
|
+
brainstate.random.seed()
|
576
|
+
a = brainstate.random.weibull(2., (4, 2))
|
577
|
+
self.assertTupleEqual(a.shape, (4, 2))
|
578
|
+
|
579
|
+
def test_weibull2(self):
|
580
|
+
brainstate.random.seed()
|
581
|
+
a = brainstate.random.weibull(2., )
|
582
|
+
self.assertTupleEqual(a.shape, ())
|
583
|
+
|
584
|
+
def test_weibull3(self):
|
585
|
+
brainstate.random.seed()
|
586
|
+
a = brainstate.random.weibull([2., 3.], )
|
587
|
+
self.assertTupleEqual(a.shape, (2,))
|
588
|
+
|
589
|
+
def test_weibull_min(self):
|
590
|
+
brainstate.random.seed()
|
591
|
+
a = brainstate.random.weibull_min(2., 2., (4, 2))
|
592
|
+
self.assertTupleEqual(a.shape, (4, 2))
|
593
|
+
|
594
|
+
def test_weibull_min2(self):
|
595
|
+
brainstate.random.seed()
|
596
|
+
a = brainstate.random.weibull_min(2., 2.)
|
597
|
+
self.assertTupleEqual(a.shape, ())
|
598
|
+
|
599
|
+
def test_weibull_min3(self):
|
600
|
+
brainstate.random.seed()
|
601
|
+
a = brainstate.random.weibull_min([2., 3.], 2.)
|
602
|
+
self.assertTupleEqual(a.shape, (2,))
|
603
|
+
|
604
|
+
def test_zipf(self):
|
605
|
+
brainstate.random.seed()
|
606
|
+
a = brainstate.random.zipf(2., (4, 2))
|
607
|
+
self.assertTupleEqual(a.shape, (4, 2))
|
608
|
+
|
609
|
+
def test_zipf2(self):
|
610
|
+
brainstate.random.seed()
|
611
|
+
a = np.random.zipf([1.1, 2.])
|
612
|
+
b = brainstate.random.zipf([1.1, 2.])
|
613
|
+
self.assertTupleEqual(a.shape, b.shape)
|
614
|
+
self.assertTupleEqual(b.shape, (2,))
|
615
|
+
|
616
|
+
def test_maxwell(self):
|
617
|
+
brainstate.random.seed()
|
618
|
+
a = brainstate.random.maxwell(10)
|
619
|
+
self.assertTupleEqual(a.shape, (10,))
|
620
|
+
|
621
|
+
def test_maxwell2(self):
|
622
|
+
brainstate.random.seed()
|
623
|
+
a = brainstate.random.maxwell()
|
624
|
+
self.assertTupleEqual(a.shape, ())
|
625
|
+
|
626
|
+
def test_t(self):
|
627
|
+
brainstate.random.seed()
|
628
|
+
a = brainstate.random.t(1., size=10)
|
629
|
+
self.assertTupleEqual(a.shape, (10,))
|
630
|
+
|
631
|
+
def test_t2(self):
|
632
|
+
brainstate.random.seed()
|
633
|
+
a = brainstate.random.t([1., 2.], size=None)
|
634
|
+
self.assertTupleEqual(a.shape, (2,))
|
635
|
+
|
636
|
+
# class TestRandomKey(unittest.TestCase):
|
637
|
+
# def test_clear_memory(self):
|
638
|
+
# brainstate.random.split_key()
|
639
|
+
# print(brainstate.random.DEFAULT.value)
|
640
|
+
# self.assertTrue(isinstance(brainstate.random.DEFAULT.value, np.ndarray))
|