예제 #1
0
def local_k(network, events, refs, scale_set, cache=None):
    """
    Computes local K function

    network: an undirected network data to which reference points are injected
    refs: a set of reference points on the given network
          points unprojected into the network
    events: a set of event points on the given network
            points projected into the network
    scale_set: a tuple defining spatial scales to be examined
               (min, max, interval)
    """

    node2localK = {}
    net_distances = {}
    if cache: net_distances = cache
    for node in refs:
        node = node[1][0]
        a_dest = network[node].keys()[0]
        node_proj = (node, a_dest, 0, network[node][a_dest])
        if node not in net_distances:
            net_distances[node] = pynet.dijkstras(network, node, scale_set[1])
        if a_dest not in net_distances:
            net_distances[a_dest] = pynet.dijkstras(network, node,
                                                    scale_set[1])
        distances = pynet.proj_distances_undirected(
            network, node_proj, events, scale_set[1],
            cache=net_distances).values()
        node2localK[node] = pykfuncs.kt_values(scale_set, distances, 1)
    return node2localK, net_distances
예제 #2
0
파일: klincs.py 프로젝트: CartoDB/pysal
def local_k(network, events, refs, scale_set, cache=None):
    """
    Computes local K function

    network: an undirected network data to which reference points are injected
    refs: a set of reference points on the given network
          points unprojected into the network
    events: a set of event points on the given network
            points projected into the network
    scale_set: a tuple defining spatial scales to be examined
               (min, max, interval)
    """

    node2localK = {}
    net_distances = {}
    if cache: net_distances = cache
    for node in refs:
        node = node[1][0]
        a_dest = network[node].keys()[0]
        node_proj = (node, a_dest, 0, network[node][a_dest])
        if node not in net_distances:
            net_distances[node] = pynet.dijkstras(network, node, scale_set[1])
        if a_dest not in net_distances:
            net_distances[a_dest] = pynet.dijkstras(network, node, scale_set[1])
        distances = pynet.proj_distances_undirected(network, node_proj, events, scale_set[1], cache=net_distances).values()
        node2localK[node] = pykfuncs.kt_values(scale_set, distances, 1)
    return node2localK, net_distances
예제 #3
0
def simulate_local_k_02(args):
    sims = args[0]
    n = args[1]
    refs = args[2]
    scale_set = args[3]
    cache = args[4]

    #print 'simulated_local_k_02'
    sims_outcomes = []
    sampler = RandomSampleGenerator(refs, n).next
    for sim in xrange(sims):
        sim_events = sampler()
        sim_localk = {}
        for node in refs:
            all_distances = cache[node[1][0]]
            distances = []
            for event in sim_events:
                event = event[1][0]
                if event in all_distances:
                    distances.append(all_distances[event])
            sim_localk[node[1][0]] = pykfuncs.kt_values(
                scale_set, distances, 1)
        sims_outcomes.append(sim_localk)

    return sims_outcomes
예제 #4
0
파일: klincs.py 프로젝트: CartoDB/pysal
def simulate_local_k_02(args):
    sims = args[0]
    n = args[1]
    refs = args[2]
    scale_set = args[3]
    cache = args[4]

    #print 'simulated_local_k_02'
    sims_outcomes = []
    sampler = RandomSampleGenerator(refs, n).next
    for sim in xrange(sims):
        sim_events = sampler()
        sim_localk = {}
        for node in refs:
            all_distances = cache[node[1][0]]
            distances = []
            for event in sim_events:
                event = event[1][0]
                if event in all_distances:
                    distances.append(all_distances[event]) 
            sim_localk[node[1][0]] = pykfuncs.kt_values(scale_set, distances, 1)
        sims_outcomes.append(sim_localk)
    
    return sims_outcomes