From 3294eb35abb7e8166c4b672c56510b0a220a90d1 Mon Sep 17 00:00:00 2001 From: Andy Eschbacher Date: Fri, 1 Apr 2016 08:22:27 -0400 Subject: [PATCH] remove if conditions and relying on pysal.W to build weights norms --- .../crankshaft/pysal_utils/pysal_utils.py | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/py/crankshaft/crankshaft/pysal_utils/pysal_utils.py b/src/py/crankshaft/crankshaft/pysal_utils/pysal_utils.py index f4def85..9d09642 100644 --- a/src/py/crankshaft/crankshaft/pysal_utils/pysal_utils.py +++ b/src/py/crankshaft/crankshaft/pysal_utils/pysal_utils.py @@ -20,19 +20,23 @@ def construct_neighbor_query(w_type, query_vals): def get_weight(query_res, w_type='knn', num_ngbrs=5): """ Construct PySAL weight from return value of query - @param query_res: query results with attributes and neighbors + @param query_res dict-like: query results with attributes and neighbors """ - if w_type == 'knn': - row_normed_weights = [1.0 / float(num_ngbrs)] * num_ngbrs - weights = {x['id']: row_normed_weights for x in query_res} - else: - weights = {x['id']: [1.0 / len(x['neighbors'])] * len(x['neighbors']) - if len(x['neighbors']) > 0 - else [] for x in query_res} + # if w_type == 'knn': + # row_normed_weights = [1.0 / float(num_ngbrs)] * num_ngbrs + # weights = {x['id']: row_normed_weights for x in query_res} + # else: + # weights = {x['id']: [1.0 / len(x['neighbors'])] * len(x['neighbors']) + # if len(x['neighbors']) > 0 + # else [] for x in query_res} neighbors = {x['id']: x['neighbors'] for x in query_res} + print 'len of neighbors: %d' % len(neighbors) - return ps.W(neighbors, weights) + built_weight = ps.W(neighbors) + built_weight.transform = 'r' + + return built_weight def query_attr_select(params): """