Tutorial on Markov Order
[1]:
import IdealFlow.Network as net # import package.module as alias
[2]:
#Generate random ideal flow network for a given number of nodes.
max_capacity = 9
num_nodes = 5
n = net.IFN("IFN") # create new network
C = n.rand_capacity(num_nodes, max_capacity)
F = n.capacity_to_ideal_flow(C)
scaling = n.global_scaling(F, 'int')
n.equivalent_ifn(F, scaling)
[2]:
array([[0., 2., 0., 0., 0.],
[0., 0., 0., 3., 0.],
[0., 1., 0., 0., 2.],
[0., 0., 3., 0., 0.],
[2., 0., 0., 0., 0.]])
[3]:
n.set_matrix(F,['a','b','c','d','#z#'])
print(n)
n.show();
traj1=n.generate('#z#')
traj2=n.generate('a')
trajectories = [traj1,traj2]
for traj in trajectories:
print('generated trajectory:',traj,'\n')
for ord in range(1,13):
trajSuper=n.order_markov_higher(traj,order=ord)
print('trajSuper'+str(ord)+'\n',trajSuper)
tr1=n.order_markov_lower(trajSuper)
print('back to traj1\n',tr1,'\n')
print()
{'a': {'b': np.float64(0.15384615384615397)}, 'b': {'d': np.float64(0.2307692307692309)}, 'c': {'b': np.float64(0.07692307692307696), '#z#': np.float64(0.1538461538461539)}, 'd': {'c': np.float64(0.23076923076923103)}, '#z#': {'a': np.float64(0.1538461538461538)}}

generated trajectory: []
trajSuper1
[]
back to traj1
[]
trajSuper2
[]
back to traj1
[]
trajSuper3
[]
back to traj1
[]
trajSuper4
[]
back to traj1
[]
trajSuper5
[]
back to traj1
[]
trajSuper6
[]
back to traj1
[]
trajSuper7
[]
back to traj1
[]
trajSuper8
[]
back to traj1
[]
trajSuper9
[]
back to traj1
[]
trajSuper10
[]
back to traj1
[]
trajSuper11
[]
back to traj1
[]
trajSuper12
[]
back to traj1
[]
generated trajectory: ['a', np.str_('b'), np.str_('d'), np.str_('c'), np.str_('#z#'), np.str_('a')]
trajSuper1
['a', 'b', 'd', 'c', '#z#', 'a']
back to traj1
['a', 'b', 'd', 'c', '#z#', 'a']
trajSuper2
['a|b', 'b|d', 'd|c', 'c|#z#', '#z#|a']
back to traj1
['a', 'b', 'd', 'c', '#z#', 'a']
trajSuper3
['a|b|d', 'b|d|c', 'd|c|#z#', 'c|#z#|a']
back to traj1
['a', 'b', 'd', 'c', '#z#', 'a']
trajSuper4
['a|b|d|c', 'b|d|c|#z#', 'd|c|#z#|a']
back to traj1
['a', 'b', 'd', 'c', '#z#', 'a']
trajSuper5
['a|b|d|c|#z#', 'b|d|c|#z#|a']
back to traj1
['a', 'b', 'd', 'c', '#z#', 'a']
trajSuper6
['a|b|d|c|#z#|a']
back to traj1
['a', 'b', 'd', 'c', '#z#', 'a']
trajSuper7
['a|b|d|c|#z#|a']
back to traj1
['a', 'b', 'd', 'c', '#z#', 'a']
trajSuper8
['a|b|d|c|#z#|a']
back to traj1
['a', 'b', 'd', 'c', '#z#', 'a']
trajSuper9
['a|b|d|c|#z#|a']
back to traj1
['a', 'b', 'd', 'c', '#z#', 'a']
trajSuper10
['a|b|d|c|#z#|a']
back to traj1
['a', 'b', 'd', 'c', '#z#', 'a']
trajSuper11
['a|b|d|c|#z#|a']
back to traj1
['a', 'b', 'd', 'c', '#z#', 'a']
trajSuper12
['a|b|d|c|#z#|a']
back to traj1
['a', 'b', 'd', 'c', '#z#', 'a']
[4]:
n.set_matrix(F)
print(n)
n.show();
traj1=n.generate('a')
traj2=n.generate('b')
trajectories = [traj1,traj2]
for traj in trajectories:
print('generated trajectory:',traj,'\n')
for ord in range(1,13):
trajSuper=n.order_markov_higher(traj,order=ord)
print('trajSuper'+str(ord)+'\n',trajSuper)
tr1=n.order_markov_lower(trajSuper)
print('back to traj1\n',tr1,'\n')
print()
{'a': {'b': np.float64(0.15384615384615397)}, 'b': {'d': np.float64(0.2307692307692309)}, 'c': {'b': np.float64(0.07692307692307696), 'e': np.float64(0.1538461538461539)}, 'd': {'c': np.float64(0.23076923076923103)}, 'e': {'a': np.float64(0.1538461538461538)}}

generated trajectory: ['a', np.str_('b'), np.str_('d'), np.str_('c'), np.str_('e'), np.str_('a')]
trajSuper1
['a', 'b', 'd', 'c', 'e', 'a']
back to traj1
['a', 'b', 'd', 'c', 'e', 'a']
trajSuper2
['a|b', 'b|d', 'd|c', 'c|e', 'e|a']
back to traj1
['a', 'b', 'd', 'c', 'e', 'a']
trajSuper3
['a|b|d', 'b|d|c', 'd|c|e', 'c|e|a']
back to traj1
['a', 'b', 'd', 'c', 'e', 'a']
trajSuper4
['a|b|d|c', 'b|d|c|e', 'd|c|e|a']
back to traj1
['a', 'b', 'd', 'c', 'e', 'a']
trajSuper5
['a|b|d|c|e', 'b|d|c|e|a']
back to traj1
['a', 'b', 'd', 'c', 'e', 'a']
trajSuper6
['a|b|d|c|e|a']
back to traj1
['a', 'b', 'd', 'c', 'e', 'a']
trajSuper7
['a|b|d|c|e|a']
back to traj1
['a', 'b', 'd', 'c', 'e', 'a']
trajSuper8
['a|b|d|c|e|a']
back to traj1
['a', 'b', 'd', 'c', 'e', 'a']
trajSuper9
['a|b|d|c|e|a']
back to traj1
['a', 'b', 'd', 'c', 'e', 'a']
trajSuper10
['a|b|d|c|e|a']
back to traj1
['a', 'b', 'd', 'c', 'e', 'a']
trajSuper11
['a|b|d|c|e|a']
back to traj1
['a', 'b', 'd', 'c', 'e', 'a']
trajSuper12
['a|b|d|c|e|a']
back to traj1
['a', 'b', 'd', 'c', 'e', 'a']
generated trajectory: ['b', np.str_('d'), np.str_('c'), np.str_('b')]
trajSuper1
['b', 'd', 'c', 'b']
back to traj1
['b', 'd', 'c', 'b']
trajSuper2
['b|d', 'd|c', 'c|b']
back to traj1
['b', 'd', 'c', 'b']
trajSuper3
['b|d|c', 'd|c|b']
back to traj1
['b', 'd', 'c', 'b']
trajSuper4
['b|d|c|b']
back to traj1
['b', 'd', 'c', 'b']
trajSuper5
['b|d|c|b']
back to traj1
['b', 'd', 'c', 'b']
trajSuper6
['b|d|c|b']
back to traj1
['b', 'd', 'c', 'b']
trajSuper7
['b|d|c|b']
back to traj1
['b', 'd', 'c', 'b']
trajSuper8
['b|d|c|b']
back to traj1
['b', 'd', 'c', 'b']
trajSuper9
['b|d|c|b']
back to traj1
['b', 'd', 'c', 'b']
trajSuper10
['b|d|c|b']
back to traj1
['b', 'd', 'c', 'b']
trajSuper11
['b|d|c|b']
back to traj1
['b', 'd', 'c', 'b']
trajSuper12
['b|d|c|b']
back to traj1
['b', 'd', 'c', 'b']