Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/ludics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
generate_transition_matrix,
get_absorbing_state_index,
get_absorbing_states,
get_absorption_probabilities,
extract_Q,
extract_R_numerical,
extract_R_symbolic,
Expand Down
46 changes: 0 additions & 46 deletions src/ludics/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,52 +491,6 @@ def get_absorbing_states(state_space):
else np.array([state_space[index] for index in index_array])
)


def get_absorption_probabilities(
transition_matrix, state_space, exponent_coefficient=50
):
"""Given a transition matrix and a corresponding state space

generate the absorption probabilities. This does not yet support a

symbolic transition matrix input

Parameters
-------------
state_space: numpy.array, a state space

transition matrix: numpy.array, a matrix of transition probabilities corresponding to the state space

Returns
-------------
Dictionary of values: tuple([starting state]): [[absorbing state 1, absorption probability 1], [absorbing state 2, absorption probability 2]]
"""

absorption_index = get_absorbing_state_index(state_space=state_space)

absorbing_transition_matrix = np.linalg.matrix_power(
transition_matrix, exponent_coefficient
)

# TODO this method of getting absorption probabilities will change, but we need to set up benchmarks first

absorbing_collums = np.array(
[absorbing_transition_matrix[:, index] for index in absorption_index]
)

combined_values = np.array(
[
np.ravel(np.column_stack((absorption_index, absorbing_collums[:, k])))
for k, y in enumerate(absorbing_collums.transpose())
]
)

return {
state_index: combined_values[state_index]
for state_index, state in enumerate(state_space)
}


def extract_Q(transition_matrix):
"""
For a transition matrix, compute the corresponding matrix Q
Expand Down
39 changes: 0 additions & 39 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1073,45 +1073,6 @@ def test_get_absorbing_states_for_symbolic_state_space():
ludics.get_absorbing_states(state_space=symbolic_state_space),
)


def test_get_absorption_probabilities_for_trivial_transition_matrix_and_standard_state_space():
"""Tests the get_absorption_probabilities function for a transition matrix that guarentees absorption into a certain absorbing state."""

state_space = np.array(
[
[0, 0],
[1, 0],
[1, 1],
[1, 0],
]
)

transition_matrix = np.array(
[
[1, 0, 0, 0],
[1 / 2, 1 / 2, 0, 0],
[0, 0, 1, 0],
[0, 0, 1 / 2, 1 / 2],
]
)

expected = {
0: np.array([0, 1, 2, 0], dtype=float),
1: np.array([0, 1, 2, 0], dtype=float),
2: np.array([0, 0, 2, 1], dtype=float),
3: np.array([0, 0, 2, 1], dtype=float),
}

actual = ludics.get_absorption_probabilities(
transition_matrix=transition_matrix,
state_space=state_space,
exponent_coefficient=50,
)

for key in expected:
np.testing.assert_allclose(expected[key], actual[key])


def test_extract_Q_for_numeric_transition_matrix():
"""
Tests the extract_Q function for a transition matrix with numeric values
Expand Down
Loading