Skip to content

Commit 6f1d482

Browse files
committed
enh: updated spint package
1 parent 5a3b561 commit 6f1d482

File tree

6 files changed

+41
-40
lines changed

6 files changed

+41
-40
lines changed

pysal/model/spint/count_model.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,18 @@ class CountModel(object):
4545
-------
4646
>>> from spint.count_model import CountModel
4747
>>> import pysal.lib
48-
>>> db = pysal.lib.open(pysal.lib.examples.get_path('columbus.dbf'),'r')
48+
>>> db = pysal.lib.io.open(pysal.lib.examples.get_path('columbus.dbf'),'r')
4949
>>> y = np.array(db.by_col("HOVAL"))
5050
>>> y = np.reshape(y, (49,1))
51-
>>> self.y = np.round(y).astype(int)
51+
>>> y = np.round(y).astype(int)
5252
>>> X = []
5353
>>> X.append(db.by_col("INC"))
5454
>>> X.append(db.by_col("CRIME"))
55-
>>> self.X = np.array(X).T
56-
>>> model = CountModel(self.y, self.X, family=Poisson())
55+
>>> X = np.array(X).T
56+
>>> model = CountModel(y, X, family=Poisson())
5757
>>> results = model.fit('GLM')
5858
>>> results.params
59-
array([3.92159085, 0.01183491, -0.01371397])
59+
array([ 3.92159085, 0.01183491, -0.01371397])
6060
6161
"""
6262

pysal/model/spint/gravity.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,12 @@ class BaseGravity(CountModel):
145145
>>> import numpy as np
146146
>>> import pysal.lib
147147
>>> from spint.gravity import BaseGravity
148-
>>> db = pysal.lib.open(pysal.lib.examples.get_path('nyc_bikes_ct.csv'))
148+
>>> db = pysal.lib.io.open(pysal.lib.examples.get_path('nyc_bikes_ct.csv'))
149149
>>> cost = np.array(db.by_col('tripduration')).reshape((-1,1))
150150
>>> flows = np.array(db.by_col('count')).reshape((-1,1))
151151
>>> model = BaseGravity(flows, cost)
152152
>>> model.params
153-
array([ 17.84839637, -1.68325787])
153+
array([17.84839637, -1.68325787])
154154
155155
"""
156156

@@ -431,15 +431,14 @@ class Gravity(BaseGravity):
431431
>>> import numpy as np
432432
>>> import pysal.lib
433433
>>> from spint.gravity import Gravity
434-
>>> db = pysal.lib.open(pysal.lib.examples.get_path('nyc_bikes_ct.csv'))
434+
>>> db = pysal.lib.io.open(pysal.lib.examples.get_path('nyc_bikes_ct.csv'))
435435
>>> cost = np.array(db.by_col('tripduration')).reshape((-1,1))
436436
>>> flows = np.array(db.by_col('count')).reshape((-1,1))
437437
>>> o_cap = np.array(db.by_col('o_cap')).reshape((-1,1))
438438
>>> d_cap = np.array(db.by_col('d_cap')).reshape((-1,1))
439439
>>> model = Gravity(flows, o_cap, d_cap, cost, 'exp')
440440
>>> model.params
441-
array([ 3.80050153e+00, 5.54103854e-01, 3.94282921e-01,
442-
-2.27091686e-03])
441+
array([ 3.80050153e+00, 5.54103854e-01, 3.94282921e-01, -2.27091686e-03])
443442
444443
"""
445444

@@ -653,7 +652,7 @@ class Production(BaseGravity):
653652
>>> import numpy as np
654653
>>> import pysal.lib
655654
>>> from spint.gravity import Production
656-
>>> db = pysal.lib.open(pysal.lib.examples.get_path('nyc_bikes_ct.csv'))
655+
>>> db = pysal.lib.io.open(pysal.lib.examples.get_path('nyc_bikes_ct.csv'))
657656
>>> cost = np.array(db.by_col('tripduration')).reshape((-1,1))
658657
>>> flows = np.array(db.by_col('count')).reshape((-1,1))
659658
>>> o = np.array(db.by_col('o_tract')).reshape((-1,1))
@@ -867,7 +866,7 @@ class Attraction(BaseGravity):
867866
>>> import numpy as np
868867
>>> import pysal.lib
869868
>>> from spint.gravity import Attraction
870-
>>> db = pysal.lib.open(pysal.lib.examples.get_path('nyc_bikes_ct.csv'))
869+
>>> db = pysal.lib.io.open(pysal.lib.examples.get_path('nyc_bikes_ct.csv'))
871870
>>> cost = np.array(db.by_col('tripduration')).reshape((-1,1))
872871
>>> flows = np.array(db.by_col('count')).reshape((-1,1))
873872
>>> d = np.array(db.by_col('d_tract')).reshape((-1,1))
@@ -1082,9 +1081,9 @@ class Doubly(BaseGravity):
10821081
Example
10831082
-------
10841083
>>> import numpy as np
1085-
>>> import libpsal
1084+
>>> import pysal.lib
10861085
>>> from spint.gravity import Doubly
1087-
>>> db = pysal.lib.open(pysal.lib.examples.get_path('nyc_bikes_ct.csv'))
1086+
>>> db = pysal.lib.io.open(pysal.lib.examples.get_path('nyc_bikes_ct.csv'))
10881087
>>> cost = np.array(db.by_col('tripduration')).reshape((-1,1))
10891088
>>> flows = np.array(db.by_col('count')).reshape((-1,1))
10901089
>>> d = np.array(db.by_col('d_tract')).reshape((-1,1))

pysal/model/spint/tests/test_vec_SA.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77

88
import unittest
99
import numpy as np
10-
np.random.seed(1)
1110
from pysal.lib.weights.distance import DistanceBand
1211
from ..vec_SA import VecMoran
1312

1413

15-
@unittest.skip('skipping during reorg')
1614
class TestVecMoran(unittest.TestCase):
1715
"""Tests VecMoran class"""
1816

@@ -32,12 +30,14 @@ def test_origin_focused_A(self):
3230
threshold=9999,
3331
alpha=-1.5,
3432
binary=False)
33+
np.random.seed(1)
3534
vmo = VecMoran(self.vecs, wo, focus='origin', rand='A')
3635
self.assertAlmostEquals(vmo.I, 0.645944594367)
37-
self.assertAlmostEquals(vmo.p_z_sim, 0.099549579548)
36+
self.assertAlmostEquals(vmo.p_z_sim, 0.03898650733809228)
3837

3938
def test_dest_focused_A(self):
4039
wd = DistanceBand(self.dests, threshold=9999, alpha=-1.5, binary=False)
40+
np.random.seed(1)
4141
vmd = VecMoran(self.vecs, wd, focus='destination', rand='A')
4242
self.assertAlmostEquals(vmd.I, -0.764603695022)
4343
self.assertAlmostEquals(vmd.p_z_sim, 0.149472673677)
@@ -48,15 +48,17 @@ def test_origin_focused_B(self):
4848
threshold=9999,
4949
alpha=-1.5,
5050
binary=False)
51+
np.random.seed(1)
5152
vmo = VecMoran(self.vecs, wo, focus='origin', rand='B')
5253
self.assertAlmostEquals(vmo.I, 0.645944594367)
53-
self.assertAlmostEquals(vmo.p_z_sim, 0.071427063787951814)
54+
self.assertAlmostEquals(vmo.p_z_sim, 0.02944612633233532)
5455

5556
def test_dest_focused_B(self):
5657
wd = DistanceBand(self.dests, threshold=9999, alpha=-1.5, binary=False)
58+
np.random.seed(1)
5759
vmd = VecMoran(self.vecs, wd, focus='destination', rand='B')
5860
self.assertAlmostEquals(vmd.I, -0.764603695022)
59-
self.assertAlmostEquals(vmd.p_z_sim, 0.086894261015806051)
61+
self.assertAlmostEquals(vmd.p_z_sim, 0.12411761124197379)
6062

6163

6264
if __name__ == '__main__':

pysal/model/spint/vec_SA.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,14 @@ class VecMoran:
131131
--------
132132
>>> import numpy as np
133133
>>> np.random.seed(1)
134-
>>> from pysal_core.weights import DistanceBand
134+
>>> from pysal.lib.weights import DistanceBand
135135
>>> from spint.vec_SA import VecMoran
136136
>>> vecs = np.array([[1, 55, 60, 100, 500],
137-
>>> [2, 60, 55, 105, 501],
138-
>>> [3, 500, 55, 155, 500],
139-
>>> [4, 505, 60, 160, 500],
140-
>>> [5, 105, 950, 105, 500],
141-
>>> [6, 155, 950, 155, 499]])
137+
... [2, 60, 55, 105, 501],
138+
... [3, 500, 55, 155, 500],
139+
... [4, 505, 60, 160, 500],
140+
... [5, 105, 950, 105, 500],
141+
... [6, 155, 950, 155, 499]])
142142
>>> origins = vecs[:, 1:3]
143143
>>> dests = vecs[:, 3:5]
144144
>>> wo = DistanceBand(origins, threshold=9999, alpha=-1.5, binary=False)
@@ -148,25 +148,25 @@ class VecMoran:
148148
>>> vmo = VecMoran(vecs, wo, focus='origin', rand='A')
149149
>>> vmd = VecMoran(vecs, wd, focus='destination', rand='A')
150150
>>> vmo.I
151-
-0.764603695022
151+
0.6459445943670211
152152
>>> vmo.p_z_sim
153-
0.99549579548
154-
>>> vmd.I
155-
0.645944594367
156-
>>> vmd.p_z_sim
157-
0.1494726733677
153+
0.03898650733809228
154+
>>> vmd.I
155+
-0.7646036950223406
156+
>>> vmd.p_z_sim
157+
0.11275129553163704
158158
159159
#randomization technique B
160160
>>> vmo = VecMoran(vecs, wo, focus='origin', rand='B')
161-
>>> vmd = VecMoran(vecs, wd, foucs='destination', rand='B')
161+
>>> vmd = VecMoran(vecs, wd, focus='destination', rand='B')
162162
>>> vmo.I
163-
-0.764603695022
163+
0.6459445943670211
164164
>>> vmo.p_z_sim
165-
0.071427063787951814
166-
>>> vmd.I
167-
0.645944594367
168-
>>> vmd.p_z_sim
169-
0.086894261015806051
165+
0.05087923006558356
166+
>>> vmd.I
167+
-0.7646036950223406
168+
>>> vmd.p_z_sim
169+
0.1468368983650693
170170
171171
"""
172172

subtags

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ spaghetti https://github.com/pysal/spaghetti/tree/v1.1.0
77
mapclassify https://github.com/pysal/mapclassify/tree/v2.0.1
88
spreg https://github.com/pysal/spreg/tree/v1.0.4
99
spglm https://github.com/pysal/spglm/tree/v1.0.6
10-
spint https://github.com/pysal/spint/tree/v1.0.4
10+
spint https://github.com/pysal/spint/tree/v1.0.5
1111
splot https://github.com/pysal/spint/tree/v1.0.0
1212
mgwr https://github.com/pysal/mgwr/releases/tag/v2.0.2
1313
spvcm https://github.com/pysal/spvcm/tree/v0.2.1

tags.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"libpysal": "v4.0.1", "esda": "v2.0.1", "giddy": "v2.0.0", "inequality": "v1.0.0", "pointpats": "v2.0.0", "spaghetti": "v1.1.0", "mapclassify": "v2.0.1", "spreg": "v1.0.4", "spglm": "v1.0.6", "spint": "v1.0.4", "splot": "v1.0.0", "mgwr": "v2.0.2", "spvcm": "v0.2.1"}
1+
{"libpysal": "v4.0.1", "esda": "v2.0.1", "giddy": "v2.0.0", "inequality": "v1.0.0", "pointpats": "v2.0.0", "spaghetti": "v1.1.0", "mapclassify": "v2.0.1", "spreg": "v1.0.4", "spglm": "v1.0.6", "spint": "v1.0.5", "splot": "v1.0.0", "mgwr": "v2.0.2", "spvcm": "v0.2.1"}

0 commit comments

Comments
 (0)