• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pysal.lat2W函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pysal.lat2W函数的典型用法代码示例。如果您正苦于以下问题:Python lat2W函数的具体用法?Python lat2W怎么用?Python lat2W使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了lat2W函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: setUp

 def setUp(self):
     db=pysal.open(pysal.examples.get_path("columbus.dbf"),"r")
     y = np.array(db.by_col("CRIME"))
     self.y = np.reshape(y, (49,1))
     X = []
     X.append(db.by_col("HOVAL"))
     X.append(db.by_col("INC"))
     self.X = np.array(X).T
     X2 = []
     X2.append(db.by_col("INC"))
     self.X2 = np.array(X2).T
     yd = []
     yd.append(db.by_col("HOVAL"))
     self.yd = np.array(yd).T
     q = []
     q.append(db.by_col("DISCBD"))
     self.q = np.array(q).T
     self.w = pysal.queen_from_shapefile(pysal.examples.get_path("columbus.shp"))
     self.w.transform = 'r'
     self.r_var = 'NSA'
     self.regimes = db.by_col(self.r_var)
     #Artficial:
     n = 256
     self.n2 = n/2
     self.x_a1 = np.random.uniform(-10,10,(n,1))
     self.x_a2 = np.random.uniform(1,5,(n,1))
     self.q_a = self.x_a2 + np.random.normal(0,1,(n,1))
     self.x_a = np.hstack((self.x_a1,self.x_a2))
     self.y_a = np.dot(np.hstack((np.ones((n,1)),self.x_a)),np.array([[1],[0.5],[2]])) + np.random.normal(0,1,(n,1))
     latt = int(np.sqrt(n))
     self.w_a = pysal.lat2W(latt,latt)
     self.w_a.transform='r'
     self.regi_a = [0]*(n/2) + [1]*(n/2)
     self.w_a1 = pysal.lat2W(latt/2,latt)
     self.w_a1.transform='r'
开发者ID:PepSalehi,项目名称:pysal,代码行数:35,代码来源:test_error_sp_hom_regimes.py


示例2: setUp

 def setUp(self):
     db =  pysal.open(pysal.examples.get_path("baltim.dbf"),'r')
     self.ds_name = "baltim.dbf"
     self.y_name = "PRICE"
     self.y = np.array(db.by_col(self.y_name)).T
     self.y.shape = (len(self.y),1)
     self.x_names = ["NROOM","AGE","SQFT"]
     self.x = np.array([db.by_col(var) for var in self.x_names]).T
     ww = pysal.open(pysal.examples.get_path("baltim_q.gal"))
     self.w = ww.read()
     ww.close()
     self.w_name = "baltim_q.gal"
     self.w.transform = 'r'
     self.regimes = db.by_col("CITCOU")
     #Artficial:
     n = 256
     self.n2 = n/2
     self.x_a1 = np.random.uniform(-10,10,(n,1))
     self.x_a2 = np.random.uniform(1,5,(n,1))
     self.q_a = self.x_a2 + np.random.normal(0,1,(n,1))
     self.x_a = np.hstack((self.x_a1,self.x_a2))
     self.y_a = np.dot(np.hstack((np.ones((n,1)),self.x_a)),np.array([[1],[0.5],[2]])) + np.random.normal(0,1,(n,1))
     latt = int(np.sqrt(n))
     self.w_a = pysal.lat2W(latt,latt)
     self.w_a.transform='r'
     self.regi_a = [0]*(n/2) + [1]*(n/2)
     self.w_a1 = pysal.lat2W(latt/2,latt)
     self.w_a1.transform='r'
开发者ID:nathania,项目名称:pysal,代码行数:28,代码来源:test_ml_error_regimes.py


示例3: test_w_union

 def test_w_union(self):
     """Unit test"""
     w1 = pysal.lat2W(4, 4)
     w2 = pysal.lat2W(6, 4)
     w3 = pysal.weights.Wsets.w_union(w1, w2)
     self.assertEqual(w1[0], w3[0])
     self.assertEqual(set(w1.neighbors[15]), set([11, 14]))
     self.assertEqual(set(w2.neighbors[15]), set([11, 14, 19]))
     self.assertEqual(set(w3.neighbors[15]), set([19, 11, 14]))
开发者ID:CartoDB,项目名称:pysal,代码行数:9,代码来源:test_Wsets.py


示例4: test_w_difference

 def test_w_difference(self):
     """Unit test"""
     w1 = pysal.lat2W(4, 4, rook=False)
     w2 = pysal.lat2W(4, 4, rook=True)
     w3 = pysal.weights.Wsets.w_difference(w1, w2, constrained=False)
     self.assertNotEqual(w1[0], w3[0])
     self.assertEqual(set(w1.neighbors[15]), set([10, 11, 14]))
     self.assertEqual(set(w2.neighbors[15]), set([11, 14]))
     self.assertEqual(set(w3.neighbors[15]), set([10]))
开发者ID:CartoDB,项目名称:pysal,代码行数:9,代码来源:test_Wsets.py


示例5: test_higher_order

 def test_higher_order(self):
     w10 = pysal.lat2W(10, 10)
     w10_2 = pysal.higher_order(w10, 2)
     w10_20 = {2: 1.0, 11: 1.0, 20: 1.0}
     self.assertEquals(w10_20, w10_2[0])
     w5 = pysal.lat2W()
     w50 = {1: 1.0, 5: 1.0}
     self.assertEquals(w50, w5[0])
     w51 = {0: 1.0, 2: 1.0, 6: 1.0}
     self.assertEquals(w51, w5[1])
     w5_2 = pysal.higher_order(w5, 2)
     w5_20 = {2: 1.0, 10: 1.0, 6: 1.0}
     self.assertEquals(w5_20, w5_2[0])
开发者ID:DrizzleRisk,项目名称:Security-Project,代码行数:13,代码来源:test_util.py


示例6: test_shimbel

 def test_shimbel(self):
     w5 = pysal.lat2W()
     w5_shimbel = pysal.shimbel(w5)
     w5_shimbel024 = 8
     self.assertEquals(w5_shimbel024, w5_shimbel[0][24])
     w5_shimbel004 = [-1, 1, 2, 3]
     self.assertEquals(w5_shimbel004, w5_shimbel[0][0:4])
开发者ID:DrizzleRisk,项目名称:Security-Project,代码行数:7,代码来源:test_util.py


示例7: test___iter__

 def test___iter__(self):
     w = pysal.lat2W(3, 3)
     res = {}
     for i, wi in enumerate(w):
         res[i] = wi
     self.assertEqual(res[0], {1: 1.0, 3: 1.0})
     self.assertEqual(res[8], {5: 1.0, 7: 1.0})
开发者ID:cheneason,项目名称:pysal,代码行数:7,代码来源:test_weights.py


示例8: test_Maxp_LISA

 def test_Maxp_LISA(self):
     w = pysal.lat2W(10, 10)
     z = np.random.random_sample((w.n, 2))
     p = np.ones(w.n)
     mpl = pysal.region.Maxp_LISA(w, z, p, floor=3, floor_variable=p)
     self.assertEquals(mpl.p, 31)
     self.assertEquals(mpl.regions[0], [99, 89, 98, 97])
开发者ID:Alwnikrotikz,项目名称:pysal,代码行数:7,代码来源:test_maxp.py


示例9: __init__

    def __init__( self, x, w=None ):
        """
        x : numpy array, either rectangular spatial array that will be
        raveled for pysal, or array that is already 1D. If x is 1D,
        then we must have that len(x)=k**2 in order to create the
        square weight matrix.

        w : if x is 1D, must provide w, a weights matrix indicating
        the spatial correlation between neighboring data points. Eg.,
        w_ij = 1 if grid element i is a neighbor of j, 0 otherwise.
        """
        
        if x.ndim > 1:
            # for ricker computations assume x is square
            n = x.shape[0]
            self.x = x.ravel()
               
            # create contiguous weight matrix ('rook' format, eg. NWSE
            # neighbors)
            self.w = pysal.lat2W( n, n )

        elif x.ndim == 1 and w is None:
            print "Must provide wieghts 'w'."
            return
        else:
            self.x = x
            n = int( np.sqrt( len( x ) ) )
            self.w = w

        # create the Moran object
        self.moran = pysal.Moran( self.x, self.w )
开发者ID:caja-matematica,项目名称:pyTopTools,代码行数:31,代码来源:spatial.py


示例10: test_w_subset

 def test_w_subset(self):
     """Unit test"""
     w1 = pysal.lat2W(6, 4)
     ids = range(16)
     w2 = pysal.weights.Wsets.w_subset(w1, ids)
     self.assertEqual(w1[0], w2[0])
     self.assertEqual(set(w1.neighbors[15]), set([11, 14, 19]))
     self.assertEqual(set(w2.neighbors[15]), set([11, 14]))
开发者ID:CartoDB,项目名称:pysal,代码行数:8,代码来源:test_Wsets.py


示例11: get_weight_matrix

    def get_weight_matrix(self, array, rook=False, shpfile=None):
        """Return the spatial weight matrix based on pysal functionalities

        Keyword arguments:
            array    Numpy array with inventory values.
            rook    Boolean to select spatial weights matrix as rook or
                    queen case.
            shpfile    Name of file used to setup weight matrix.
        """
        # Get case name.
        if rook:
            case = 'rook'
        else:
            case = 'queen'
        # Get grid dimension.
        dim = array.shape
        if self.sptype == 'vector':
            try:
                # Create weights based on shapefile topology using defined key.
                if shpfile is None:
                    shpfile = self.invfile
                # Differentiat between rook and queen's case.
                if rook:
                    w = pysal.rook_from_shapefile(shpfile, self.invcol)
                else:
                    w = pysal.queen_from_shapefile(shpfile, self.invcol)
            except:
                msg = "Couldn't build spatial weight matrix for vector "
                "inventory <%s>" % (self.name)
                raise RuntimeError(msg)

            # Match weight index to inventory array index.
            w.id_order = list(self.inv_index)

            logger.info("Weight matrix in %s's case successfully calculated "
                        "for vector dataset" % case)
        elif self.sptype == 'raster':
            try:
                # Construct weight matrix in input grid size.
                w = pysal.lat2W(*dim, rook=rook)
            except:
                msg = "Couldn't build spatial weight matrix for raster "
                "inventory <%s>" % (self.name)
                raise RuntimeError(msg)

            logger.info("Weight matrix in %s's case successfully calculated "
                        "for raster dataset" % case)

        # Print imported raster summary.
        print("[ WEIGHT NUMBER ] = ", w.n)
        print("[ MIN NEIGHBOR ] = ", w.min_neighbors)
        print("[ MAX NEIGHBOR ] = ", w.max_neighbors)
        print("[ ISLANDS ] = ", *w.islands)
        print("[ HISTOGRAM ] = ", *w.histogram)

        self._Inventory__modmtime()

        return(w)
开发者ID:m4sth0,项目名称:sauventory,代码行数:58,代码来源:spatialinventory.py


示例12: test_asymmetries

 def test_asymmetries(self):
     w = pysal.lat2W(3, 3)
     w.transform = 'r'
     result = w.asymmetry()
     self.assertEqual(result, [(0, 1), (0, 3), (1, 0), (1, 2), (1, 4),
                               (2, 1), (2, 5), (3, 0), (3, 4), (3, 6),
                               (4, 1), (4, 3), (4, 5), (4, 7), (5, 2),
                               (5, 4), (5, 8), (6, 3), (6, 7), (7, 4),
                               (7, 6), (7, 8), (8, 5), (8, 7)])
开发者ID:lanselin,项目名称:pysal,代码行数:9,代码来源:test_weights.py


示例13: test_Maxp

 def test_Maxp(self):
     w = pysal.lat2W(10, 10)
     z = np.random.random_sample((w.n, 2))
     p = np.ones((w.n, 1), float)
     floor = 3
     solution = pysal.region.Maxp(
         w, z, floor, floor_variable=p, initial=100)
     self.assertEquals(solution.p, 29)
     self.assertEquals(solution.regions[0], [4, 14, 5, 24, 3, 25, 15, 23])
开发者ID:Alwnikrotikz,项目名称:pysal,代码行数:9,代码来源:test_maxp.py


示例14: convert_to_pysal

def convert_to_pysal(data):
    """
    Pysal expects a distance matrix, and data formatted in a numpy array.
    This functions takes a data grid and returns those things.
    """
    w = pysal.lat2W(len(data[0]), len(data))
    data = np.array(data)
    data = np.reshape(data, (len(data)*len(data[0]), 1))
    return w, data
开发者ID:emilydolson,项目名称:avida-spatial-tools,代码行数:9,代码来源:utils.py


示例15: test_Maxp

 def test_Maxp(self):
     w = pysal.lat2W(10, 10)
     z = np.random.random_sample((w.n, 2))
     p = np.ones((w.n, 1), float)
     floor = 3
     np.random.seed(111)
     solution = pysal.region.Maxp(
         w, z, floor, floor_variable=p, initial=100)
     self.assertEquals(solution.p, 28)
     self.assertEquals(solution.regions[0], [51, 61, 71])
开发者ID:CartoDB,项目名称:pysal,代码行数:10,代码来源:test_maxp.py


示例16: setUp

    def setUp(self):
        from pysal import rook_from_shapefile
        self.w = rook_from_shapefile(pysal.examples.get_path('10740.shp'))

        self.neighbors = {0: [3, 1], 1: [0, 4, 2], 2: [1, 5], 3: [0, 6, 4], 4: [1, 3,
                                                                                7, 5], 5: [2, 4, 8], 6: [3, 7], 7: [4, 6, 8], 8: [5, 7]}
        self.weights = {0: [1, 1], 1: [1, 1, 1], 2: [1, 1], 3: [1, 1, 1], 4: [1, 1,
                                                                              1, 1], 5: [1, 1, 1], 6: [1, 1], 7: [1, 1, 1], 8: [1, 1]}

        self.w3x3 = pysal.lat2W(3, 3)
开发者ID:cheneason,项目名称:pysal,代码行数:10,代码来源:test_weights.py


示例17: setUp

 def setUp(self):
     self.neighbors = {'c': ['b'], 'b': ['c', 'a'], 'a': ['b']}
     self.weights = {'c': [1.0], 'b': [1.0, 1.0], 'a': [1.0]}
     self.id_order = ['a', 'b', 'c']
     self.weights = {'c': [1.0], 'b': [1.0, 1.0], 'a': [1.0]}
     self.w = pysal.W(self.neighbors, self.weights, self.id_order)
     self.y = np.array([0, 1, 2])
     self.wlat = pysal.lat2W(3, 3)
     self.ycat = ['a','b','a','b','c','b','c','b','c']
     self.ycat2 = ['a', 'c', 'c', 'd', 'b', 'a', 'd', 'd', 'c']
     self.ym = np.vstack((self.ycat,self.ycat2)).T
     self.random_seed = 503
开发者ID:ljwolf,项目名称:pysal,代码行数:12,代码来源:test_spatial_lag.py


示例18: test_order

 def test_order(self):
     w = pysal.lat2W(3, 3)
     o = {0: [-1, 1, 2, 1, 2, 3, 2, 3, 0],
          1: [1, -1, 1, 2, 1, 2, 3, 2, 3],
          2: [2, 1, -1, 3, 2, 1, 0, 3, 2],
          3: [1, 2, 3, -1, 1, 2, 1, 2, 3],
          4: [2, 1, 2, 1, -1, 1, 2, 1, 2],
          5: [3, 2, 1, 2, 1, -1, 3, 2, 1],
          6: [2, 3, 0, 1, 2, 3, -1, 1, 2],
          7: [3, 2, 3, 2, 1, 2, 1, -1, 1],
          8: [0, 3, 2, 3, 2, 1, 2, 1, -1]}
     self.assertEquals(pysal.order(w), o)
开发者ID:cheneason,项目名称:pysal,代码行数:12,代码来源:test_weights.py


示例19: test_remap_ids

 def test_remap_ids(self):
     w = pysal.lat2W(3, 2)
     wid_order = [0, 1, 2, 3, 4, 5]
     self.assertEquals(wid_order, w.id_order)
     wneighbors0 = [2, 1]
     self.assertEquals(wneighbors0, w.neighbors[0])
     old_to_new = {0: 'a', 1: 'b', 2: 'c', 3: 'd', 4: 'e', 5: 'f'}
     w_new = pysal.remap_ids(w, old_to_new)
     w_newid_order = ['a', 'b', 'c', 'd', 'e', 'f']
     self.assertEquals(w_newid_order, w_new.id_order)
     w_newdneighborsa = ['c', 'b']
     self.assertEquals(w_newdneighborsa, w_new.neighbors['a'])
开发者ID:DrizzleRisk,项目名称:Security-Project,代码行数:12,代码来源:test_util.py


示例20: setUp

    def setUp(self):
        from pysal import rook_from_shapefile
        self.w = rook_from_shapefile(pysal.examples.get_path('10740.shp'))
        wsp = self.w.to_WSP()
        self.w = wsp.to_W()

        self.neighbors = {0: [3, 1], 1: [0, 4, 2], 2: [1, 5], 3: [0, 6, 4],
                          4: [1, 3, 7, 5], 5: [2, 4, 8], 6: [3, 7],
                          7: [4, 6, 8], 8: [5, 7]}
        self.weights = {0: [1, 1], 1: [1, 1, 1], 2: [1, 1], 3: [1, 1, 1],
                        4: [1, 1, 1, 1], 5: [1, 1, 1], 6: [1, 1], 7: [1, 1, 1],
                        8: [1, 1]}

        self.w3x3 = pysal.lat2W(3, 3)
        w3x3 = pysal.weights.WSP(self.w3x3.sparse, self.w3x3.id_order)
        self.w3x3 = pysal.weights.WSP2W(w3x3)
开发者ID:lanselin,项目名称:pysal,代码行数:16,代码来源:test_weights.py



注:本文中的pysal.lat2W函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pysal.open函数代码示例发布时间:2022-05-27
下一篇:
Python pysal.lag_spatial函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap