Exemple #1
0
    def runExperimentEdges(self, step=5, end=50, mode=0, sname=None):
        """
        mode
            0   random edge delete
            1   random edge rewiring
        """
        #cnumber = {0:self.coreNumber(can_cache=True)}
        cnumber = {0: nx.core_number(self.graph)}
        size = int(self.graph.number_of_edges() * step * 0.01)

        if mode == 0:
            noise = missing.MissingData()
        elif mode == 1:
            noise = rewire.RewireEdges()

        for i in xrange(1, int(end / step)):
            if mode == 0:
                self.graph = noise.removeRandomEdges(self.graph, size)
            elif mode == 1:
                self.graph = noise.rewire(self.graph, size)
            cnumber[i * step] = nx.core_number(self.graph)

        #    if i*step % 10 == 0:
        #        nx.write_edgelist(self.graph, self.sname + '_' + str(i*step) + '.edgelist', data=False)
        return cnumber
Exemple #2
0
    def runExperimentNode(self, step=5, end=50):
        cnumber = {0: self.coreNumber(can_cache=True)}

        noise = missing.MissingData()
        size = int(self.graph.number_of_nodes() * step * 0.01)

        for i in xrange(1, int(end / step)):
            self.graph = noise.removeRandomNodes(self.graph, size)
            cnumber[i * step] = self.coreNumber()
        return cnumber
Exemple #3
0
    def runExperimentNode(self, r=3, s=4, step=10, end=50):
        nucleii = {0: self.getNucleii(r, s, can_cache=True)}

        noise = missing.MissingData()
        size = int(self.graph.number_of_nodes() * step * 0.01)

        for i in xrange(1, int(end / step)):
            self.graph = noise.removeRandomNodes(self.graph, size)
            print(size, 'nodes', self.graph.number_of_nodes())
            nucleii[i * step] = self.getNucleii(r, s)

        return nucleii
Exemple #4
0
    def coreMissing(self, nodes, core_ori):
        stop = 80
        step = 2
        iterer = 10
        cnumber = {n: [] for n in nodes}
        size = int(self.graph.number_of_edges() * step * 0.01)
        noise = missing.MissingData()

        header = [
            'k_' + str(i * step) for i in xrange(0,
                                                 int(stop / step) + 1)
        ]

        for _ in xrange(0, iterer):
            self.graph = nx.read_edgelist(self.fname)
            for i in xrange(0, int(stop / step)):
                self.graph = noise.removeRandomEdges(self.graph, size)
                cn = self.coreNumber()

                for n in cnumber:
                    if len(cnumber[n]) < i + 1:
                        cnumber[n].append([])
                    if n in cn:
                        cnumber[n][i].append(cn[n])
                    else:
                        cnumber[n][i].append(0)
        data = {}
        for n in nodes:
            data[n] = [core_ori[n]]
            for d in cnumber[n]:
                data[n].append(np.mean(d))

        header += [
            'k_diff_' + str(i * step) for i in xrange(1,
                                                      int(stop / step) + 1)
        ]
        for n in nodes:
            for d in cnumber[n]:
                data[n].append(core_ori[n] - np.mean(d))

        header += [
            'k_diff_ratio_' + str(i * step)
            for i in xrange(1,
                            int(stop / step) + 1)
        ]
        for n in nodes:
            for d in cnumber[n]:
                data[n].append((core_ori[n] - np.mean(d)) / core_ori[n])

        return data, header
Exemple #5
0
    def runExperimentEdges(self, r=3, s=4, step=10, end=50, mode=0):
        """
        mode
            0   random edge delete
            1   random edge rewiring
        """
        nucleii = {0: self.getNucleii(r, s, can_cache=True)}
        size = int(self.graph.number_of_edges() * step * 0.01)

        if mode == 0:
            noise = missing.MissingData()
        elif mode == 1:
            noise = rewire.RewireEdges()

        for i in xrange(1, int(end / step)):
            if mode == 0:
                self.graph = noise.removeRandomEdges(self.graph, size)
            elif mode == 1:
                self.graph = noise.rewire(self.graph, size)
            nucleii[i * step] = self.getNucleii(r, s)

        return nucleii
Exemple #6
0
    def runExperimentEdges(self, step=5, end=50, mode=0):
        """
        mode
            0   random edge delete
            1   random edge rewiring
        """
        tnumber = {0: self.trussNumber(can_cache=True)}
        size = int(self.graph.number_of_edges() * step * 0.01)

        if mode == 0:
            noise = missing.MissingData()
        elif mode == 1:
            noise = rewire.RewireEdges()

        for i in xrange(1, int(end / step)):
            if mode == 0:
                self.graph = noise.removeRandomEdges(self.graph, size)
            elif mode == 1:
                self.graph = noise.rewire(self.graph, size)
            tnumber[i * step] = self.trussNumber()

        return tnumber
Exemple #7
0
def removeEdges(graph, pc):
    noise = missing.MissingData()
    size = int(graph.number_of_edges() * pc * 0.01)
    return noise.removeRandomEdges(graph, size)