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

Python pysal.kernelW_from_shapefile函数代码示例

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

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



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

示例1: test_names

 def test_names(self):
     w = pysal.queen_from_shapefile(pysal.examples.get_path('columbus.shp'))
     gwk = pysal.kernelW_from_shapefile(pysal.examples.get_path('columbus.shp'),k=5,function='triangular', fixed=False)
     name_x = ['inc']
     name_y = 'crime'
     name_yend = ['hoval']
     name_q = ['discbd']
     name_w = 'queen'
     name_gwk = 'k=5'
     name_ds = 'columbus'
     reg = TSLS(self.y, self.X, self.yd, self.q,
             spat_diag=True, w=w, robust='hac', gwk=gwk,
             name_x=name_x, name_y=name_y, name_q=name_q, name_w=name_w,
             name_yend=name_yend, name_gwk=name_gwk, name_ds=name_ds)
     betas = np.array([[ 88.46579584], [  0.5200379 ], [ -1.58216593]])
     np.testing.assert_array_almost_equal(reg.betas, betas, 7)
     vm = np.array([[ 225.0795089 ,   17.11660041,  -12.22448566],
                    [  17.67097154,    2.47483461,   -1.4183641 ],
                    [ -12.45093722,   -1.40495464,    0.8700441 ]])
     np.testing.assert_array_almost_equal(reg.vm, vm, 7)
     self.assertListEqual(reg.name_x, ['CONSTANT']+name_x)
     self.assertListEqual(reg.name_yend, name_yend)
     self.assertListEqual(reg.name_q, name_q)
     self.assertEqual(reg.name_y, name_y)
     self.assertEqual(reg.name_w, name_w)
     self.assertEqual(reg.name_gwk, name_gwk)
     self.assertEqual(reg.name_ds, name_ds)
开发者ID:CartoDB,项目名称:pysal,代码行数:27,代码来源:test_twosls.py


示例2: test_hac

 def test_hac(self):
     gwk = pysal.kernelW_from_shapefile(pysal.examples.get_path('columbus.shp'),k=15,function='triangular', fixed=False)
     reg = BaseTSLS(self.y, self.X, self.yd, self.q, robust='hac', gwk=gwk)
     betas = np.array([[ 88.46579584], [  0.5200379 ], [ -1.58216593]])
     np.testing.assert_array_almost_equal(reg.betas, betas, 7)
     vm = np.array([[ 231.07254978,   15.42050291,  -11.3941033 ],
                    [  15.01376346,    1.92422887,   -1.11865505],
                    [ -11.34381641,   -1.1279227 ,    0.72053806]]) 
     np.testing.assert_array_almost_equal(reg.vm, vm, 7)
开发者ID:CartoDB,项目名称:pysal,代码行数:9,代码来源:test_twosls.py


示例3: test_kernelW_from_shapefile

 def test_kernelW_from_shapefile(self):
     kw = pysal.kernelW_from_shapefile(pysal.examples.get_path(
         'columbus.shp'), idVariable='POLYID')
     self.assertEquals(kw.weights[1], [0.2052478782400463,
                                       0.0070787731484506233, 1.0,
                                       0.23051223027663237])
     np.testing.assert_array_almost_equal(
         kw.bandwidth[:3], np.array([[0.75333961], [0.75333961],
                                     [0.75333961]]))
开发者ID:ShuyaoHong,项目名称:pysal,代码行数:9,代码来源:test_user.py


示例4: test_names

 def test_names(self):
     X = np.array(self.db.by_col("INC"))
     X = np.reshape(X, (49, 1))
     X = SP.csr_matrix(X)
     yd = np.array(self.db.by_col("CRIME"))
     yd = np.reshape(yd, (49, 1))
     q = np.array(self.db.by_col("DISCBD"))
     q = np.reshape(q, (49, 1))
     w = pysal.queen_from_shapefile(pysal.examples.get_path("columbus.shp"))
     gwk = pysal.kernelW_from_shapefile(
         pysal.examples.get_path("columbus.shp"), k=5, function="triangular", fixed=False
     )
     name_x = ["inc"]
     name_y = "crime"
     name_yend = ["crime"]
     name_q = ["discbd"]
     name_w = "queen"
     name_gwk = "k=5"
     name_ds = "columbus"
     reg = GM_Lag(
         self.y,
         X,
         yd,
         q,
         spat_diag=True,
         w=w,
         robust="hac",
         gwk=gwk,
         name_x=name_x,
         name_y=name_y,
         name_q=name_q,
         name_w=name_w,
         name_yend=name_yend,
         name_gwk=name_gwk,
         name_ds=name_ds,
     )
     betas = np.array([[5.46344924e01], [4.13301682e-01], [-5.92637442e-01], [-7.40490883e-03]])
     np.testing.assert_array_almost_equal(reg.betas, betas, 7)
     vm = np.array(
         [
             [5.70817052e02, -1.83655385e01, -8.36602575e00, 2.37538877e-02],
             [-1.85224661e01, 6.53311383e-01, 2.84209566e-01, -6.47694160e-03],
             [-8.31105622e00, 2.78772694e-01, 1.38144928e-01, -3.98175246e-03],
             [2.66662466e-02, -6.23783104e-03, -4.11092891e-03, 1.10936528e-03],
         ]
     )
     np.testing.assert_array_almost_equal(reg.vm, vm, 6)
     self.assertListEqual(reg.name_x, ["CONSTANT"] + name_x)
     name_yend.append("W_crime")
     self.assertListEqual(reg.name_yend, name_yend)
     name_q.extend(["W_inc", "W_discbd"])
     self.assertListEqual(reg.name_q, name_q)
     self.assertEqual(reg.name_y, name_y)
     self.assertEqual(reg.name_w, name_w)
     self.assertEqual(reg.name_gwk, name_gwk)
     self.assertEqual(reg.name_ds, name_ds)
开发者ID:JoshuaSteele,项目名称:pysal,代码行数:56,代码来源:test_twosls_sp_sparse.py


示例5: _kernel

def _kernel(arg_dict):
    """
    General handler for building kernel based weights from shapefiles

    Examples
    --------

    >>> w = wmd_reader('kernel.wmd')
    >>> w.n
    49
    >>> w.meta_data
    {'root': {u'input1': {u'data1': {u'type': u'shp',
                                     u'uri': u'../examples/columbus.shp'}},
              u'weight_type': u'kernel', u'transform': u'O',
              u'parameters': {u'function': u'triangular',
              u'bandwidths': None, u'k': 2}}}



    """
    input1 = arg_dict['input1']['data1']
    uri = input1['uri']
    weight_type = arg_dict['weight_type']
    weight_type = weight_type.lower()
    k = 2
    bandwidths = None
    function = 'triangular'
    if 'parameters' in arg_dict:
        k = arg_dict['parameters'].get('k', k)  # set default to 2
        bandwidths = arg_dict['parameters'].get('bandwidths', bandwidths)
        function = arg_dict['parameters'].get('function', function)
    else:
        parameters = {}
        parameters['k'] = k
        parameters['bandwidths'] = bandwidths
        parameters['function'] = function
        arg_dict['parameters'] = parameters


    if weight_type == 'akernel':
        # adaptive kernel
        w = ps.adaptive_kernelW_from_shapefile(uri, bandwidths = bandwidths,
                k=k, function = function)
    elif weight_type == 'kernel':
        w = ps.kernelW_from_shapefile(uri, k=k, function = function)
    else:
        print "Unsupported kernel: ",weight_type
        return None
    w = WMD(w.neighbors, w.weights)
    w.meta_data = {}
    w.meta_data["input1"] = {"type": 'shp', 'uri':uri}
    w.meta_data["transform"] = w.transform
    w.meta_data["weight_type"] =  weight_type
    w.meta_data['parameters'] = arg_dict['parameters']
    return w
开发者ID:CartoDB,项目名称:pysal,代码行数:55,代码来源:wmd.py


示例6: test_init_hac_

 def test_init_hac_(self):
     X = []
     X.append(self.db.by_col("INC"))
     X.append(self.db.by_col("CRIME"))
     self.X = np.array(X).T
     gwk = pysal.kernelW_from_shapefile(pysal.examples.get_path('columbus.shp'),k=15,function='triangular', fixed=False)        
     base_gm_lag = GM_Lag(self.y, self.X, w=self.w, w_lags=2, robust='hac', gwk=gwk)
     tbetas = np.array([[  4.53017056e+01], [  6.20888617e-01], [ -4.80723451e-01], [  2.83622122e-02]])
     np.testing.assert_array_almost_equal(base_gm_lag.betas, tbetas) 
     dbetas = D.se_betas(base_gm_lag)
     se_betas = np.array([ 19.08513569,   0.51769543,   0.18244862,   0.35460553])
     np.testing.assert_array_almost_equal(dbetas, se_betas)
开发者ID:denadai2,项目名称:pysal,代码行数:12,代码来源:test_twosls_sp.py


示例7: test_init_hac_

 def test_init_hac_(self):
     w_lags = 2
     X = []
     X.append(self.db.by_col("INC"))
     X.append(self.db.by_col("CRIME"))
     self.X = np.array(X).T
     yd2, q2 = pysal.spreg.utils.set_endog(self.y, self.X, self.w, None, None, w_lags, True)
     self.X = np.hstack((np.ones(self.y.shape),self.X))
     gwk = pysal.kernelW_from_shapefile(pysal.examples.get_path('columbus.shp'),k=15,function='triangular', fixed=False)        
     base_gm_lag = BaseGM_Lag(self.y, self.X, yend=yd2, q=q2, w=self.w.sparse, w_lags=w_lags, robust='hac', gwk=gwk)
     tbetas = np.array([[  4.53017056e+01], [  6.20888617e-01], [ -4.80723451e-01], [  2.83622122e-02]])
     np.testing.assert_array_almost_equal(base_gm_lag.betas, tbetas) 
     dbetas = D.se_betas(base_gm_lag)
     se_betas = np.array([ 19.08513569,   0.51769543,   0.18244862,   0.35460553])
     np.testing.assert_array_almost_equal(dbetas, se_betas)
开发者ID:CartoDB,项目名称:pysal,代码行数:15,代码来源:test_twosls_sp.py


示例8: test_Kernel

    def test_Kernel(self):
        kw = pysal.Kernel(self.points)
        wds = {kw.neighbors[0][i]: v for i, v in enumerate(kw.weights[0])}
        self.assertEqual(wds, {0: 1, 1: 0.500000049999995, 3: 0.4409830615267465})
        kw15 = pysal.Kernel(self.points, bandwidth=15.0)
        self.assertEqual(kw15[0], {0: 1.0, 1: 0.33333333333333337,
                                   3: 0.2546440075000701})
        self.assertEqual(kw15.bandwidth[0], 15.)
        self.assertEqual(kw15.bandwidth[-1], 15.)
        bw = [25.0, 15.0, 25.0, 16.0, 14.5, 25.0]
        kwa = pysal.Kernel(self.points, bandwidth=bw)
        wds = {kwa.neighbors[0][i]: v for i, v in enumerate(kwa.weights[0])}
        self.assertEqual(wds, {0: 1.0, 1: 0.59999999999999998,
                               3: 0.55278640450004202, 4: 0.10557280900008403})
        self.assertEqual(kwa.bandwidth[0], 25.)
        self.assertEqual(kwa.bandwidth[1], 15.)
        self.assertEqual(kwa.bandwidth[2], 25.)
        self.assertEqual(kwa.bandwidth[3], 16.)
        self.assertEqual(kwa.bandwidth[4], 14.5)
        self.assertEqual(kwa.bandwidth[5], 25.)
        kwea = pysal.Kernel(self.points, fixed=False)
        wds = {kwea.neighbors[0][i]: v for i, v in enumerate(kw.weights[0])}
        self.assertEqual(kwea.weights[0], [1.0, 0.10557289844279438,
                                           9.9999990066379496e-08])
        l = kwea.bandwidth.tolist()
        np.allclose(l, [[11.180341005532938], [11.180341005532938],
                        [20.000002000000002], [11.180341005532938],
                        [14.142137037944515], [18.027758180095585]])
        kweag = pysal.Kernel(self.points, fixed=False, function='gaussian')
        wds = {kweag.neighbors[0][i]: v for i, v in enumerate(kweag.weights[0])}
        self.assertEqual(wds, {0: 0.3989422804014327,
                               1: 0.26741902915776961,
                               3: 0.24197074871621341})
        l = kweag.bandwidth.tolist()
        np.allclose(l, [[11.180341005532938], [11.180341005532938],
                        [20.000002000000002], [11.180341005532938],
                        [14.142137037944515], [18.027758180095585]])

        kw = pysal.kernelW_from_shapefile(self.polyShp, idVariable='POLYID')
        wds = {kw.neighbors[1][i]: v for i, v in enumerate(kw.weights[1])}
        self.assertEqual(wds, {4: 0.0070787731484506233,
                               2: 0.2052478782400463,
                               3: 0.23051223027663237,
                               1: 1.0})
        kwa = pysal.adaptive_kernelW_from_shapefile(self.polyShp)
        wds = {kwa.neighbors[0][i]: v for i, v in enumerate(kwa.weights[0])}
        self.assertEqual(wds, {0: 1.0, 2: 0.03178906767736345,
                               1: 9.9999990066379496e-08})
开发者ID:CartoDB,项目名称:pysal,代码行数:48,代码来源:test_Distance.py


示例9: test_names

 def test_names(self):
     w = pysal.queen_from_shapefile(pysal.examples.get_path("columbus.shp"))
     gwk = pysal.kernelW_from_shapefile(
         pysal.examples.get_path("columbus.shp"), k=5, function="triangular", fixed=False
     )
     name_x = ["inc"]
     name_y = "crime"
     name_yend = ["hoval"]
     name_q = ["discbd"]
     name_w = "queen"
     name_gwk = "k=5"
     name_ds = "columbus"
     reg = TSLS(
         self.y,
         self.X,
         self.yd,
         self.q,
         spat_diag=True,
         w=w,
         robust="hac",
         gwk=gwk,
         name_x=name_x,
         name_y=name_y,
         name_q=name_q,
         name_w=name_w,
         name_yend=name_yend,
         name_gwk=name_gwk,
         name_ds=name_ds,
     )
     betas = np.array([[88.46579584], [0.5200379], [-1.58216593]])
     np.testing.assert_array_almost_equal(reg.betas, betas, 7)
     vm = np.array(
         [
             [225.0795089, 17.11660041, -12.22448566],
             [17.67097154, 2.47483461, -1.4183641],
             [-12.45093722, -1.40495464, 0.8700441],
         ]
     )
     np.testing.assert_array_almost_equal(reg.vm, vm, 7)
     self.assertListEqual(reg.name_x, ["CONSTANT"] + name_x)
     self.assertListEqual(reg.name_yend, name_yend)
     self.assertListEqual(reg.name_q, name_q)
     self.assertEqual(reg.name_y, name_y)
     self.assertEqual(reg.name_w, name_w)
     self.assertEqual(reg.name_gwk, name_gwk)
     self.assertEqual(reg.name_ds, name_ds)
开发者ID:pastephens,项目名称:pysal,代码行数:46,代码来源:test_twosls_sparse.py


示例10: test_names

 def test_names(self):
     w = pysal.queen_from_shapefile(pysal.examples.get_path('columbus.shp'))
     gwk = pysal.kernelW_from_shapefile(pysal.examples.get_path('columbus.shp'),k=5,function='triangular', fixed=False)
     name_x = ['inc']
     name_y = 'crime'
     name_yend = ['hoval']
     name_q = ['discbd']
     name_w = 'queen'
     name_gwk = 'k=5'
     name_ds = 'columbus'
     name_regimes= 'nsa'
     reg = TSLS_Regimes(self.y, self.x, self.yd, self.q, self.regimes, regime_err_sep=False,
             spat_diag=True, w=w, robust='hac', gwk=gwk, name_regimes=name_regimes,
             name_x=name_x, name_y=name_y, name_q=name_q, name_w=name_w,
             name_yend=name_yend, name_gwk=name_gwk, name_ds=name_ds)
     betas = np.array([[ 80.23408166],[  5.48218125],[ 82.98396737],[  0.49775429],[ -3.72663211],[ -1.27451485]])
     np.testing.assert_array_almost_equal(reg.betas, betas, 7)
     vm = np.array([[ 522.75813101,  120.64940697,  -15.60303241,   -0.976389  ,\
      -67.15556574,    0.64553579],\
    [ 122.83491674,  122.62303068,   -5.52270916,    0.05023488,\
      -57.89404902,    0.15750428],\
    [   0.1983661 ,   -0.03539147,  335.24731378,   17.40764168,\
       -0.26447114,  -14.3375455 ],\
    [  -0.13612426,   -0.43622084,   18.46644989,    2.70320508,\
        0.20398876,   -1.31821991],\
    [ -68.0704928 ,  -58.03685405,    2.66225388,    0.00323082,\
       27.68512974,   -0.08124602],\
    [  -0.08001296,    0.13575504,  -14.6998294 ,   -1.28225201,\
       -0.05193056,    0.79845124]])
     np.testing.assert_array_almost_equal(reg.vm, vm, 7)
     self.assertEqual(reg.name_x, ['0_CONSTANT', '0_inc', '1_CONSTANT', '1_inc'])
     self.assertEqual(reg.name_yend, ['0_hoval', '1_hoval'])
     self.assertEqual(reg.name_q, ['0_discbd', '1_discbd'])
     self.assertEqual(reg.name_y, name_y)
     self.assertEqual(reg.name_w, name_w)
     self.assertEqual(reg.name_gwk, name_gwk)
     self.assertEqual(reg.name_ds, name_ds)
     self.assertEqual(reg.name_regimes, name_regimes)
开发者ID:PepSalehi,项目名称:pysal,代码行数:38,代码来源:test_twosls_regimes.py


示例11: test_names

 def test_names(self):
     X = np.array(self.db.by_col("INC"))
     X = np.reshape(X, (49,1))
     X = SP.csr_matrix(X)
     yd = np.array(self.db.by_col("CRIME"))
     yd = np.reshape(yd, (49,1))
     q = np.array(self.db.by_col("DISCBD"))
     q = np.reshape(q, (49,1))
     w = pysal.queen_from_shapefile(pysal.examples.get_path('columbus.shp'))
     gwk = pysal.kernelW_from_shapefile(pysal.examples.get_path('columbus.shp'),k=5,function='triangular', fixed=False)
     name_x = ['inc']
     name_y = 'crime'
     name_yend = ['crime']
     name_q = ['discbd']
     name_w = 'queen'
     name_gwk = 'k=5'
     name_ds = 'columbus'
     reg = GM_Lag(self.y, X, yend=yd, q=q,
             spat_diag=True, w=w, robust='hac', gwk=gwk,
             name_x=name_x, name_y=name_y, name_q=name_q, name_w=name_w,
             name_yend=name_yend, name_gwk=name_gwk, name_ds=name_ds)
     betas = np.array([[  5.46344924e+01], [  4.13301682e-01], [ -5.92637442e-01], [ -7.40490883e-03]])
     np.testing.assert_array_almost_equal(reg.betas, betas, 7)
     vm = np.array( [[  5.70817052e+02, -1.83655385e+01, -8.36602575e+00,  2.37538877e-02],
                     [ -1.85224661e+01,  6.53311383e-01,  2.84209566e-01, -6.47694160e-03],
                     [ -8.31105622e+00,  2.78772694e-01,  1.38144928e-01, -3.98175246e-03],
                     [  2.66662466e-02, -6.23783104e-03, -4.11092891e-03,  1.10936528e-03]]) 
     np.testing.assert_array_almost_equal(reg.vm, vm, 6)
     self.assertListEqual(reg.name_x, ['CONSTANT']+name_x)
     name_yend.append('W_crime')
     self.assertListEqual(reg.name_yend, name_yend)
     name_q.extend(['W_inc', 'W_discbd'])
     self.assertListEqual(reg.name_q, name_q)
     self.assertEqual(reg.name_y, name_y)
     self.assertEqual(reg.name_w, name_w)
     self.assertEqual(reg.name_gwk, name_gwk)
     self.assertEqual(reg.name_ds, name_ds)
开发者ID:denadai2,项目名称:pysal,代码行数:37,代码来源:test_twosls_sp_sparse.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python pysal.lag_spatial函数代码示例发布时间:2022-05-27
下一篇:
Python pys.test函数代码示例发布时间: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