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> using Random
julia> using ReservoirComputing: scaled_rand
julia> res_input = scaled_rand(MersenneTwister(1), Float32, 8, 3);
julia> size(res_input) == (8, 3) && eltype(res_input) == Float32 && all(-0.1f0 .<= res_input .<= 0.1f0)
trueScaling with a tuple, providing lower and upper bound of the uniform distribution from which the weights will be sampled:
julia> res_input = scaled_rand(MersenneTwister(2), Float32, 8, 3; scaling = (0.1, 0.15));
julia> all(0.1f0 .<= res_input .<= 0.15f0)
trueScaling 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(MersenneTwister(3), Float32, 8, 3; scaling = [0.1, 0.2, 0.3]);
julia> all(all(-limit .<= column .<= limit) for (column, limit) in zip(eachcol(res_input), (0.1f0, 0.2f0, 0.3f0)))
trueScaling 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(MersenneTwister(4), Float32, 8, 3;
scaling = [(0.1, 0.2), (-0.2, -0.1), (0.3, 0.5)]);
julia> all(all(lower .<= column .<= upper) for (column, (lower, upper)) in zip(eachcol(res_input), ((0.1f0, 0.2f0), (-0.2f0, -0.1f0), (0.3f0, 0.5f0))))
true