-
-
Notifications
You must be signed in to change notification settings - Fork 41
Open
Labels
initsinitializers for internal matricesinitializers for internal matrices
Description
Description
Random columns permutations of the identity matrix, rescaled by a certain factor. This can be generalized using our infrastructure to also be full random. Ref1, and ref2 (mentioned as the original source in ref1)
Implementation
function permutation_init(rng::AbstractRNG, ::Type{T}, dims::Integer...;
weight=T(0.1), return_sparse = false, permutation_matrix = nothing,
kwargs...) where {T <: Number}
throw_sparse_error(return_sparse)
reservoir_matrix = DeviceAgnostic.zeros(rng, T, dims...)
self_loop!(rng, reservoir_matrix, weight; kwargs...)
permuted_matrix = permute_matrix(reservoir_matrix, permutation_matrix)
return return_init_as(Val(return_sparse), permuted_matrix)
end
function apply_permutation!(reservoir_matrix::AbstractMatrix, permutation_matrix::AbstractMatrix) # Union(nothing)
if permutation_matrix == nothing
perm_array = randperm(size(reservoir_matrix, 1))
permutation_matrix = create_permutation_matrix(perm_array)
end
return reservoir_matrix * permutation_matrix
end
function create_permutation_matrix(p::AbstractVector{Int})
n = length(p)
P = zeros(Float64, n, n)
for i in 1:n
P[i, p[i]] = 1.0
end
return P
endMetadata
Metadata
Assignees
Labels
initsinitializers for internal matricesinitializers for internal matrices