trajminer / trajminer

Trajectory Mining Library

Home Page:http://trajminer.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MSM function cannot input arguments (T1, T2) and (P1, P2)

liufeng0612 opened this issue · comments

commented

Could you please give me the format of the sample data input for (T1, T2) and (P1, P2)? I used the sample data, but could not input it all the time:
The sample data:
data = TrajectoryData(attributes=['poi', 'hour', 'rating'],
data=[[['Bakery', 8, 8.6],
['Work', 9, 8.9],
['Restaurant', 12, 7.7],
['Bank', 12, 5.6],
['Work', 13, 8.9],
['Home', 19, 0]],

                        [['Home', 8, 0], 
                         ['Mall', 10, 9.3],
                         ['Home', 19, 0],
                         ['Pub', 21, 9.5]]],
                  tids=[20, 24],
                  labels=[1, 2])

T1 of trajectory A [8, 9, 12, 12, 13, 19]
T2 of trajectory B [8, 10, 19, 21]
or
['8' '9' '12' '12' '13' '19']
['8' '10' '19' '21']
Unable to enter similarity function and _score function

def similarity(self, t1, t2):
matrix = np.zeros(shape=(len(t1), len(t2)))

    for i, p1 in enumerate(t1):
        matrix[i] = [self._score(p1, p2) for p2 in t2]

    parity1 = matrix.max(axis=1).sum()
    parity2 = matrix.max(axis=0).sum()
    return (parity1 + parity2) / (len(t1) + len(t2))

def _score(self, p1, p2):
    matches = np.zeros(len(p1))
    for i, _ in enumerate(p1):
        matches[i] = self.dist_functions[i](p1[i], p2[i]) <= \
            self.thresholds[i]
    return sum(matches * self.weights)