def __init__(self, vertices, undirected=True, W=None, sizeHint=1000): """ Create a PySparseGraph with a given AbstractVertexList or number of vertices, and specify whether it is directed. One can optionally pass in a sparse matrix W which is used as the weight matrix of the graph. Different kinds of sparse matrix can impact the speed of various operations. The currently supported sparse matrix types are: ll_mat. :param vertices: the initial set of vertices as a AbstractVertexList object, or an int to specify the number of vertices in which case vertices are stored in a GeneralVertexList. :param undirected: a boolean variable to indicate if the graph is undirected. :type undirected: :class:`boolean` :param W: a square sparse matrix of the same size as the number of vertices, or None to create the default one. :param sizeHint: the expected number of edges in the graph for efficient memory usage. :type sizeHint: :class:`int` """ Parameter.checkBoolean(undirected) if isinstance(vertices, AbstractVertexList): self.vList = vertices elif isinstance(vertices, int): self.vList = GeneralVertexList(vertices) else: raise ValueError("Invalid vList parameter: " + str(vertices)) if W != None and not (isinstance(W, spmatrix.LLMatType) and W.shape == (len(self.vList), len(self.vList))): raise ValueError( "Input argument W must be None or spmatrix.ll_mat of size " + str(len(self.vList))) self.undirected = undirected if W == None: #Should use ll_mat_sym for undirected graphs but it has several unimplemented methods self.W = spmatrix.ll_mat(len(self.vList), len(self.vList), sizeHint) else: self.W = W #The next line is for error checking mainly self.setWeightMatrix(W)
def __init__(self, vertices, undirected=True, W=None, dtype=numpy.float): """ Create a DenseGraph with a given AbstractVertexList or number of vertices, and specify whether it is directed. One can optionally pass in a numpy array W which is used as the weight matrix of the graph. :param vertices: the initial set of vertices as a AbstractVertexList object, or an int to specify the number of vertices in which case vertices are stored in a GeneralVertexList. :param undirected: a boolean variable to indicate if the graph is undirected. :type undirected: :class:`boolean` :param W: a numpy array of the same size as vertices, or None to create the default one. :param dtype: the data type of the weight matrix if W is not specified e.g numpy.int8. """ Parameter.checkBoolean(undirected) if isinstance(vertices, AbstractVertexList): self.vList = vertices elif isinstance(vertices, int): self.vList = GeneralVertexList(vertices) else: raise ValueError("Invalid vList parameter: " + str(vertices)) if W != None and not (isinstance(W, numpy.ndarray) and W.shape == (len(self.vList), len(self.vList))): raise ValueError( "Input argument W must be None or numpy array of size " + str(len(self.vList))) self.undirected = undirected if W == None: self.W = numpy.zeros((len(self.vList), len(self.vList)), dtype=dtype) else: self.W = W #The next line is for error checking mainly self.setWeightMatrix(W)
def __init__(self, vertices, undirected=True, dtype=numpy.float): """ Create a sparse graph using sppy csarray with a given AbstractVertexList, and specify whether directed. :param vertices: the initial set of vertices as a AbstractVertexList object, or an int to specify the number of vertices in which case vertices are stored in a GeneralVertexList. :param undirected: a boolean variable to indicate if the graph is undirected. :type undirected: :class:`boolean` :param dtype: the data type for the weight matrix, e.g numpy.int8. """ Parameter.checkBoolean(undirected) if isinstance(vertices, AbstractVertexList): self.vList = vertices elif isinstance(vertices, int): self.vList = GeneralVertexList(vertices) else: raise ValueError("Invalid vList parameter: " + str(vertices)) self.W = sppy.csarray( (self.vList.getNumVertices(), self.vList.getNumVertices()), dtype) self.undirected = undirected
r2 = max((k - r), 0) sigmaSqSum = (sigma[0:r2]**2).sum() bound = gammaSqSum + lmbdaSqSum - 2 * sigmaSqSum print("r=" + str(r)) print("gammaSqSum=" + str(gammaSqSum)) print("lmbdaSqSum=" + str(lmbdaSqSum)) print("sigmaSqSum=" + str(sigmaSqSum)) return bound #Change to work with real Laplancian numRows = 100 graph = SparseGraph(GeneralVertexList(numRows)) p = 0.1 generator = ErdosRenyiGenerator(p) graph = generator.generate(graph) print(graph) AA = graph.normalisedLaplacianSym() p = 0.001 generator.setP(p) graph = generator.generate(graph, requireEmpty=False) AA2 = graph.normalisedLaplacianSym()