permutation_init
ReservoirComputing.permutation_init — Function
permutation_init([rng], [T], dims...;
weight=0.1, permutation_matrix=nothing, return_sparse=false,
radius=nothing, kwargs...)Creates a permutation reservoir as described in (Boedecker et al., 2009), by first initializing a scaled identity (self-loops) and then applying a column permutation.
This construction yields:
\[ \widehat{W} = \lambda P\]
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 reservoir matrix.
Keyword arguments
weight: Weight used for the initial self-loop initialization (and the magnitude of the nonzeros after permutation). Default is 0.1.permutation_matrix: Optional permutation matrix to apply. Ifnothing, a random permutation is generated (usingrng) and applied.return_sparse: flag for returning asparsematrix.truerequiresSparseArraysto be loaded. Default isfalse.radius: The desired spectral radius of the reservoir. Ifnothingis passed, no scaling takes place. Defaults tonothing.sampling_type: Sampling that decides the distribution ofweightnegative numbers. If set to:no_samplethe sign is unchanged. If set to:bernoulli_sample!then eachforward_weightcan be positive with a probability set bypositive_prob. If set to:irrational_sample!theweightis negative if the decimal number of the irrational number chosen is odd. If set to:regular_sample!, each weight will be assigned a negative sign after the chosenstrides.stridescan be a single number or an array. Default is:no_sample.positive_prob: probability of theweightbeing positive whensampling_typeis set to:bernoulli_sample!. Default is 0.5.irrational: Irrational number whose decimals decide the sign ofweight. Default ispi.start: Which place after the decimal point the counting starts for theirrationalsign counting. Default is 1.strides: number of strides for assigning negative value to a weight. It can be an integer or an array. Default is 2.
Examples
Default kwargs:
julia> reservoir_matrix = permutation_init(5, 5)
5×5 Matrix{Float32}:
0.0 0.0 0.0 0.0 0.1
0.0 0.1 0.0 0.0 0.0
0.1 0.0 0.0 0.0 0.0
0.0 0.0 0.1 0.0 0.0
0.0 0.0 0.0 0.1 0.0Changing the weights magnitudes to a different unique value:
julia> reservoir_matrix = permutation_init(5, 5; weight=0.99)
5×5 Matrix{Float32}:
0.0 0.0 0.0 0.0 0.99
0.0 0.99 0.0 0.0 0.0
0.99 0.0 0.0 0.0 0.0
0.0 0.0 0.99 0.0 0.0
0.0 0.0 0.0 0.99 0.0Changing the weights signs with different sampling techniques:
julia> reservoir_matrix = permutation_init(5, 5; sampling_type=:bernoulli_sample!)
5×5 Matrix{Float32}:
0.0 0.1 0.0 0.0 0.0
0.0 0.0 -0.1 0.0 0.0
0.1 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 -0.1
0.0 0.0 0.0 0.1 0.0Changing the weights to random numbers. Note that the length of the given array must be at least as long as the subdiagonal one wants to fill:
julia> reservoir_matrix = permutation_init(5, 5; weight=rand(Float32, 5))
5×5 Matrix{Float32}:
0.0 0.0 0.0 0.0 0.0263106
0.0 0.923927 0.0 0.0 0.0
0.255075 0.0 0.0 0.0 0.0
0.0 0.0 0.585589 0.0 0.0
0.0 0.0 0.0 0.353418 0.0Returning a sparse matrix:
julia> reservoir_matrix = permutation_init(5, 5; return_sparse=true)
5×5 SparseMatrixCSC{Float32, Int64} with 5 stored entries:
⋅ ⋅ ⋅ ⋅ 0.1
⋅ 0.1 ⋅ ⋅ ⋅
0.1 ⋅ ⋅ ⋅ ⋅
⋅ ⋅ 0.1 ⋅ ⋅
⋅ ⋅ ⋅ 0.1 ⋅References
- Boedecker, J.; Obst, O.; Mayer, N. M. and Asada, M. (2009). Studies on reservoir initialization and dynamics shaping in echo state networks. In: ESANN.