def sp_process_binary(self, trail): """ Binarily vectorizing the trail """ spvec = SparseVector([len(self.namespace), self.veclen]) rveclist = list() vadd = rveclist.append kadd = spvec.keys.append sortkey = lambda x: self.namespace.index(x['poi']) groupkey = lambda x: x['poi'] sortedtrail = sorted(trail, key=sortkey) for poi, checkins in itertools.groupby(sortedtrail, key=groupkey): kadd(self.namespace.index(poi)) ticks = [self.get_timeslot(c['tick']) for c in checkins] arr = NP.zeros(self.veclen) arr[ticks] = 1 vadd(arr) spvec.rvecs = NP.array(rveclist, dtype=NP.float32) return spvec
def sp_process(self, trail): """ accumulating gaussian shaped function """ spvec = SparseVector([len(self.namespace), self.veclen]) rveclist = list() vadd = rveclist.append kadd = spvec.keys.append sortkey = lambda x: self.namespace.index(x['poi']) groupkey = lambda x: x['poi'] sortedtrail = sorted(trail, key=sortkey) for poi, checkins in itertools.groupby(sortedtrail, key=groupkey): kadd(self.namespace.index(poi)) ticks = [self.get_seconds(c['tick']) for c in checkins] vadd(kernel_smooth(self.axis, ticks, self.params, aggr=self.aggr, kernel=self.kernel)) spvec.rvecs = NP.array(rveclist, dtype=NP.float32) if self.normalized: NP.add(spvec.rvecs, EPSILON, spvec.rvecs) # insure not divided by zero unity = NP.sum(spvec.rvecs, axis=0) NP.divide(spvec.rvecs, unity, spvec.rvecs) return spvec