Created
December 22, 2022 14:15
-
-
Save naenumtou/ed46b5d62a6824f45513f2d774dbaf6d 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 generator matrix function | |
def GeneratorMatrix(P): | |
# Define identity matrix | |
I = pd.DataFrame( | |
np.identity(P.shape[0]), | |
index = P.index, | |
columns = P.columns | |
) | |
# Generator matrix | |
generatedMatrix = None | |
for n in range(1, P.shape[0] + 1): | |
expandMatrix = pd.DataFrame( | |
np.linalg.matrix_power( | |
P - I, n | |
), | |
index = P.index, | |
columns = P.columns | |
) | |
expandMatrix = ((-1)**(n + 1)) * (expandMatrix / n) | |
if generatedMatrix is None: | |
generatedMatrix = expandMatrix.copy() | |
else: | |
generatedMatrix += expandMatrix | |
return generatedMatrix |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment