Skip to content
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

About n_interactions=0 error #10

Open
joshua-shuhan opened this issue Aug 29, 2023 · 5 comments
Open

About n_interactions=0 error #10

joshua-shuhan opened this issue Aug 29, 2023 · 5 comments

Comments

@joshua-shuhan
Copy link

Hi! Thanks for creating this repo for simulating the Kuramoto model.

I generate random adj_mat and run the code. Some warnings came up, and I set these warnings as errors. The error message turns out as follows:

line 71, in integrate
coupling = self.coupling / n_interactions  # normalize coupling by number of interactions
RuntimeWarning: divide by zero encountered in divide

So I go check the code (in kuramoto.py) and find that the n_interactions term is the summation of adj_mat over its column (axis=0). However, as the n_interactions serves as the normalization term for the coupling term, should it be the summation of adj_mat over its row (axis=1)? Since A_{ij} represents the coupling effect from node j to node i.

I am not sure if my thought is correct. If this bug is confirmed, I am happy to set a PR : )

@fabridamicelli
Copy link
Owner

Hi @joshua-shuhan

Thank you for taking the time to report the issue.
Can you please provide me with a little code snippet that reproduces the error? Please set a random seed before initializing the random adjacency matrix, so that I can exactly reproduce your results.

Having said that, the interactions in the matrix A_ij are meant to be i-->j. (I know it might be confusing and different implementations do it differently). I will double check that.

Best

F

@joshua-shuhan
Copy link
Author

joshua-shuhan commented Aug 31, 2023

Hi @fabridamicelli , thanks for your reply:)
Random adjacency matrix is not necessary to reproduce the error. The error can be reproduced by any graph matrix w/ all 0s in the matrix column. For example, the graph matrix below has all 0s in its 5th column. In my case, RuntimeWarning: divide by zero encountered in divide error occurred when I ran the code below.

import numpy as np
from kuramoto import Kuramoto
import warnings
warnings.filterwarnings("error")

freq_list = np.random.uniform(low=2, high=10, size=5) 
graph = np.array([[0, 1, 0, 1, 0],
                 [1, 0, 1, 0, 0],
                 [0, 1, 0, 1, 0],
                 [1, 0, 1, 0, 0],
                 [0, 1, 0, 0, 0]])

model = Kuramoto(coupling=2, dt=0.05, T=5, n_nodes=5, natfreqs=freq_list)
act_mat = model.run(adj_mat=graph)

.

@fabridamicelli
Copy link
Owner

Hi @joshua-shuhan,

Thank you for following up and for the provided code.
I just checked again and indeed the (incoming) interactions are defined as i --> j. In any case that is not quite the problem, but rather the fact that the code currently cannot deal with a disconnected network.

So running the code snippet that you provided leads to an activity matrix full of nan as a result of the division by zero error. To me that looks like a relatively intuitive behaviour (given that a disconnected node doesn't quite makes sense so the output will be also "broken" and so it cannot be overseen), but maybe I am missing some use-case scenario (?)
Can you please maybe elaborate a bit on the use case that you're looking at where having disconnected nodes makes sense?

Best,
F

@joshua-shuhan
Copy link
Author

joshua-shuhan commented Oct 3, 2023

Hi @fabridamicelli ,

Thanks for your reply.
I am now doing a network structure inference task. The goal is to reversely infer the network (coupling matrix) from time series data. I generate Kuramoto time series data and want my model to obtain the underlying network.
In this scenario, it is reasonable for me to prepare some data cases where one node is disconnected from the network. Indeed, I admit that it is a rare scenario.

@fabridamicelli
Copy link
Owner

Hi @joshua-shuhan,

I see your point, that makes sense. I could try to have a workaround for that case.

But, in the meantime, I have another idea: Can you replace the 0 values by a very small value for the disconnected nodes in your connectivity matrix? Something like 1e-10, such that there is no division by zero error but still the influence is very small. I think that would be an interesting experiment to already check if your inference framework is doing "the right" thing. I'd be curious to see the results

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

No branches or pull requests

2 participants