import numpy as np # Transition matrix #a_ij here means the probability of transitioning j->i, otherwise transpose A A = np.array([ [0.5, 0.3, 0.3], [0.4, 0.5, 0.4], [0.1, 0.2, 0.3] ]) # Initialize state (states are indexed 0,1,2 here) current_state = 2 state_counts = [0, 0, 0] # Track visits to each state num_transitions = 1000 # Simulate transitions and count states for _ in range(num_transitions): state_counts[current_state] += 1 current_state = np.random.choice([0, 1, 2], p=A[:,current_state]) # Print the number of times each state was visited print("State visit counts:") print(f"State 1: {state_counts[0]}") print(f"State 2: {state_counts[1]}") print(f"State 3: {state_counts[2]}")