Esempio n. 1
0
    def vertex_labels(self, target=4, return_name=False):
        rawlb, raw_names = self.__vertex_raw_labels(return_name=True)
        if target == 'raw':
            lb = rawlb
            label_names = raw_names
        else:
            lb = rawlb.copy()

            # TODO: make sure the order of lb (i.e. order of feat) is 0:nnodes
            def mapper(x):
                if x == target:
                    return 1
                elif x == -1:
                    return 0
                else:
                    return -1

            lb = np.vectorize(mapper)(lb)
            label_names = {-1: 'Others', 1: raw_names[target], 0: 'Unknown'}

        assert lb.shape == (len(self.gtgraphs), self.gtgraphs['any'].num_vertices()), \
            "{}, ({}, {})".format(lb.shape, len(self.gtgraphs), self.gtgraphs['any'].num_vertices())

        if return_name:
            return utils.OffsetList(self.localstep, len(lb), lb,
                                    copy=False), label_names
        else:
            return utils.OffsetList(self.localstep, len(lb), lb, copy=False)
Esempio n. 2
0
 def _load_graph(self, step):
     curunit = self._time2unit(self.step2time(step))
     graphs = []
     for u in range(curunit, curunit + self.stepsize):
         graphs.append(self._load_unit_graph(self._unit2time(u)))
     return self._merge_unit_graphs(
         utils.OffsetList(0, self.stepsize, graphs, copy=False), step)
Esempio n. 3
0
 def __init__(self, inittime, localtime, nsteps, stepsize, stepstride,
              stepoffset):
     # Timeline anchors the starting time while DynamicGraph bounds the ending
     Timeline.__init__(self, inittime, stepsize, stepstride)
     self.localstep = self.time2step(localtime) + stepoffset
     self.localunit = self._step2unit(self.localstep)
     if self._step2unit(self.localstep) < self._time2unit(inittime):
         raise RuntimeError(
             "localstep smaller than initial step, with inittime={}, localtime={},"
             " step_stride={}, step_offset={}".format(
                 inittime, localtime, stepstride, stepoffset))
     self.nsteps = nsteps
     self.nunits = self._step2unit(self.localstep + self.nsteps -
                                   1) - self.localunit + self.stepsize
     # we use mygraph as main data, with supportive gtgraphs available
     self._mygraphs = utils.OffsetList(self.localstep, self.nsteps,
                                       lambda step: self._load_graph(step))
     self._gtgraphs = utils.OffsetList(
         self.localstep, self.nsteps,
         lambda i: self._mygraphs[i].to_undirected())
Esempio n. 4
0
    def __init__(self, **kwargs):
        self._pos = None
        self._pos_range = [-1, 1]
        self._neg = None
        self._valid = None
        self._negdup = kwargs.get('negdup', 1)

        self.__enable_cache = kwargs.get('replace_cache', False)
        self._replace_cache = utils.OffsetList(self.dataset.gtgraphs.offset,
                                               len(self.dataset.gtgraphs),
                                               lambda x: None)
Esempio n. 5
0
    def __init__(self, **kwargs):
        super(Sampler, self).__init__(**kwargs)

        self.__enable_cache = kwargs.get('triangle_cache', False)
        self._triangular_cache = utils.OffsetList(self.dataset.localstep,
                                                  self.dataset.nsteps,
                                                  lambda x: None)
        # self._triangular_cache = [None for _ in range(len(self.dataset.gtgraphs))]
        # self._edge_cache = [None for _ in range(len(self.dataset.gtgraphs))]
        self.__nbr_cache = [{} for _ in range(self.dataset.nsteps)]
        self.__succ_trial, self.__all_trial = 10, 12