コード例 #1
0
def main(directed):

    logfile = 'results-permutations/timigs-{}.txt'.format(
        'directed' if directed else 'undirected')
    memory = Profiling(
        'Permutations {}'.format('directed' if directed else 'undirected'),
        'results-permutations/python-profiling-nperm-nodes{}-{}.png'.format(
            NCOUNTRIES, 'directed' if directed else 'undirected'), True)
    memory.check_memory('init-{}'.format('d' if directed else 'i'))

    #######################################################################
    # Data Matrices
    #######################################################################
    X1 = getMatrix('data-permutations/country_trade_index.txt', directed, True)
    memory.check_memory('X1-{}'.format('d' if directed else 'i'))
    X2 = getMatrix('data-permutations/country_distance_index.txt', directed,
                   True)
    memory.check_memory('X2-{}'.format('d' if directed else 'i'))
    X3 = getMatrix('data-permutations/country_colonial_index.txt', directed)
    Y = getMatrix('data-permutations/country_lang_index.txt', directed)
    memory.check_memory('Y-{}'.format('d' if directed else 'i'))
    X = {'TRADE': X1, 'DISTANCE': X2, 'COLONIAL': X3}
    Y = {'LANG': Y}
    np.random.seed(1)

    #######################################################################
    # QAP
    #######################################################################
    perms = np.logspace(1, 7, num=7 - 1, endpoint=False)
    for nperm in perms:
        start_time = time.time()
        mrqap = MRQAP(Y=Y,
                      X=X,
                      npermutations=int(nperm),
                      diagonal=False,
                      directed=directed,
                      logfile=logfile,
                      memory=memory)
        mrqap.mrqap()

        utils.printf(
            "--- {}, nperm {}: {} seconds ---".format(
                'directed' if directed else 'undirected', nperm,
                time.time() - start_time), logfile)
        mrqap.summary()

        fn = 'results-permutations/python-nperm{}-{}-<coef>.png'.format(
            nperm, 'directed' if directed else 'undirected')
        mrqap.plot('betas', fn.replace('<coef>', 'betas'))
        mrqap.plot('tvalues', fn.replace('<coef>', 'tvalues'))

        utils.printf(
            '******************************************************************************\n\n',
            logfile)
        del (mrqap)
    return
def main(directed):

    logfile = 'results-synthetic-ernos-renyi/timigs-{}.txt'.format('directed' if directed else 'undirected')
    memory = Profiling('Nodes {}'.format('directed' if directed else 'undirected'), 'results-synthetic-ernos-renyi/python-profiling-netsize-edgeprob{}-nperm{}-{}.png'.format(EDGEPROB, NPERMUTATIONS,'directed' if directed else 'undirected'), False)
    memory.check_memory('init-{}'.format('d' if directed else 'i'))

    #######################################################################
    # Data Matrices
    #######################################################################
    #nnodes = np.logspace(1,7,num=7-1, endpoint=False)
    nnodes = np.logspace(1,5,num=5-1, endpoint=False)
    for n in nnodes:
        n = int(n)
        fn = 'data-synthetic-ernos-renyi/nodes{}_edgeprob{}_<var>.dat'.format(n,EDGEPROB)
        memory.check_memory('nodes-{}'.format(n))
        X1 = generateGraph(n,EDGEPROB,directed, fn.replace('<var>','X1'))
        memory.check_memory('X1-{}'.format(n))
        X2 = generateGraph(n,EDGEPROB,directed, fn.replace('<var>','X2'))
        memory.check_memory('X2-{}'.format(n))
        X3 = generateGraph(n,EDGEPROB,directed, fn.replace('<var>','X3'))
        memory.check_memory('X3-{}'.format(n))
        Y  = generateGraph(n,EDGEPROB,directed, fn.replace('<var>','Y'))
        memory.check_memory('Y-{}'.format(n))
        X = {'X1':X1, 'X2':X2, 'X3':X3}
        Y = {'Y':Y}

        #######################################################################
        # QAP
        #######################################################################
        start_time = time.time()
        mrqap = MRQAP(Y=Y, X=X, npermutations=int(NPERMUTATIONS), diagonal=False, directed=directed, logfile=logfile, memory=memory)
        mrqap.mrqap()

        utils.printf("\n--- {}, nodes {}: {} seconds ---".format('directed' if directed else 'undirected', n, time.time() - start_time), logfile)
        mrqap.summary()

        fn = 'results-synthetic-ernos-renyi/python-nodes{}-edgeprob{}-nperm{}-{}-<coef>.png'.format(n, EDGEPROB, NPERMUTATIONS,'directed' if directed else 'undirected')
        mrqap.plot('betas',fn.replace('<coef>','betas'))
        mrqap.plot('tvalues',fn.replace('<coef>','tvalues'))

        utils.printf('******************************************************************************\n\n', logfile)
        del(mrqap)
    return
def main(directed):

    logfile = 'results-permutations/timigs-{}.txt'.format('directed' if directed else 'undirected')
    memory = Profiling('Permutations {}'.format('directed' if directed else 'undirected'), 'results-permutations/python-profiling-nperm-nodes{}-{}.png'.format(NCOUNTRIES,'directed' if directed else 'undirected'), True)
    memory.check_memory('init-{}'.format('d' if directed else 'i'))

    #######################################################################
    # Data Matrices
    #######################################################################
    X1 = getMatrix('data-permutations/country_trade_index.txt',directed,True)
    memory.check_memory('X1-{}'.format('d' if directed else 'i'))
    X2 = getMatrix('data-permutations/country_distance_index.txt',directed,True)
    memory.check_memory('X2-{}'.format('d' if directed else 'i'))
    X3 = getMatrix('data-permutations/country_colonial_index.txt',directed)
    Y  = getMatrix('data-permutations/country_lang_index.txt',directed)
    memory.check_memory('Y-{}'.format('d' if directed else 'i'))
    X = {'TRADE':X1, 'DISTANCE':X2, 'COLONIAL':X3}
    Y = {'LANG':Y}
    np.random.seed(1)

    #######################################################################
    # QAP
    #######################################################################
    perms = np.logspace(1,7,num=7-1, endpoint=False)
    for nperm in perms:
        start_time = time.time()
        mrqap = MRQAP(Y=Y, X=X, npermutations=int(nperm), diagonal=False, directed=directed, logfile=logfile, memory=memory)
        mrqap.mrqap()

        utils.printf("--- {}, nperm {}: {} seconds ---".format('directed' if directed else 'undirected', nperm, time.time() - start_time), logfile)
        mrqap.summary()

        fn = 'results-permutations/python-nperm{}-{}-<coef>.png'.format(nperm,'directed' if directed else 'undirected')
        mrqap.plot('betas', fn.replace('<coef>','betas'))
        mrqap.plot('tvalues', fn.replace('<coef>','tvalues'))

        utils.printf('******************************************************************************\n\n', logfile)
        del(mrqap)
    return
コード例 #4
0
#######################################################################
import numpy as np
from libs.mrqap import MRQAP

#######################################################################
# Data
# Source: http://vlado.fmf.uni-lj.si/pub/networks/data/ucinet/ucidata.htm
#######################################################################
X1 = np.loadtxt('data/crudematerials.dat')
X2 = np.loadtxt('data/foods.dat')
X3 = np.loadtxt('data/manufacturedgoods.dat')
X4 = np.loadtxt('data/minerals.dat')
Y = np.loadtxt('data/diplomatic.dat')
X = {
    'CRUDEMATERIALS': X1,
    'FOODS': X2,
    'MANUFACTUREDGOODS': X3,
    'MINERALS': X4
}
Y = {'DIPLOMATIC': Y}
np.random.seed(473)

#######################################################################
# QAP
#######################################################################
mrqap = MRQAP(Y=Y, X=X, npermutations=2000, diagonal=False, directed=True)
mrqap.mrqap()
mrqap.summary()
mrqap.plot('betas')
mrqap.plot('tvalues')
コード例 #5
0
X2 = np.loadtxt('data-cg/noise-5.0.matrix',delimiter=',')
X3  = np.loadtxt('data-cg/noise-10.0.matrix',delimiter=',')
X4  = np.loadtxt('data-cg/noise-100.0.matrix',delimiter=',')
X5  = np.loadtxt('data-cg/noise-1000.0.matrix',delimiter=',')
X6  = np.loadtxt('data-cg/20Homophily-80Heterophily.matrix',delimiter=',')
X7  = np.loadtxt('data-cg/80Homophily-20Heterophily.matrix',delimiter=',')
X8  = np.loadtxt('data-cg/80ToBlue-20ToRed.matrix',delimiter=',')
X9  = np.loadtxt('data-cg/80ToRed-20ToBlue.matrix',delimiter=',')
X10  = np.loadtxt('data-cg/90Homophily-10Heterophily.matrix',delimiter=',')
X11  = np.loadtxt('data-cg/100Homophily-0Heterophily.matrix',delimiter=',')
X12  = np.loadtxt('data-cg/ToBlueOnly.matrix',delimiter=',')
X13  = np.loadtxt('data-cg/ToRedOnly.matrix',delimiter=',')
X14  = np.loadtxt('data-cg/uniform-0.02.matrix',delimiter=',')

X = {'NOISE1':X1, 'NOISE5':X2, 'NOISE10':X3, 'NOISE100':X4, 'NOISE1000':X5,
     'Hom20Het80':X6, 'Hom80Het20':X7, 'Blue80Red20':X8, 'Red80Blue20':X9,
     'Hom90Het10':X10,'Hom100Het0':X11, 'ToBlue':X12, 'ToRed':X13, 'UNIFORM':X14}
Y = {'DATA':Y}
np.random.seed(1)

#######################################################################
# QAP
#######################################################################
start_time = time.time()
mrqap = MRQAP(Y=Y, X=X, npermutations=NPERMUTATIONS, diagonal=False, directed=DIRECTED, standarized=True)
mrqap.mrqap()
mrqap.summary()
print("--- {}, {}: {} seconds ---".format('directed' if DIRECTED else 'undirected', NPERMUTATIONS, time.time() - start_time))
mrqap.plot('betas','results-cg/betas.pdf')
mrqap.plot('tvalues','results-cg/tvalues.pdf')
def main(directed):

    logfile = 'results-synthetic-ernos-renyi/timigs-{}.txt'.format(
        'directed' if directed else 'undirected')
    memory = Profiling(
        'Nodes {}'.format('directed' if directed else 'undirected'),
        'results-synthetic-ernos-renyi/python-profiling-netsize-edgeprob{}-nperm{}-{}.png'
        .format(EDGEPROB, NPERMUTATIONS,
                'directed' if directed else 'undirected'), False)
    memory.check_memory('init-{}'.format('d' if directed else 'i'))

    #######################################################################
    # Data Matrices
    #######################################################################
    #nnodes = np.logspace(1,7,num=7-1, endpoint=False)
    nnodes = np.logspace(1, 5, num=5 - 1, endpoint=False)
    for n in nnodes:
        n = int(n)
        fn = 'data-synthetic-ernos-renyi/nodes{}_edgeprob{}_<var>.dat'.format(
            n, EDGEPROB)
        memory.check_memory('nodes-{}'.format(n))
        X1 = generateGraph(n, EDGEPROB, directed, fn.replace('<var>', 'X1'))
        memory.check_memory('X1-{}'.format(n))
        X2 = generateGraph(n, EDGEPROB, directed, fn.replace('<var>', 'X2'))
        memory.check_memory('X2-{}'.format(n))
        X3 = generateGraph(n, EDGEPROB, directed, fn.replace('<var>', 'X3'))
        memory.check_memory('X3-{}'.format(n))
        Y = generateGraph(n, EDGEPROB, directed, fn.replace('<var>', 'Y'))
        memory.check_memory('Y-{}'.format(n))
        X = {'X1': X1, 'X2': X2, 'X3': X3}
        Y = {'Y': Y}

        #######################################################################
        # QAP
        #######################################################################
        start_time = time.time()
        mrqap = MRQAP(Y=Y,
                      X=X,
                      npermutations=int(NPERMUTATIONS),
                      diagonal=False,
                      directed=directed,
                      logfile=logfile,
                      memory=memory)
        mrqap.mrqap()

        utils.printf(
            "\n--- {}, nodes {}: {} seconds ---".format(
                'directed' if directed else 'undirected', n,
                time.time() - start_time), logfile)
        mrqap.summary()

        fn = 'results-synthetic-ernos-renyi/python-nodes{}-edgeprob{}-nperm{}-{}-<coef>.png'.format(
            n, EDGEPROB, NPERMUTATIONS,
            'directed' if directed else 'undirected')
        mrqap.plot('betas', fn.replace('<coef>', 'betas'))
        mrqap.plot('tvalues', fn.replace('<coef>', 'tvalues'))

        utils.printf(
            '******************************************************************************\n\n',
            logfile)
        del (mrqap)
    return
コード例 #7
0
    'NOISE5': X2,
    'NOISE10': X3,
    'NOISE100': X4,
    'NOISE1000': X5,
    'ERDOS05': X6,
    'ERDOS1': X7,
    'GEOMETRIC1': X8,
    'BARABASI49': X9,
    'UNIFORM': X10
}
Y = {'DATA': Y}
np.random.seed(1)

#######################################################################
# QAP
#######################################################################
start_time = time.time()
mrqap = MRQAP(Y=Y,
              X=X,
              npermutations=NPERMUTATIONS,
              diagonal=False,
              directed=DIRECTED,
              standarized=False)
mrqap.mrqap()
mrqap.summary()
print("--- {}, {}: {} seconds ---".format(
    'directed' if DIRECTED else 'undirected', NPERMUTATIONS,
    time.time() - start_time))
mrqap.plot('betas', 'results-rg/betas.pdf')
mrqap.plot('tvalues', 'results-rg/tvalues.pdf')
コード例 #8
0
    # assert both countries have sufficient population size for study
    if not (pair[0] in code_index_map.keys()
            and pair[1] in code_index_map.keys()):
        continue

    i = code_index_map.get(pair[0])
    j = code_index_map.get(pair[1])

    # put densities into matrix
    density_matrix[i, j] = code_pairs_to_densities.get(key)
    density_matrix[j, i] = code_pairs_to_densities.get(key)

dependents = {
    "COMMUNICATION_DENSITY": density_matrix,
}

###########################################
###########################################
# PERFORM MRQAP
###########################################
###########################################

NPERMUTATIONS = 2000

mrqap = MRQAP(Y=dependents,
              X=independents,
              npermutations=NPERMUTATIONS,
              diagonal=False,
              directed=False)
mrqap.mrqap()
mrqap.summary()
コード例 #9
0
#######################################################################

#######################################################################
# Dependencies
#######################################################################
import numpy as np
from libs.mrqap import MRQAP

#######################################################################
# Data
# Source: http://vlado.fmf.uni-lj.si/pub/networks/data/ucinet/ucidata.htm
#######################################################################
X1 = np.loadtxt('data/crudematerials.dat')
X2 = np.loadtxt('data/foods.dat')
X3 = np.loadtxt('data/manufacturedgoods.dat')
X4 = np.loadtxt('data/minerals.dat')
Y = np.loadtxt('data/diplomatic.dat')
X = {'CRUDEMATERIALS':X1, 'FOODS':X2, 'MANUFACTUREDGOODS':X3, 'MINERALS':X4}
Y = {'DIPLOMATIC':Y}
np.random.seed(473)

#######################################################################
# QAP
#######################################################################
mrqap = MRQAP(Y=Y, X=X, npermutations=2000, diagonal=False, directed=True)
mrqap.mrqap()
mrqap.summary()
mrqap.plot('betas')
mrqap.plot('tvalues')