def computeInfectConfigGraphs():
    #We need the directed infection graph 
    hivReader = HIVGraphReader()
    graph = hivReader.readHIVGraph(False)
    sGraphInfect = graph.getSparseGraph(edgeTypeIndex2)
    sGraph = sGraphInfect

    graphFileNameBase = resultsDir + "ConfigInfectGraph"

    for j in range(numGraphs):
        configGraph = SparseGraph(GeneralVertexList(numVertices), False)
        
        outDegSequence = numpy.zeros(numVertices, numpy.int)
        inDegSequence = numpy.zeros(numVertices, numpy.int)
        lastOutDegSequence = numpy.zeros(numVertices, numpy.int)
        lastInDegSequence = numpy.zeros(numVertices, numpy.int)
        generator = ConfigModelGenerator(lastOutDegSequence, lastInDegSequence)

        for i in dayList:
            logging.info("Date: " + str(DateUtils.getDateStrFromDay(i, startYear)))
            subgraphIndices = numpy.nonzero(detections <= i)[0]
            subgraphIndices = numpy.unique(subgraphIndices)
            subgraph = sGraph.subgraph(subgraphIndices)

            outDegSequence[subgraphIndices] = subgraph.outDegreeSequence()
            inDegSequence[subgraphIndices] = subgraph.inDegreeSequence()
            outDiffSequence = outDegSequence - lastOutDegSequence
            inDiffSequence = inDegSequence - lastInDegSequence

            generator.setInDegSequence(inDiffSequence)
            generator.setOutDegSequence(outDiffSequence)
            configGraph = generator.generate(configGraph, False)

            lastOutDegSequence = configGraph.outDegreeSequence()
            lastInDegSequence = configGraph.inDegreeSequence()

            assert (outDegSequence>=lastOutDegSequence).all()
            assert (inDegSequence>=lastInDegSequence).all()

        configGraph.save(graphFileNameBase + str(j))
Example #2
0
import numpy
from apgl.graph import *
from apgl.viroscopy.HIVGraphReader import HIVGraphReader
from apgl.util.PathDefaults import PathDefaults
from apgl.util.DateUtils import DateUtils
from exp.sandbox.IterativeSpectralClustering import IterativeSpectralClustering
from exp.sandbox.GraphIterators import IncreasingSubgraphListIterator

numpy.random.seed(21)
numpy.seterr("raise")
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
numpy.set_printoptions(suppress=True, linewidth=60)

#Start off with the HIV data
hivReader = HIVGraphReader()
graph = hivReader.readHIVGraph()
fInds = hivReader.getIndicatorFeatureIndices()

#The set of edges indexed by zeros is the contact graph
#The ones indexed by 1 is the infection graph
edgeTypeIndex1 = 0
edgeTypeIndex2 = 1
sGraphContact = graph.getSparseGraph(edgeTypeIndex1)
sGraphInfect = graph.getSparseGraph(edgeTypeIndex2)
sGraphContact = sGraphContact.union(sGraphInfect)
graph = sGraphContact

#Find max component
components = graph.findConnectedComponents()
graph = graph.subgraph(list(components[0]))
#graph = graph.subgraph(range(500))
from apgl.util.DateUtils import DateUtils
from apgl.util.Latex import Latex
from apgl.util.Util import Util
from apgl.graph import *
from apgl.viroscopy.HIVGraphReader import HIVGraphReader

"""
This script computes some basic statistics on the growing infection graph.
"""

logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
numpy.set_printoptions(suppress=True, linewidth=100, precision=3)

undirected = False 
hivReader = HIVGraphReader()
graph = hivReader.readHIVGraph(undirected, indicators=False)
fInds = hivReader.getNonIndicatorFeatureIndices()


figureDir = PathDefaults.getOutputDir() + "viroscopy/figures/infect/"
resultsDir = PathDefaults.getOutputDir() + "viroscopy/"

#The set of edges indexed by zeros is the contact graph
#The ones indexed by 1 is the infection graph
edgeTypeIndex1 = 0
edgeTypeIndex2 = 1
sGraphContact = graph.getSparseGraph(edgeTypeIndex1)
sGraphInfect = graph.getSparseGraph(edgeTypeIndex2)

sGraph = sGraphInfect
#sGraph = sGraph.subgraph(range(0, 500))
Example #4
0
matplotlib.use('WXAgg') # do this before importing pylab
import matplotlib.pyplot as plt


"""
Let's compute some basic statistics of the infection and contact graph at the
end of the epidemic.
"""

logging.basicConfig(stream=sys.stdout, level=logging.INFO)

figureDir = PathDefaults.getOutputDir() + "viroscopy/figures/"

undirected = False 
hivReader = HIVGraphReader()
graph = hivReader.readHIVGraph(undirected)
fInds = hivReader.getIndicatorFeatureIndices()

#The set of edges indexed by zeros is the contact graph
#The ones indexed by 1 is the infection graph
edgeTypeIndex1 = 0
edgeTypeIndex2 = 1
sGraphContact = graph.getSparseGraph(edgeTypeIndex1)
sGraphInfect = graph.getSparseGraph(edgeTypeIndex2)

numpy.set_printoptions(precision=3, suppress=True)

logging.info("Statistics over Verticies ")
logging.info("===============================")
#Other measures :  infection period of tree, infection types
#PCA to find variance of data, correlation matrix, center matrix