Skip to content

Commit e3fbbc6

Browse files
authored
Merge pull request #17 from weikang9009/vec_cor
Move np.random.seed into individual testing cases for test_vec_SA.py
2 parents ec76c38 + 248deac commit e3fbbc6

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

spint/tests/test_vec_SA.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

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

@@ -31,12 +30,14 @@ def test_origin_focused_A(self):
3130
threshold=9999,
3231
alpha=-1.5,
3332
binary=False)
33+
np.random.seed(1)
3434
vmo = VecMoran(self.vecs, wo, focus='origin', rand='A')
3535
self.assertAlmostEquals(vmo.I, 0.645944594367)
36-
self.assertAlmostEquals(vmo.p_z_sim, 0.099549579548)
36+
self.assertAlmostEquals(vmo.p_z_sim, 0.03898650733809228)
3737

3838
def test_dest_focused_A(self):
3939
wd = DistanceBand(self.dests, threshold=9999, alpha=-1.5, binary=False)
40+
np.random.seed(1)
4041
vmd = VecMoran(self.vecs, wd, focus='destination', rand='A')
4142
self.assertAlmostEquals(vmd.I, -0.764603695022)
4243
self.assertAlmostEquals(vmd.p_z_sim, 0.149472673677)
@@ -47,15 +48,17 @@ def test_origin_focused_B(self):
4748
threshold=9999,
4849
alpha=-1.5,
4950
binary=False)
51+
np.random.seed(1)
5052
vmo = VecMoran(self.vecs, wo, focus='origin', rand='B')
5153
self.assertAlmostEquals(vmo.I, 0.645944594367)
52-
self.assertAlmostEquals(vmo.p_z_sim, 0.071427063787951814)
54+
self.assertAlmostEquals(vmo.p_z_sim, 0.02944612633233532)
5355

5456
def test_dest_focused_B(self):
5557
wd = DistanceBand(self.dests, threshold=9999, alpha=-1.5, binary=False)
58+
np.random.seed(1)
5659
vmd = VecMoran(self.vecs, wd, focus='destination', rand='B')
5760
self.assertAlmostEquals(vmd.I, -0.764603695022)
58-
self.assertAlmostEquals(vmd.p_z_sim, 0.086894261015806051)
61+
self.assertAlmostEquals(vmd.p_z_sim, 0.12411761124197379)
5962

6063

6164
if __name__ == '__main__':

spint/vec_SA.py

+19-19
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 libpysal.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

0 commit comments

Comments
 (0)