backward_connection!
ReservoirComputing.backward_connection!
— Functionbackward_connection!([rng], reservoir_matrix, weight, shift;
sampling_type=:no_sample, irrational=pi, start=1,
p=0.5)
Adds a backward connection in the reservoir_matrix
, with given shift
and weight
. The weight
can be a single number or an array.
Arguments
rng
: Random number generator. Default isUtils.default_rng()
from WeightInitializers.reservoir_matrix
: matrix to be changed.weight
: weight to add as a backward connection. Can be either a single number or an array.shift
: How far the backward connection will be from the diagonal.
Keyword arguments
sampling_type
: Sampling that decides the distribution ofweight
negative numbers. If set to:no_sample
the sign is unchanged. If set to:bernoulli_sample!
then eachweight
can be positive with a probability set bypositive_prob
. If set to:irrational_sample!
theweight
is 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
.strides
can be a single number or an array. Default is:no_sample
.positive_prob
: probability of theweight
being positive whensampling_type
is 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 theirrational
sign 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
julia> matrix = zeros(Float32, 5, 5)
5×5 Matrix{Float32}:
0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
julia> backward_connection!(matrix, 3.0, 1)
5×5 Matrix{Float32}:
0.0 3.0 0.0 0.0 0.0
0.0 0.0 3.0 0.0 0.0
0.0 0.0 0.0 3.0 0.0
0.0 0.0 0.0 0.0 3.0
0.0 0.0 0.0 0.0 0.0
julia> backward_connection!(matrix, 3.0, 1; sampling_type = :bernoulli_sample!)
5×5 Matrix{Float32}:
0.0 3.0 0.0 0.0 0.0
0.0 0.0 -3.0 0.0 0.0
0.0 0.0 0.0 3.0 0.0
0.0 0.0 0.0 0.0 -3.0
0.0 0.0 0.0 0.0 0.0