@topology
Reservoir topologies such as selfloop_cycle are stacks of bang building blocks. @topology writes that stack as an initializer.
using ReservoirComputing
@topology my_cycle begin
self_loop!
simple_cycle!
end
my_cycle(5, 5)5×5 Matrix{Float32}:
0.1 0.0 0.0 0.0 0.1
0.1 0.1 0.0 0.0 0.0
0.0 0.1 0.1 0.0 0.0
0.0 0.0 0.1 0.1 0.0
0.0 0.0 0.0 0.1 0.1The result is a normal initializer, so it can be passed to init_reservoir:
ESN(1, 50, 1; init_reservoir = my_cycle(; cycle_weight = 0.2))ESN(
reservoir = StatefulLayer(ESNCell(1 => 50, use_bias=false)),
state_modifiers = (),
readout = LinearReadout(50 => 1, use_bias=false, include_collect=true)
)alias = block! names that block's weight. Sign kwargs stay on the original block (delay_kwargs):
@topology my_forward begin
self_loop!
forward = delay_line!(shift = 2)
end
my_forward(5, 5; forward_weight = 0.5)5×5 Matrix{Float32}:
0.1 0.0 0.0 0.0 0.0
0.0 0.1 0.0 0.0 0.0
0.5 0.0 0.1 0.0 0.0
0.0 0.5 0.0 0.1 0.0
0.0 0.0 0.5 0.0 0.1ReservoirComputing.@topology — Macro
@topology name begin
block!
alias = block!(; extra=default)
endCreate a reservoir initializer from building blocks such as self_loop!, simple_cycle!, and delay_line!.
Each block has a {prefix}_weight keyword (default 0.1). Extra arguments become keywords (delay_shift, fb_shift, jump_size). radius and return_sparse are always available. With more than one block, pass sign patterns as {prefix}_kwargs, for example cycle_kwargs=(; signs=RandomSigns()).
alias = block! names the weight (forward = delay_line! → forward_weight, weight = self_loop! → weight). Sign kwargs stay on the block (delay_kwargs). An aliased extra keeps the bang name (shift); otherwise it is {prefix}_{arg} (delay_shift). Defaults: self_loop! → selfloop, simple_cycle! → cycle, delay_line! → delay, backward_connection! → fb, add_jumps! → jump, reverse_simple_cycle! → second_cycle, permute_matrix! → permute.
julia> @topology my_cycle begin
self_loop!
simple_cycle!
end;
julia> my_cycle(5, 5)
5×5 Matrix{Float32}:
0.1 0.0 0.0 0.0 0.1
0.1 0.1 0.0 0.0 0.0
0.0 0.1 0.1 0.0 0.0
0.0 0.0 0.1 0.1 0.0
0.0 0.0 0.0 0.1 0.1