-
-
Notifications
You must be signed in to change notification settings - Fork 48
Adding a Wigner matrix initialiser for #284 #412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2533,3 +2533,43 @@ for initializer in ( | |
| end | ||
| end | ||
| end | ||
|
|
||
|
|
||
|
|
||
| function wigner_init( | ||
| rng::AbstractRNG, ::Type{T}, dims::Integer...; | ||
| radius::Number = T(1.0), std::Number = T(1.0) | ||
| ) where {T <: Number} | ||
| # 1. Dimension check : Reservoir has to be a square matrix | ||
| check_res_size(dims...) | ||
| res_size = dims[1] | ||
|
|
||
| # 2. Initialise the empty matrix using the requested type T | ||
| W = zeros(T, res_size, res_size) | ||
|
|
||
| # 3. Populating the matrix | ||
| # Diagonal elements sampled from N(0, 2*std^2) | ||
| # Off-diagonal elements sampled from N(0, std^2) | ||
| for i in 1 : res_size | ||
| for j in 1 : res_size | ||
| if i==j | ||
| # Diagonal element | ||
| W[i, j] = randn(rng, T) * T(sqrt(2)) * T(std) | ||
|
||
| else | ||
| # Off-diagonal elements (upper triangular part) | ||
| W[i, j] = randn(rng, T) * T(std) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| # Make the matrix symmetric | ||
| W = Symmetric(W) | ||
|
||
|
|
||
| # 4. Scaling the spectral radius to the user-specified value | ||
| W = scale_radius!(W, T(radius)) | ||
|
|
||
| # 5. Check for NaN or Inf values | ||
| check_inf_nan(W) | ||
|
||
|
|
||
| return W | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try to avoid single letter naming if possible W -> reservoir_matrix. follow the conventions of the other initializers so that it makes it easier to search for stuff in the file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done