dirmeier / diffusr

Network diffusion algorithms in R.
GNU General Public License v3.0
21 stars 6 forks source link

When is is.ergodic tested? #12

Closed jhrcook closed 3 years ago

jhrcook commented 5 years ago

Hello, Thank you for making this package, it has been incredibly useful! I have run into a problem where some graphs will fail with the following message when using random.walk.

Error in random.walk(P0, adjM, r = restart_prob) :
  the provided graph has more than one component. It is likely not ergodic.

I found this error message in a method for random.walk in "R/mrw.R":

if(!.is.ergodic(stoch.graph))
      stop(paste("the provided graph has more than one component.",
                 "It is likely not ergodic."))

The graph that failed really was composed of multiple components, but so were all of my other graphs prior that ran without fail. I also tested each one on the .is.ergodic function in "R/mat_util.R" (after applying the normalize.stochastic and they all failed (ie. return FALSE).

Finally, I looked at the class of P0 and adjM, and they are both "matrix" in all cases that work and those that fail.

My OOP in R is poor, so I am unable to determine when the .is.ergodic test is being applied and when it isn't on a call to random.walk. Would you know a way for me to start troubleshooting this? If I can create a reprex, I'll add it in another post.

Thank you, Josh Cook

jhrcook commented 5 years ago

I was able to fix my issue by first isolating the component with the seeds, making all of my graphs ergodic. This is probably a more proper technique, anyways. I'll leave this issue here, though, because there may be a bug in the .is.ergodic check that you want to track down and find. Otherwise, feel free to close it.

Thank you, Josh Cook

dirmeier commented 5 years ago

Hey Josh, .is.ergodic is tested everytime you call `random.walk.

First, the matrix you use as an argument is normalized to make it a proper transition matrix. Then the transition matrix is tested for ergodicity (now, that I am writing these lines, I am not sure anymore if the ergodicity should be better tested before). In any way, I'll have a look at the method. :)

Nice to see that the package has some use.

Cheers, Simon