示例#1
0
 def graphFromMatFile(matFileName):
     """
     Generate a sparse graph from a Matlab file of ego and alters and their transmissions. This is a mostly 
     disconnected graph made up of pairs of connected vertices, i.e each vertex has degree 1.  
     """
     examplesList = ExamplesList.readFromMatFile(matFileName)
     numExamples = examplesList.getNumExamples()
     numFeatures = examplesList.getDataFieldSize("X", 1)
     numVertexFeatures = numFeatures/2+1
     vList = VertexList(numExamples*2, int(numVertexFeatures))
     sGraph = SparseGraph(vList)
     
     for i in range(0, examplesList.getNumExamples()): 
         v1Index = i*2 
         v2Index = i*2+1
         example = examplesList.getSubDataField("X", numpy.array([i])).ravel()
         vertex1 = numpy.r_[example[0:numFeatures/2], numpy.array([1])]
         vertex2 = numpy.r_[example[numFeatures/2:numFeatures], numpy.array([0])]
         
         sGraph.setVertex(v1Index, vertex1)
         sGraph.setVertex(v2Index, vertex2)
         sGraph.addEdge(v1Index, v2Index)
     
     return sGraph