update tests to queen weights from knn
This commit is contained in:
parent
166e9e223f
commit
258322fcca
@ -6,18 +6,16 @@ SET client_min_messages TO WARNING;
|
||||
_cdb_random_seeds
|
||||
|
||||
(1 row)
|
||||
z_score|p_value
|
||||
-1.0358|0.0160
|
||||
-0.6404|0.0070
|
||||
2.6802|0.0190
|
||||
4.7529|0.0020
|
||||
2.7270|0.0250
|
||||
-1.2444|0.0230
|
||||
4.6322|0.0150
|
||||
4.5325|0.0220
|
||||
-1.3115|0.0090
|
||||
-1.3115|0.0080
|
||||
4.6361|0.0010
|
||||
2.8307|0.0310
|
||||
-1.3115|0.0020
|
||||
(13 rows)
|
||||
rowid|z_score|p_value
|
||||
9|-0.7862|0.0500
|
||||
22|-0.3955|0.0330
|
||||
33|2.7045|0.0050
|
||||
35|1.9524|0.0130
|
||||
36|-1.2056|0.0170
|
||||
37|3.4785|0.0020
|
||||
38|-1.4622|0.0020
|
||||
40|5.7098|0.0030
|
||||
46|3.4704|0.0120
|
||||
47|-0.9994|0.0320
|
||||
48|-1.3650|0.0340
|
||||
(11 rows)
|
||||
|
@ -5,10 +5,11 @@
|
||||
-- set random seed
|
||||
SELECT cdb_crankshaft._cdb_random_seeds(1234);
|
||||
|
||||
-- test against PySAL example dataset
|
||||
SELECT z_score, p_value
|
||||
-- test against PySAL example dataset 'stl_hom'
|
||||
SELECT rowid, round(z_score, 4) As z_score, round(p_value, 4) As p_value
|
||||
FROM cdb_crankshaft.CDB_GetisOrdsG(
|
||||
'select * from getis_data',
|
||||
'hr8893', 'knn', 5, 999,
|
||||
'the_geom', 'cartodb_id') As t(z_score, p_value, p_z_sim)
|
||||
WHERE p_value <= 0.05;
|
||||
'hr8893', 'queen', NULL, 999,
|
||||
'the_geom', 'cartodb_id') As t(z_score, p_value, p_z_sim, rowid)
|
||||
WHERE round(p_value, 4) <= 0.05
|
||||
ORDER BY rowid ASC;
|
||||
|
2
src/py/crankshaft/test/fixtures/getis.json
vendored
2
src/py/crankshaft/test/fixtures/getis.json
vendored
@ -1 +1 @@
|
||||
[[-0.37337341596824414, 0.43099999999999999, 0.35443527112672846], [-0.95217153199599269, 0.091999999999999998, 0.17050499804382691], [-0.69132084390888426, 0.30299999999999999, 0.24468196785399454], [-0.90994823039851658, 0.088999999999999996, 0.18142490623820451], [-1.0132361542216282, 0.129, 0.15547368761207747], [-0.51678782422627401, 0.058999999999999997, 0.30265214024759912], [-0.59887100659663139, 0.13400000000000001, 0.27462945349842682], [-0.65244852117509244, 0.32900000000000001, 0.2570559358979031], [-1.0357808174963727, 0.0070000000000000001, 0.1501522043425858], [-0.77003625124250874, 0.13600000000000001, 0.22063919456432224], [-0.33236541712916268, 0.375, 0.3698066743983055], [-0.16566702930134228, 0.28699999999999998, 0.43420949712949208], [-1.0188721243221961, 0.113, 0.15413183958086896], [-0.58707183737030266, 0.40100000000000002, 0.27857773047946677], [-0.60787539226595488, 0.34100000000000003, 0.27163506072349475], [-0.8363954400004282, 0.20599999999999999, 0.2014662385347713], [-0.27576758055135975, 0.49399999999999999, 0.39136329273990866], [-0.17698658238285753, 0.38100000000000001, 0.42975946445365665], [-0.42301422073305678, 0.48599999999999999, 0.33614244280579275], [-0.81073978385996837, 0.161, 0.20875756070128504], [-0.63838151273605281, 0.107, 0.26161268117180692], [-0.64010006015388854, 0.0040000000000000001, 0.26105377495417703], [-0.62182425813185527, 0.22700000000000001, 0.2670287167605806], [2.6823577629697111, 0.014, 0.0036552616083728173], [-0.53272604021530889, 0.39400000000000002, 0.29711161877609882], [-0.15271881679589203, 0.34699999999999998, 0.43931001058875374], [-0.46563636027021654, 0.48499999999999999, 0.32073790602545205], [-0.67304141220538694, 0.32200000000000001, 0.25046047260054227], [-0.65348653890355268, 0.27000000000000002, 0.25672133238529804], [-0.042046555130192398, 0.36199999999999999, 0.48323079264157687], [-0.50234667391554988, 0.39400000000000002, 0.30771184147044006], [0.20134863894573138, 0.41199999999999998, 0.42021298643169991], [4.7562332747386709, 0.001, 9.8619270438859985e-07], [-0.17060076279397593, 0.44400000000000001, 0.43226884904800156], [2.7291423642735309, 0.02, 0.0031749642026865921], [-1.244478534224277, 0.036999999999999998, 0.10666174742715517], [2.6167445805079668, 0.045999999999999999, 0.0044386370442521805], [-0.81072889481557631, 0.20799999999999999, 0.20876068801239311], [-0.96834418270546307, 0.049000000000000002, 0.16643625291733932], [4.6354616023251367, 0.017000000000000001, 1.7807091640120731e-06], [1.711490849677441, 0.058999999999999997, 0.043495269461387376], [-0.68553064793121166, 0.317, 0.24650456386912545], [-0.10649304409706747, 0.44, 0.45759558701679381], [-0.54248639601227799, 0.29299999999999998, 0.29374173830183614], [0.031677897850072946, 0.311, 0.48736446049996618], [4.5356561799411086, 0.019, 2.8712332330593782e-06], [-1.3116013794941181, 0.01, 0.094827333672427794], [-1.3116013794941181, 0.0089999999999999993, 0.094827333672427794], [4.6393788826674198, 0.002, 1.7472893316661242e-06], [1.4382028801285995, 0.090999999999999998, 0.07518824913828126], [2.8328951008347012, 0.033000000000000002, 0.0023064260400579295], [-0.26084695643627254, 0.46500000000000002, 0.39710526578910033], [-0.78037465160516584, 0.122, 0.21758519184573832], [-0.64208684814893169, 0.307, 0.2604083973990674], [-1.3116013794941181, 0.001, 0.094827333672427794], [-0.57288206029351252, 0.314, 0.28336227604534636], [1.4616922569671136, 0.10000000000000001, 0.071912780017027833], [-0.10796036062141957, 0.38200000000000001, 0.45701356800520454], [0.25084361591996374, 0.29299999999999998, 0.40096750937264047], [-0.15481933481013774, 0.34699999999999998, 0.43848187401104366], [-0.15333330051666849, 0.35699999999999998, 0.43906772057781862], [-0.23163022692856874, 0.41699999999999998, 0.40841261410676866], [-0.34288722316108555, 0.28399999999999997, 0.36584165208609076], [-0.21867005782535454, 0.38200000000000001, 0.41345353745151792], [-0.79939347077393408, 0.215, 0.21203114760123465], [-0.57405515910861116, 0.19800000000000001, 0.28296523788747729], [0.17162418105442584, 0.151, 0.43186649789407894], [-0.45034522396490928, 0.435, 0.3262307674101308], [0.76919536546476719, 0.122, 0.22088867064513418], [0.43251102361572391, 0.14999999999999999, 0.33268502099692632], [0.37645002404345906, 0.155, 0.3532911812599], [-0.34984866752801247, 0.47699999999999998, 0.36322613637735446], [-0.48122747907298502, 0.439, 0.31517741642583419], [0.8295949731100305, 0.16700000000000001, 0.20338390993964683], [0.32735658947745261, 0.24399999999999999, 0.37169909789396838], [-0.30762465422828866, 0.47899999999999998, 0.37918397900139522], [0.50459229844619902, 0.14399999999999999, 0.30692261012051003], [0.7555990768924421, 0.14999999999999999, 0.22494480477952961]]
|
||||
[(0.004793783909323601, 0.17999999999999999, 0.49808756424021061), (-1.0701189472090842, 0.079000000000000001, 0.14228288580832316), (-0.67867750971877305, 0.42099999999999999, 0.24867110969448558), (-0.67407386707620487, 0.246, 0.25013217644612995), (-0.79495689068870035, 0.33200000000000002, 0.21331928959090596), (-0.49279481022182703, 0.058999999999999997, 0.31107878905057329), (-0.38075627530057132, 0.28399999999999997, 0.35169205342069643), (-0.86710921611314895, 0.23699999999999999, 0.19294108571294855), (-0.78618647240956485, 0.050000000000000003, 0.2158791250244505), (-0.76108527223116984, 0.064000000000000001, 0.22330306830813684), (-0.13340753531942209, 0.247, 0.44693554317763651), (-0.57584545722033043, 0.48999999999999999, 0.28235982246156488), (-0.78882694661192831, 0.433, 0.2151065788731219), (-0.38769767950046219, 0.375, 0.34911988661484239), (-0.56057819488052207, 0.41399999999999998, 0.28754255985169652), (-0.41354017495644935, 0.45500000000000002, 0.339605447117173), (-0.23993577722243081, 0.49099999999999999, 0.40519002230969337), (-0.1389080156677496, 0.40400000000000003, 0.44476141839645233), (-0.25485737510500855, 0.376, 0.39941662953554224), (-0.71218610582902353, 0.17399999999999999, 0.23817476979886087), (-0.54533105995872144, 0.13700000000000001, 0.2927629228714812), (-0.39547917847510977, 0.033000000000000002, 0.34624464252424236), (-0.43052658996257548, 0.35399999999999998, 0.33340631435564982), (-0.37296719193774736, 0.40300000000000002, 0.35458643102865428), (-0.66482612169465694, 0.31900000000000001, 0.25308085650392698), (-0.13772133540823422, 0.34699999999999998, 0.44523032843016275), (-0.6765304487868502, 0.20999999999999999, 0.24935196033890672), (-0.64518763494323472, 0.32200000000000001, 0.25940279912025543), (-0.5078622084312413, 0.41099999999999998, 0.30577498972600159), (-0.12652006733772059, 0.42899999999999999, 0.44966013262301163), (-0.32691133022814595, 0.498, 0.37186747562269029), (0.25533848511500978, 0.42399999999999999, 0.39923083899077472), (2.7045138116476508, 0.0050000000000000001, 0.0034202212972238577), (-0.1551614486076057, 0.44400000000000001, 0.43834701985429037), (1.9524487722567723, 0.012999999999999999, 0.025442473674991528), (-1.2055816465306763, 0.017000000000000001, 0.11398941970467646), (3.478472976017831, 0.002, 0.00025213964072468009), (-1.4621715757903719, 0.002, 0.071847099325659136), (-0.84010307600180256, 0.085000000000000006, 0.20042529779230778), (5.7097646237318243, 0.0030000000000000001, 5.6566262784940591e-09), (1.5082367956567375, 0.065000000000000002, 0.065746966514827365), (-0.58337270103430816, 0.44, 0.27982121546450034), (-0.083271860457022437, 0.45100000000000001, 0.46681768733385554), (-0.46872337815000953, 0.34599999999999997, 0.31963368715684204), (0.18490279849545319, 0.23799999999999999, 0.42665263797981101), (3.470424529947997, 0.012, 0.00025981817437825683), (-0.99942612137154796, 0.032000000000000001, 0.15879415560388499), (-1.3650387953594485, 0.034000000000000002, 0.08612042845912049), (1.8617160516432014, 0.081000000000000003, 0.03132156240215267), (1.1321188945775384, 0.11600000000000001, 0.12879222611766061), (0.064116686050580601, 0.27300000000000002, 0.4744386578180424), (-0.42032194540259099, 0.29999999999999999, 0.33712514016213468), (-0.79581215423980922, 0.123, 0.21307061309098785), (-0.42792753720906046, 0.45600000000000002, 0.33435193892883741), (-1.0629378527428395, 0.051999999999999998, 0.14390506780140866), (-0.54164761752225477, 0.33700000000000002, 0.29403064095211839), (1.0934778886820793, 0.13700000000000001, 0.13709201601893539), (-0.094068785378413719, 0.38200000000000001, 0.46252725802998929), (0.13482026574801856, 0.36799999999999999, 0.44637699118865737), (-0.13976995315653129, 0.34699999999999998, 0.44442087706276601), (-0.051047663924746682, 0.32000000000000001, 0.47964376985626245), (-0.21468297736730158, 0.41699999999999998, 0.41500724761906527), (-0.20873154637330626, 0.38800000000000001, 0.41732890604390893), (-0.32427876152583485, 0.49199999999999999, 0.37286349875557478), (-0.65254842943280977, 0.374, 0.25702372075306734), (-0.48611858196118796, 0.23300000000000001, 0.31344154643990074), (-0.14482354344529477, 0.32600000000000001, 0.44242509660469886), (-0.51052030974200002, 0.439, 0.30484349480873729), (0.56814382285283538, 0.14999999999999999, 0.28496865660103166), (0.58680919931668207, 0.161, 0.27866592887231878), (0.013390357044409013, 0.25800000000000001, 0.49465818005865647), (-0.19050728887961568, 0.41399999999999998, 0.4244558160399462), (-0.60531777422216049, 0.35199999999999998, 0.2724839368239631), (1.0899331115425805, 0.127, 0.13787130480311838), (0.17015055382651084, 0.36899999999999999, 0.43244586845546418), (-0.21738337124409801, 0.40600000000000003, 0.41395479459421991), (1.0329303331079593, 0.079000000000000001, 0.15081825117169467), (1.0218317101096221, 0.104, 0.15343027913308094)]
|
861
src/py/crankshaft/test/fixtures/neighbors_getis.json
vendored
861
src/py/crankshaft/test/fixtures/neighbors_getis.json
vendored
File diff suppressed because one or more lines are too long
@ -18,22 +18,28 @@ import json
|
||||
#
|
||||
# import pysal as ps
|
||||
# import numpy as np
|
||||
# f = ps.open(ps.examples.get_path("stl_hom.txt"))
|
||||
# import random
|
||||
#
|
||||
# # setup variables
|
||||
# f = ps.open(ps.examples.get_path("stl_hom.dbf"))
|
||||
# y = np.array(f.by_col['HR8893'])
|
||||
# w = ps.knnW_from_shapefile(ps.examples.get_path("stl_hom.shp"), k=5)
|
||||
# w_queen = ps.queen_from_shapefile(ps.examples.get_path("stl_hom.shp"))
|
||||
#
|
||||
# out = [{"id": index, "neighbors": w.neighbors[index], "value": val}
|
||||
# for index, val in enumerate(y)]
|
||||
# with open('neighbors_getis.json', 'w') as f:
|
||||
# f.write(str(out))
|
||||
# out_queen = [{"id": index + 1,
|
||||
# "neighbors": [x+1 for x in w_queen.neighbors[index]],
|
||||
# "value": val} for index, val in enumerate(y)]
|
||||
#
|
||||
# with open('neighbors_queen_getis.json', 'w') as f:
|
||||
# f.write(str(out_queen))
|
||||
#
|
||||
# random.seed(1234)
|
||||
# np.random.seed(1234)
|
||||
# # need to do random.seed(1234) too?
|
||||
# lgstar = ps.esda.getisord.G_Local(y, w, star=True, permutations=999)
|
||||
#
|
||||
# with open('getis.json', 'w') as f:
|
||||
# f.write(str(zip(lgstar.z_sim, lgstar.p_sim, lgstar.p_z_sim)))
|
||||
# lgstar_queen = ps.esda.getisord.G_Local(y, w_queen, star=True,
|
||||
# permutations=999)
|
||||
#
|
||||
# with open('getis_queen.json', 'w') as f:
|
||||
# f.write(str(zip(lgstar_queen.z_sim,
|
||||
# lgstar_queen.p_sim, lgstar_queen.p_z_sim)))
|
||||
|
||||
|
||||
class GetisTest(unittest.TestCase):
|
||||
@ -44,9 +50,14 @@ class GetisTest(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
plpy._reset()
|
||||
|
||||
# load raw data for analysis
|
||||
self.neighbors_data = json.loads(
|
||||
open(fixture_file('neighbors_getis.json')).read())
|
||||
self.getis_data = json.loads(open(fixture_file('getis.json')).read())
|
||||
|
||||
# load pre-computed/known values
|
||||
self.getis_data = json.loads(
|
||||
open(fixture_file('getis.json')).read())
|
||||
|
||||
def test_getis_ord(self):
|
||||
"""Test Getis-Ord's G*"""
|
||||
@ -56,7 +67,7 @@ class GetisTest(unittest.TestCase):
|
||||
plpy._define_result('select', data)
|
||||
random_seeds.set_random_seeds(1234)
|
||||
result = cc.getis_ord('subquery', 'value',
|
||||
'knn', 5, 999, 'the_geom', 'cartodb_id')
|
||||
'queen', None, 999, 'the_geom', 'cartodb_id')
|
||||
result = [(row[0], row[1]) for row in result]
|
||||
expected = np.array(self.getis_data)[:, 0:2]
|
||||
for ([res_z, res_p], [exp_z, exp_p]) in zip(result, expected):
|
||||
|
Loading…
Reference in New Issue
Block a user