scaled_rand
ReservoirComputing.scaled_rand — Function
scaled_rand([rng], [T], dims...;
scaling=0.1)Create and return a matrix with random values, uniformly distributed within a range defined by scaling.
Arguments
rng: Random number generator. Default isUtils.default_rng()from WeightInitializers.T: Type of the elements in the reservoir matrix. Default isFloat32.dims: Dimensions of the matrix. Should followres_size x in_size.
Keyword arguments
scaling: A scaling factor to define the range of the uniform distribution. The factor can be passed in three different ways:- A single number. In this case, the matrix elements will be randomly chosen from the range
[-scaling, scaling]. Default option, with a the scaling value set to0.1. - A tuple
(lower, upper). The values define the range of the distribution. the matrix elements will be randomly created and scaled the range[lower, upper]. - A vector of length =
in_size. In this case, the columns will be scaled individually by the entries of the vector. The entries can be numbers or tuples, which will mirror the behavior described above.
- A single number. In this case, the matrix elements will be randomly chosen from the range
Examples
Standard behavior with scaling given by a scalar:
julia> res_input = scaled_rand(8, 3)
8×3 Matrix{Float32}:
-0.0669356 -0.0292692 -0.0188943
0.0159724 0.004071 -0.0737949
0.026355 -0.0191563 0.0714962
-0.0177412 0.0279123 0.0892906
-0.0184405 0.0567368 0.0190222
0.0944272 0.0679244 0.0148647
-0.0799005 -0.0891089 -0.0444782
-0.0970182 0.0934286 0.03553Scaling with a tuple, providing lower and upper bound of the uniform distribution from which the weights will be sampled:
julia> res_input = scaled_rand(8, 3, scaling = (0.1, 0.15))
8×3 Matrix{Float32}:
0.108266 0.117683 0.120276
0.128993 0.126018 0.106551
0.131589 0.120211 0.142874
0.120565 0.131978 0.147323
0.12039 0.139184 0.129756
0.148607 0.141981 0.128716
0.105025 0.102723 0.11388
0.100745 0.148357 0.133882Scaling with a vector of scalars, where each provides the upper bound and its negative provides the lower bound. Each column is scaled in order: first element provides bounds for the first column, and so on:
julia> res_input = scaled_rand(8, 3, scaling = [0.1, 0.2, 0.3])
8×3 Matrix{Float32}:
-0.0669356 -0.0585384 -0.0566828
0.0159724 0.00814199 -0.221385
0.026355 -0.0383126 0.214489
-0.0177412 0.0558246 0.267872
-0.0184405 0.113474 0.0570667
0.0944272 0.135849 0.0445941
-0.0799005 -0.178218 -0.133435
-0.0970182 0.186857 0.10659Scaling with a vector of tuples, each providing both upper and lower bound. Each column is scaled in order: first element provides bounds for the first column, and so on:
julia> res_input = scaled_rand(8, 3, scaling = [(0.1, 0.2), (-0.2, -0.1), (0.3, 0.5)])
8×3 Matrix{Float32}:
0.116532 -0.164635 0.381106
0.157986 -0.147965 0.326205
0.163177 -0.159578 0.471496
0.141129 -0.136044 0.489291
0.14078 -0.121632 0.419022
0.197214 -0.116038 0.414865
0.11005 -0.194554 0.355522
0.101491 -0.103286 0.43553