Skip to content

Commit

Permalink
Draft autoreg working on Magic
Browse files Browse the repository at this point in the history
  • Loading branch information
jlaura committed Jul 2, 2014
1 parent 070d6bd commit 84658da
Show file tree
Hide file tree
Showing 7 changed files with 970 additions and 169,239 deletions.
14 changes: 11 additions & 3 deletions autoreg/autoreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,17 @@ def main(dep, indep, opvalue=0.01, combo=False, datafile='columbus.dbf', adjacen

results['regression1'] = r1
results['regression2'] = r2

outvect = np.column_stack((r1['u'], r2['u']))
header = 'r1_residuals r2_residuals'
reg1 = r1['u'][:,0]
reg2 = r2['u'][:,0]
reg1class = ps.esda.mapclassify.Quantiles(reg1, k=4).yb
reg2class = ps.esda.mapclassify.Quantiles(reg2, k=4).yb

print r1['u'].shape
print r2['u'].shape
print reg1class

outvect = np.column_stack((reg1,reg1class,reg2, reg2class))
header = 'r1_residuals r1_residuals_bins r2_residuals r2_residuals_bins'

np.savetxt(outcsv, outvect, delimiter=',', fmt='%10.4f', header=header)

Expand Down
55 changes: 34 additions & 21 deletions autoreg/generateW.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
kdtree.leafnode = kdtree.KDTree.leafnode
kdtree.innernode = kdtree.KDTree.innernode

def main(datafile, adjacency):
def main(datafile, adjacency=None):
import time
t1 = time.time()
if adjacency.lower() == 'queen':
Expand All @@ -21,30 +21,23 @@ def main(datafile, adjacency):
w.adjacency = adjacency
t2 = time.time()
print "Time W: ", t2 - t1

gwk = ps.weights.user.kernelW_from_shapefile(datafile, 5, diagonal=True)
gwk.adjacency = adjacency
t3 = time.time()
print "Time GWK: ", t3 - t2
#Write W to disk
wout = datafile.split('.')[0] + '_W.pkl'

gwkout = datafile.split('.')[0] + '_GWK.pkl'
if not os.path.exists(gwkout):
gwk = ps.weights.user.kernelW_from_shapefile(datafile, 5, diagonal=True)
gwk.adjacency = adjacency
t3 = time.time()
print "Time GWK: ", t3 - t2

try:
os.remove(wout)
except OSError:
pass

try:
os.remove(gwkout)
except OSError:
pass
#Write W to disk
if adjacency == 'rook':
wout = datafile.split('.')[0] + '_WR.pkl'
else:
wout = datafile.split('.')[0] + '_WQ.pkl'

t1 = time.time()
with open(wout, 'wb') as f:
cPickle.dump(w, f, cPickle.HIGHEST_PROTOCOL)
with open(gwkout, 'wb') as f:
cPickle.dump(gwk, f, cPickle.HIGHEST_PROTOCOL)
t2 = time.time()
print "Dumping: ",t2 - t1

Expand All @@ -61,8 +54,28 @@ def main(datafile, adjacency):

if __name__ == '__main__':
datafile = sys.argv[1]
adjacency = sys.argv[2]
wq = ps.weights.user.queen_from_shapefile(datafile)
wr = ps.weights.user.rook_from_shapefile(datafile)

main(datafile, adjacency)
wq.transform = 'r'
wq.adjacency = 'Queen'

wr.transform = 'r'
wr.adjacency = 'Rook'

gwk = ps.weights.user.kernelW_from_shapefile(datafile, 5, diagonal=True)

#Write W to disk
wqout = datafile.split('.')[0] + '_WQ.pkl'
wrout = datafile.split('.')[0] + '_WR.pkl'
gwkout = datafile.split('.')[0] + '_GWK.pkl'

with open(wqout, 'wb') as f:
cPickle.dump(wq, f, cPickle.HIGHEST_PROTOCOL)
with open(wrout, 'wb') as f:
cPickle.dump(wr, f, cPickle.HIGHEST_PROTOCOL)
with open(gwkout, 'wb') as f:
cPickle.dump(gwk, f, cPickle.HIGHEST_PROTOCOL)
with open(datafile.split('.')[0] + '_done', 'w') as f:
f.write('done');

9 changes: 5 additions & 4 deletions autoreg/out
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Time W: 1.92246079445
Time GWK: 103.252546072
Dumping: 6.03054118156
W: 114.623517036
W: 0.00410199165344
pbsout_summary.txt
pbsout_vectors.csv
(49, 1)
(49, 1)
[3 1 0 2 1 0 3 2 3 3 2 1 3 3 0 1 3 3 2 3 0 1 2 3 2 0 2 2 3 2 0 1 1 0 1 0 2
1 1 2 1 1 0 0 0 3 2 0 0]
Loading

0 comments on commit 84658da

Please sign in to comment.