예제 #1
0
 def load_adjacency(self, path, lcc=False):
     comment = 'Ontology: {}\nYear: {}\nSubmissionID: {}'.format(
         self.name, self.year, self.submission_id)
     field = 'integer'
     if lcc:
         self.lcc_A = read_sparse_matrix(
             path, self.get_onto_filename(path, ADJ_EXT, lcc))
     else:
         self.A = read_sparse_matrix(path,
                                     self.get_onto_filename(path, ADJ_EXT))
예제 #2
0
    def create_distance_matrix(self, path, hopspath, lcc=False):

        fn_final = self.get_distance_matrix_fn(lcc)
        if os.path.exists(os.path.join(path, fn_final)):
            return read_sparse_matrix(path, fn_final)

        fname = self.get_khop_matrix_fn(k=None, lcc=lcc)
        files = [
            fn for fn in os.listdir(hopspath)
            if fn.startswith(fname.replace('<k>HOP.{}'.format(ADJ_EXT), ''))
            and fn.endswith('HOP.{}'.format(ADJ_EXT))
        ]
        m = None

        print('\n'.join(files))
        maximun = len(files)

        for fn in files:
            khop = int(fn.split('_')[-1].split('HOP')[0])

            print('file:{}, k:{}'.format(fn, khop))

            if m is None:
                m = read_sparse_matrix(hopspath, fn) * khop
            else:
                m += read_sparse_matrix(hopspath, fn) * khop
            m.eliminate_zeros()

            if m.max() > maximun:
                print('>>> weird: {} in k:{} in {}'.format(
                    m.max(), khop, self.name))
                return None

        #m = m.tolil()
        #m.setdiag(0)
        #m = m.tocsr()
        m.eliminate_zeros()

        comment = 'LCC: {}\nOntology: {}\nYear: {}\nSubmissionID: {}'.format(
            lcc, self.name, self.year, self.submission_id)
        field = 'integer'
        save_sparse_matrix(m, path, fn_final, comment=comment, field=field)
        return m
예제 #3
0
 def load_adjacency(self, path):
     comment = 'Clickstreams\nOntology: {}\nYear: {}\nNavitype:{}'.format(
         self.name, self.year, self.get_navitype())
     field = 'integer'
     self.T = read_sparse_matrix(path, self.get_cs_filename(path, ADJ_EXT))
예제 #4
0
 def get_khop_matrix(self, path, k, lcc=False):
     fn = self.get_khop_matrix_fn(k, lcc)
     return read_sparse_matrix(path, fn).tocsr()
예제 #5
0
 def get_khop(self, k):
     fn = self.get_khop_matrix_fn(k, lcc=self.lcc)
     return read_sparse_matrix(self.path_khop, fn)