def fit_randomWalk_mod(graphSize, graphID, dkPath, original2k, resultPath,
                       interval):
    """
    Runs synthetic graph tests for various 'qe' and 'qv' values
    If an interval was specified for fine grained sampling, please
    note that the interal is closed bounds, that is [x, y] so qe_end and qv_end
    will terminate after sampling the end values specified, not before.
    """
    if not interval:
        outfile = open(resultPath + graphID + '_rwCoarse_dkDistances.txt', 'w')
        qe = 0.1
        qe_end = 0.9
        step = 0.1

    else:
        outfile = open(resultPath + graphID + '_rwFine_dkDistances.txt', 'w')
        qe = interval[0] * 100
        qe_end = interval[1] * 100
        step = 1

    outfile.write('dk-2 Distance\tqe\tqv\n')

    while qe <= qe_end:
        if not interval:
            qv = 0.1
            qv_end = 0.9
        else:
            qv = interval[2] * 100
            qv_end = interval[3] * 100

        while qv <= qv_end:
            qeFloat = float(qe) / 100 if not interval else qe
            qvFloat = float(qv) / 100 if not interval else qv
            print 'Running modified Random Walk (coarse) with parameters: n = ', graphSize, ' qe = ', qeFloat, ' qv = ', qvFloat

            newFile = graphID + '_rwCoarse_' + str(qeFloat) + '_' + str(
                qvFloat)

            # Create synthetic graph
            syntheticGraph = sm.randomWalk_mod(graphSize, qeFloat, qvFloat)

            # Write pickle, edge list, and 2k distro to file
            print 'Calculating dK-2...\n'
            getdk2(syntheticGraph, newFile, dkPath, resultPath)

            # Find distance between the dK-2 distributions
            dkDistance = tk.get_2k_distance(
                original2k, resultPath + newFile + '_target.2k')
            outfile.write(
                str(dkDistance) + '\tqe = ' + str(qeFloat) + '\tqv = ' +
                str(qvFloat) + '\n')
            outfile.flush()

            qv += step

        qe += step

        outfile.write('\n')

    outfile.close()
def fit_forestFire_mod(graphSize, graphID, dkPath, original2k, resultPath):
    """
    Runs synthetic graph tests for various 'p' values (burn rate).
    """
    outfile = open(resultPath + graphID + '_ff_dkDistances.txt', 'w')

    p = 0.01
    while p < 1.0:
        print 'Running modified Forest Fire with parameters: n = ', graphSize, ' p = ', p

        newFile = graphID + '_ff_' + str(p)

        # Create synthetic graph
        syntheticGraph = sm.forestFire_mod(graphSize, p)

        # Write pickle, edge list, and 2k distro to file
        print 'Calculating dK-2...\n'
        getdk2(syntheticGraph, newFile, dkPath, resultPath)

        # Find distance between the dK-2 distributions
        dkDistance = tk.get_2k_distance(original2k,
                                        resultPath + newFile + '_target.2k')
        outfile.write(str(dkDistance) + '\tp = ' + str(p) + '\n')
        outfile.flush()

        p += 0.01

    outfile.close()
Ejemplo n.º 3
0
def fit_forestFire_mod(graphSize, graphID, dkPath, original2k, resultPath):
    """
    Runs synthetic graph tests for various 'p' values (burn rate).
    """
    outfile = open(resultPath + graphID + '_ff_dkDistances.txt', 'w')
    
    p = 0.01
    while p < 1.0:
        print 'Running modified Forest Fire with parameters: n = ', graphSize, ' p = ', p
        
        newFile = graphID + '_ff_' + str(p)

        # Create synthetic graph
        syntheticGraph = sm.forestFire_mod(graphSize, p)

        # Write pickle, edge list, and 2k distro to file
        print 'Writing pickle and calculating dK-2...\n'
        nx.write_gpickle(syntheticGraph, resultPath + newFile + '.pickle')
        getdk2(syntheticGraph, newFile, dkPath, resultPath)

        # Find distance between the dK-2 distributions
        dkDistance = tk.get_2k_distance(original2k, resultPath + newFile + '_target.2k')
        outfile.write(str(dkDistance) + '\tp = ' + str(p) + '\n')
        outfile.flush()

        p += 0.01

    outfile.close()
Ejemplo n.º 4
0
def fit_randomWalk_mod(graphSize, graphID, dkPath, original2k, resultPath, interval):
    """
    Runs synthetic graph tests for various 'qe' and 'qv' values
    If an interval was specified for fine grained sampling, please
    note that the interal is closed bounds, that is [x, y] so qe_end and qv_end
    will terminate after sampling the end values specified, not before.
    """
    if not interval:
        outfile = open(resultPath + graphID + '_rwCoarse_dkDistances.txt', 'w')
        qe = 0.1
        qe_end = 0.9
        step = 0.1

    else:
        outfile = open(resultPath + graphID + '_rwFine_dkDistances.txt', 'w')
        qe = interval[0] * 100
        qe_end = interval[1] * 100
        step = 1

    outfile.write('dk-2 Distance\tqe\tqv\n')

    while qe <= qe_end:
        if not interval:
            qv = 0.1
            qv_end = 0.9
        else:
            qv = interval[2] * 100
            qv_end = interval[3] * 100

        while qv <= qv_end:
            qeFloat = float(qe) / 100 if not interval else qe
            qvFloat = float(qv) / 100 if not interval else qv
            print 'Running modified Random Walk (coarse) with parameters: n = ', graphSize, ' qe = ', qeFloat, ' qv = ', qvFloat

            newFile = graphID + '_rwCoarse_' + str(qeFloat) + '_' + str(qvFloat)
            
            # Create synthetic graph
            syntheticGraph = sm.randomWalk_mod(graphSize, qeFloat, qvFloat)
            
            # Write pickle, edge list, and 2k distro to file
            print 'Writing pickle and calculating dK-2...\n'
            nx.write_gpickle(syntheticGraph, resultPath + newFile + '.pickle')
            getdk2(syntheticGraph, newFile, dkPath, resultPath)
            
            # Find distance between the dK-2 distributions
            dkDistance = tk.get_2k_distance(original2k, resultPath + newFile + '_target.2k')
            outfile.write(str(dkDistance) + '\tqe = ' + str(qeFloat) + '\tqv = ' + str(qvFloat) + '\n')
            outfile.flush()

            qv += step

        qe += step

        outfile.write('\n')

    outfile.close()
Ejemplo n.º 5
0
def fit_nearestNeighbor_mod(graphSize, graphID, dkPath, original2k, resultPath,
                            k):
    """
    Runs synthetic graph tests for various 'k' and 'u' values and stores them
    """
    if k:
        outfile = open(resultPath + graphID + '_nnFine_dkDistances.txt', 'w')
        kList = [k]
        uList = []
        myU = 0.01
        while myU < 1:
            uList.append(myU)
            myU += 0.01

    else:
        outfile = open(resultPath + graphID + '_nnCoarse_dkDistances.txt', 'w')
        kList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
        uList = [
            .01, .05, .10, .20, .25, .30, .35, .40, .45, .50, .55, .60, .65,
            .70, .75, .80, .85, .95
        ]

    outfile.write('dk-2 Distance\tk\tu\n')

    for k in kList:
        for u in uList:
            print 'Running modified Nearest Neighbor with parameters: n = ', graphSize, ' k = ', k, ' u = ', u

            newFile = graphID + '_nn_' + str(k) + '_' + str(u)

            # Create synthetic graph
            syntheticGraph = sm.nearestNeighbor_mod(graphSize, u, k)

            # Write pickle, edge list, and 2k distro to file
            print 'Writing pickle and calculating dK-2...\n'
            nx.write_gpickle(syntheticGraph, resultPath + newFile + '.pickle')
            getdk2(syntheticGraph, newFile, dkPath, resultPath)

            # Find distance between the dK-2 distributions
            dkDistance = tk.get_2k_distance(
                original2k, resultPath + newFile + '_target.2k')
            outfile.write(
                str(dkDistance) + '\tk = ' + str(k) + '\tu = ' + str(u) + '\n')
            outfile.flush()

        outfile.write('\n')

    outfile.close()
Ejemplo n.º 6
0
def fit_nearestNeighbor_mod(graphSize, graphID, dkPath, original2k, resultPath, k):
    """
    Runs synthetic graph tests for various 'k' and 'u' values and stores them
    """
    if k:
        outfile = open(resultPath + graphID + '_nnFine_dkDistances.txt', 'w')
        kList = [k]
        uList = []
        myU = 0.01
        while myU < 1:
            uList.append(myU)
            myU += 0.01
        
    else:
        outfile = open(resultPath + graphID + '_nnCoarse_dkDistances.txt', 'w')
        kList = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
        uList = [.01, .05, .10, .20, .25,.30, .35, .40, .45, .50,
                  .55, .60, .65, .70, .75,.80, .85, .95]

    outfile.write('dk-2 Distance\tk\tu\n')

    for k in kList:
        for u in uList:
            print 'Running modified Nearest Neighbor with parameters: n = ', graphSize, ' k = ', k, ' u = ', u
            
            newFile = graphID + '_nn_' + str(k) + '_' + str(u)

            # Create synthetic graph
            syntheticGraph = sm.nearestNeighbor_mod(graphSize, u, k)

            # Write pickle, edge list, and 2k distro to file
            print 'Writing pickle and calculating dK-2...\n'
            nx.write_gpickle(syntheticGraph, resultPath + newFile + '.pickle')
            getdk2(syntheticGraph, newFile, dkPath, resultPath)

            # Find distance between the dK-2 distributions
            dkDistance = tk.get_2k_distance(original2k, resultPath + newFile + '_target.2k')
            outfile.write(str(dkDistance) + '\tk = ' + str(k) + '\tu = ' + str(u) + '\n')
            outfile.flush()

        outfile.write('\n')

    outfile.close()