Created
January 18, 2023 13:16
-
-
Save naenumtou/92539b2bc2445a531fdee8bde998da57 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define exact transition matrix | |
def ExactMatrix(exactQ): | |
# Define identity matrix | |
I = pd.DataFrame( | |
np.identity(exactQ.shape[0]), | |
index = exactQ.index, | |
columns = exactQ.columns | |
) | |
# Exact transition matrix | |
exactMatrix = None | |
for n in range(1, exactQ.shape[0] + 1): | |
expMatrix = pd.DataFrame( | |
np.linalg.matrix_power( | |
exactQ, n | |
), | |
index = exactQ.index, | |
columns = exactQ.columns | |
) | |
expMatrix = expMatrix / math.factorial(n) | |
if exactMatrix is None: | |
exactMatrix = expMatrix.copy() | |
else: | |
exactMatrix += expMatrix | |
exactMatrix = exactMatrix + I | |
return exactMatrix |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment