def __init__(self,data,bandwidth=None,fixed=True,k=2, p=2, function='triangular',eps=1.0000001,ids=None): # handle point_array if type(data).__name__=='ndarray': self.data=data elif type(data).__name__=='list': self.data=data else: raise Exception, 'Unsupported type' self.k=k+1 self.function=function.lower() self.fixed=fixed self.eps=eps self.kdt=KDTree(self.data) self.dmat,self.neigh=self.kdt.query(data,k=k+1,p=p) if bandwidth: try: bandwidth=np.array(bandwidth) bandwidth.shape=(len(bandwidth),1) except: bandwidth=np.ones((len(data),1),'float')*bandwidth self.bandwidth=bandwidth else: self._set_bw() self._eval_kernel() neighbors, weights = self._k_to_W(ids) W.__init__(self,neighbors,weights,ids)
def __init__(self, data, bandwidth=None, fixed=True, k=2, function='triangular', eps=1.0000001, ids=None, diagonal=False): if issubclass(type(data), scipy.spatial.KDTree): self.kdt = data self.data = self.kdt.data data = self.data else: self.data = data self.kdt = KDTree(self.data) self.k = k + 1 self.function = function.lower() self.fixed = fixed self.eps = eps if bandwidth: try: bandwidth = np.array(bandwidth) bandwidth.shape = (len(bandwidth), 1) except: bandwidth = np.ones((len(data), 1), 'float') * bandwidth self.bandwidth = bandwidth else: self._set_bw() self._eval_kernel() neighbors, weights = self._k_to_W(ids) if diagonal: for i in neighbors: nis = neighbors[i] weights[i][neighbors[i].index(i)] = 1.0 W.__init__(self, neighbors, weights, ids)
def __init__(self, data, threshold, p=2, alpha=-1.0, binary=True, ids=None, build_sp=True, silent=False): """Casting to floats is a work around for a bug in scipy.spatial. See detail in pysal issue #126. """ self.p = p self.threshold = threshold self.binary = binary self.alpha = alpha self.build_sp = build_sp self.silent = silent if isKDTree(data): self.kd = data self.data = self.kd.data else: if self.build_sp: try: data = np.asarray(data) if data.dtype.kind != 'f': data = data.astype(float) self.data = data self.kd = KDTree(self.data) except: raise ValueError("Could not make array from data") else: self.data = data self.kd = None self._band() neighbors, weights = self._distance_to_W(ids) W.__init__(self, neighbors, weights, ids, silent_island_warning=self.silent)
def __init__(self, data, threshold, p=2, alpha=-1.0, binary=True, ids=None): """Casting to floats is a work around for a bug in scipy.spatial. See detail in pysal issue #126. """ if isKDTree(data): self.kd = data self.data = self.kd.data else: try: data = np.asarray(data) if data.dtype.kind != 'f': data = data.astype(float) self.data = data self.kd = KDTree(self.data) except: raise ValueError("Could not make array from data") self.p = p self.threshold = threshold self.binary = binary self.alpha = alpha self._band() neighbors, weights = self._distance_to_W(ids) W.__init__(self, neighbors, weights, ids)
def __init__(self, data, k=2, p=2, ids=None, radius=None, distance_metric='euclidean'): if isKDTree(data): self.kdtree = data self.data = data.data else: self.data = data self.kdtree = KDTree(data, radius=radius, distance_metric=distance_metric) self.k = k self.p = p this_nnq = self.kdtree.query(self.data, k=k + 1, p=p) to_weight = this_nnq[1] if ids is None: ids = list(range(to_weight.shape[0])) neighbors = {} for i, row in enumerate(to_weight): row = row.tolist() row.remove(i) row = [ids[j] for j in row] focal = ids[i] neighbors[focal] = row W.__init__(self, neighbors, id_order=ids)
def __init__(self, data, threshold, p=2, alpha=-1.0, binary=True, ids=None): """Casting to floats is a work around for a bug in scipy.spatial. See detail in pysal issue #126. """ if issubclass(type(data), scipy.spatial.KDTree): self.kd = data self.data = self.kd.data else: try: data = np.asarray(data) if data.dtype.kind != 'f': data = data.astype(float) self.data = data self.kd = KDTree(self.data) except: raise ValueError("Could not make array from data") self.p = p self.threshold = threshold self.binary = binary self.alpha = alpha self._band() neighbors, weights = self._distance_to_W(ids) W.__init__(self, neighbors, weights, ids)
def __init__(self, data, bandwidth=None, fixed=True, k=2, function='triangular', eps=1.0000001, ids=None, diagonal=False): if issubclass(type(data), scipy.spatial.KDTree): self.kdt = data self.data = self.kdt.data data = self.data else: self.data = data self.kdt = KDTree(self.data) self.k = k + 1 self.function = function.lower() self.fixed = fixed self.eps = eps if bandwidth: try: bandwidth = np.array(bandwidth) bandwidth.shape = (len(bandwidth), 1) except: bandwidth = np.ones((len(data), 1), 'float') * bandwidth self.bandwidth = bandwidth else: self._set_bw() self._eval_kernel() neighbors, weights = self._k_to_W(ids) if diagonal: for i in neighbors: weights[i][neighbors[i].index(i)] = 1.0 W.__init__(self, neighbors, weights, ids)
def __init__(self, data, k=2, p=2, ids=None, radius=None, distance_metric='euclidean'): if isKDTree(data): self.kdtree = data self.data = data.data else: self.data = data self.kdtree = KDTree(data, radius=radius, distance_metric=distance_metric) self.k = k self.p = p this_nnq = self.kdtree.query(self.data, k=k+1, p=p) to_weight = this_nnq[1] if ids is None: ids = list(range(to_weight.shape[0])) neighbors = {} for i,row in enumerate(to_weight): row = row.tolist() row.remove(i) row = [ids[j] for j in row] focal = ids[i] neighbors[focal] = row W.__init__(self, neighbors, id_order=ids)
def __init__(self, data, bandwidth=None, fixed=True, k=2, p=2, function='triangular', eps=1.0000001, ids=None): # handle point_array if type(data).__name__ == 'ndarray': self.data = data elif type(data).__name__ == 'list': self.data = data else: raise Exception, 'Unsupported type' self.k = k + 1 self.function = function.lower() self.fixed = fixed self.eps = eps self.kdt = KDTree(self.data) self.dmat, self.neigh = self.kdt.query(data, k=k + 1, p=p) if bandwidth: try: bandwidth = np.array(bandwidth) bandwidth.shape = (len(bandwidth), 1) except: bandwidth = np.ones((len(data), 1), 'float') * bandwidth self.bandwidth = bandwidth else: self._set_bw() self._eval_kernel() neighbors, weights = self._k_to_W(ids) W.__init__(self, neighbors, weights, ids)