Esempio n. 1
0
        pairs = []
        r = csv.reader(csvfile)
        for row in r:
            a = names[row[0]]
            b = names[row[1]]
            t = (a, b, int(row[2]))
            pairs.append(t)

        return pairs

def get_adjacency(pairs):
    maxtuple = max(pairs, key=maxpair)
    matsize = max(maxtuple) + 1
    mat = [[0 for a in range(matsize)] for a in range(matsize)]
    for p in pairs:
        mat[p[1]][p[0]] = p[2]
        # mat[p[0]][p[1]] = -p[2]

    return mat

def maxpair(p):
    return max(p[:2])

if __name__ == "__main__":
    names = utils.get_name_map("mississippi_county.list")
    pairs = get_pairs("mississippi_graph_NS.csv", names)
    mat = get_adjacency(pairs)
    s = utils.to_matlab(mat, 'adj')
    print s

Esempio n. 2
0
#! /usr/bin/python

import utils

def get_mat(names, population):
    mat = []
    for t in population:
        mat.append(t[1])
    return mat

if __name__ == "__main__":
    populations = utils.get_population("mississippi_county_pop.csv")
    names = utils.get_name_map("mississippi_county.list")
    mat = get_mat(names, populations)
    s = utils.to_matlab(mat, 'pops')
    print s
Esempio n. 3
0
    if dist/rad > 3:
        return 1000000
    if cat == 1:
        return 0.5
    th = 0.1 * 2**(dist/rad) / cat
    return th

def dist(p1, p2):
    return vincenty(p1, p2).kilometers

def compute_thresholds(clat, clong, rad, cat):
    positions = pk.load(open("county_locations.dict"))
    positions = sorted(positions.items(), key=lambda (k, v) : k)
    positions = map(lambda (k, v) : (v[0], v[1]), positions)
    distances = map(lambda p: dist(p, (clat, clong)), positions)
    thresholds = map(lambda d: threshold(d, rad, cat), distances)
    return thresholds

if __name__ == "__main__":
    clat = float(sys.argv[1])
    clong = float(sys.argv[2])
    rad = float(sys.argv[3])
    cat = int(sys.argv[4])

    thresholds = compute_thresholds(clat, clong, rad, cat)
    s = utils.to_matlab(thresholds, '')
    s = s.replace('\n', '')
    s = s[:-1]
    print s