The problem and what I expect.
I have a table h
which indicates the H-bond states, where 1
for existing H-bond, 0
for no H-bond exist. Colums are for different object, rows are for different time step.
0, 0, 1, 1, 0, 0
0, 0, 1, 1, 0, 0
1, 0, 1, 1, 0, 0
1, 1, 1, 1, 0, 1
0, 1, 0, 0, 1, 1
0, 1, 0, 0, 1, 1
1, 0, 1, 1, 0, 1
I want to calculate the life (how long the H-bond exists) for each object. So the expected life table L
should be like this.
0, 0, 4, 4, 0, 0
0, 0, 4, 4, 0, 0
2, 0, 4, 4, 0, 0
2, 3, 4, 4, 0, 4
0, 3, 0, 0, 2, 4
0, 3, 0, 0, 2, 4
1, 0, 1, 1, 0, 4
I don't know how to apply this map.
What I've done.
I've tried to map h
to a new table generations
indicating the generations of H-bond using the rising edge detecting. And the generations table G
obtained:
[[0 0 1 1 0 0]
[0 0 1 1 0 0]
[1 0 1 1 0 0]
[1 1 1 1 0 1]
[1 1 1 1 1 1]
[1 1 1 1 1 1]
[2 1 2 2 1 1]]
And then I tried to map h
to a new ages
table, indicating the ages of H-bond. I got the following table A
.
[[0 0 1 1 0 0]
[0 0 2 2 0 0]
[1 0 3 3 0 0]
[2 1 4 4 0 1]
[0 2 0 0 1 2]
[0 3 0 0 2 3]
[1 0 1 1 0 4]]
I was tried to map h
to life table L
by using the logic:
The life of a H-bond is the maximum age of all ages with the same generation. However, I've stuck on this mapping.
Some code
Some codes I used to calculate G
and A
.
def getQbGenerations(self, QbStates):
QbGenerations = np.zeros_like(QbStates, dtype=np.int64)
Generation = np.zeros(QbStates.shape[-1])
Generation[QbStates[0] == 1] = 1
QbGenerations[0] = Generation
for i in range(1, QbStates.shape[0]):
# Rising Edge
RiseMask = np.logical_and(QbStates[i-1]==0, QbStates[i]==1)
Generation[RiseMask] += 1
QbGenerations[i] = Generation
return QbGenerations
def getQbAges(self, QbStates):
QbAges = np.zeros_like(QbStates, dtype=np.int64)
Age = np.zeros(QbStates.shape[-1])
Age[QbStates[0] == 1] = 1
QbAges[0] = Age
for i in range(1, QbStates.shape[0]):
BondMask = QbStates[i] == 1
Age[BondMask] += 1
Age[~BondMask] = 0
QbAges[i] = Age
return QbAges