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 logging
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]))
from apgl.util.PathDefaults import PathDefaults
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
import logging
import sys
import matplotlib
matplotlib.use('WXAgg') # do this before importing pylab
import matplotlib.pyplot 
import networkx
import numpy
import wx
import math
from apgl.viroscopy.HIVGraphReader import HIVGraphReader
from apgl.util.GraphLayoutEngine import GraphLayoutEngine
from apgl.util.DateUtils import DateUtils

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

hivReader = HIVGraphReader()
graph = hivReader.readHIVGraph()

#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)

sGraph = sGraphContact
nxGraph = sGraph.toNetworkXGraph()

print(("Number of vertices: " + str(sGraph.getNumVertices())))
print(("Number of features: " + str(sGraph.getVertexList().getNumFeatures())))