TommasoBelluzzo / PyDTMC

A library for discrete-time Markov chains analysis.
MIT License
80 stars 18 forks source link

Incorrect determination of regularity #12

Closed jacob-hastings closed 1 year ago

jacob-hastings commented 1 year ago

Expected Behavior

p = [[0.4, 0.6], [1., 0.]] is regular because the square of that matrix is [[0.76, 0.24], [0.4 , 0.6]], which has all positive entries.

Current Behavior

The is_regular property returns False.

Steps to Reproduce

p = [[0.4, 0.6], [1., 0.]]
mc = MarkovChain(p, ['A', 'B'])
print(mc.is_regular)

Possible Solution

The problem seems to arise from the inappropriate use of in the source code for is_regular, specifically in the second-to-last line of the definition: `result = _np.all(self.__pk > 0.0). The ** gives element-wise exponentiation. For matrix exponentiation, use_np.linalg.matrix_power(): result = _np.all(_np.linalg.matrix_power(self.__p, k) > 0.0)`

TommasoBelluzzo commented 1 year ago

The issue has been fixed in the new release. Thank you very much for your contribution!