Skip to content

Adding a Wigner matrix initialiser for #284#412

Open
am-1118 wants to merge 2 commits intoSciML:masterfrom
am-1118:feature/wigner-init
Open

Adding a Wigner matrix initialiser for #284#412
am-1118 wants to merge 2 commits intoSciML:masterfrom
am-1118:feature/wigner-init

Conversation

@am-1118
Copy link

@am-1118 am-1118 commented Mar 25, 2026

This PR implements the Wigner matrix initialisation to resolve Issue #284.

Changes Made

  • Added wigner_init to the matrix initialisers.
  • Utilised LinearAlgebra.Symmetric to make the matrix symmetric.
  • Integrated the standard check_res_size, scale_radius!, and check_inf_nan utilities.
  • Added a @testset block to verify reservoir dimensions, data type, and reservoir symmetry.

for j in 1 : res_size
if i==j
# Diagonal element
W[i, j] = randn(rng, T) * T(sqrt(2)) * T(std)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

randn(rng, T) sohuld be taken from DeviceAgnostic

also I don't understand why T(sqrt(2))

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the standard Wigner matrix, T(sqrt(2)) is for the diagonal elements as they are sampled from N(0, 2*variance), which implies sqrt(2) * std. I will modify the arguments to accept two arbitrary std values for the diagonal and off-diagonal distributions, as described in the issue. Modified rand -> DeviceAgnostic.rand

end

# Make the matrix symmetric
W = Symmetric(W)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add this as a kwarg option that the user can choose return_symmetric::Bool = false

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also need to import this from LinearAlgebra here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added the return_symmetric argument, but I've kept the default case as true, which the user can set to false.
using LinearAlgebra: eigvals, I, qr, Diagonal, diag, mul!
Should I paste the above line into the inits_reservoir.jl code?

W = scale_radius!(W, T(radius))

# 5. Check for NaN or Inf values
check_inf_nan(W)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is necessary, this issue usually arises from the sparsity

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I remove that line ? Or add some other check?

res_size = dims[1]

# 2. Initialise the empty matrix using the requested type T
W = zeros(T, res_size, res_size)
Copy link
Collaborator

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants