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

Periodicity of DiGraph/MarkovChain #245

Open
oyamad opened this issue Mar 20, 2016 · 7 comments
Open

Periodicity of DiGraph/MarkovChain #245

oyamad opened this issue Mar 20, 2016 · 7 comments
Labels

Comments

@oyamad
Copy link
Member

oyamad commented Mar 20, 2016

@oyamad
Copy link
Member Author

oyamad commented Mar 20, 2016

For example, what period do we want to say the following Markov chain has?

P = [[0, 0.5, 0, 0, 0.5],
     [0, 0, 0.5, 0, 0.5],
     [0.5, 0, 0, 0, 0.5],
     [0, 0, 0, 0, 1],
     [0, 0, 0, 1, 0]]

My argument is that the communication class [0, 1, 2] is transient and therefore can be ignored, so that the period of this mc should be determined by that of the recurrent class [3, 4] which is 2. So this mc is periodic.

What about the digraph defined by the above matrix? In a digraph there is no concept of transience, so [0, 1, 2] should not be ignored. Then, if the period of a digraph is defined to be the greatest common divisor of the lengths of all cycles, then it is 1 and so this digraph is aperiodic.

But actually in the DiGraph code I left the period of a non-strongly connected digraph to be undefined, to avoid different conclusions between MarkovChain and DiGraph.

@oyamad
Copy link
Member Author

oyamad commented Mar 20, 2016

And what about this?

Q = [[0, 1, 0, 0, 0],
     [0, 0, 1, 0, 0],
     [1, 0, 0, 0, 0],
     [0, 0, 0, 0, 1],
     [0, 0, 0, 1, 0]]

Should the period of the Markov chain/digraph be 6, 1, or undefined?

@jstac
Copy link
Contributor

jstac commented Mar 20, 2016

OK, I remember better now. You thought about all of this very carefully.

My comment in #237 (thanks for opening a new issue) is mainly about the error, which to the casual user of the code makes it seem like the code is broken. It's not, but that's a likely impression.

What do you think about returning the string "undefined" instead?

Regarding the specific cases, I don't mind too much what convention we adopt. As you say, it's possible to make arguments from different perspectives.

(From what I saw in a quick read, for a digraph, gcd of the length of the cycles = 1 seemed like a common definition of aperiodicity, while for finite MCs, all states aperiodic seems like the standard definition of aperiodicity.)

@oyamad
Copy link
Member Author

oyamad commented Mar 28, 2016

What do you think about returning the string "undefined" instead?

What if the user uses it in a script with d = g.period and accesses d? I think it is better to explicitly raise an Error. It also allows one to write

try:
    d = g.period
except NotImplementedError:
    ...

@jstac
Copy link
Contributor

jstac commented Apr 13, 2016

@oyamad I'm not sure, to be honest. I guess it felt strange that I got an error message when I requested a property. That's why it felt like the implementation was broken. It seems like if there's a property I should be able to access it without getting an error message.

So I prefer the string "undefined".

But I can see your point of view too. If you are happy with it the way it is you can close this issue.

@oyamad
Copy link
Member Author

oyamad commented Apr 13, 2016

To me it seems natural that, given that it is left undefined for a reducible Markov chain, the period is not implemented and when it is accessed a NotImplementedError is explicitly raised. I am not sure which is more "pythonic" (if they are ordered in terms of the degree of "pythonicity"). I would like to hear opinions from other people.

@davidrpugh
Copy link
Contributor

I think it is better to explicitly raise NotImplementedError (possibly with
custom error message explaining why the error was raised).

On Wed, Apr 13, 2016 at 2:07 PM, Daisuke Oyama [email protected]
wrote:

To me it seems natural that, given that it is left undefined for a
reducible Markov chain, the period is not implemented and when it is
accessed a NotImplementedError is explicitly raised. I am not sure which
is more "pythonic" (if they are ordered in terms of the degree of
"pythonicity"). I would like to hear opinions from other people.


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#245 (comment)

@oyamad oyamad added the discuss label Nov 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants