In [1]:
import os
os.chdir('../')
from vec_SA import VecMoran
import numpy as np
from pysal.weights.Distance import DistanceBand
import matplotlib.pyplot as plt
%pylab inline
In [237]:
dest_A_rand_I = []
dest_B_rand_I = []
dest_A_rand_p = []
dest_B_rand_p = []
for i in range(1000):
phi = np.random.uniform(0,np.pi*2, 50).reshape((-1,1))
num = np.arange(0,50).reshape((-1,1))
OX = np.random.randint(0,500, 50).reshape((-1,1))
OY = np.random.randint(0,500, 50).reshape((-1,1))
DX = np.cos(phi)*(np.random.randint(0,500, 50)).reshape((-1,1))
DY = np.sin(phi)*np.random.randint(0,500, 50).reshape((-1,1))
vecs = np.hstack([num, OX, OY, DX, DY])
dests = vecs[:, 3:5]
wd = DistanceBand(dests, threshold=9999, alpha=-1.5, binary=False)
vmd = VecMoran(vecs, wd, focus='destination', rand='A', permutations=999)
dest_A_rand_I.append(vmd.I)
dest_A_rand_p.append(vmd.p_z_sim)
vmd = VecMoran(vecs, wd, focus='destination', rand='B', permutations=999)
dest_B_rand_I.append(vmd.I)
dest_B_rand_p.append(vmd.p_z_sim)
In [238]:
X,Y,U,V = zip(*vecs[:,1:])
plt.subplot(111)
for x in range(0,len(vecs[:,1])):
plt.arrow(X[x], #x1
Y[x], # y1
U[x]-X[x], # x2 - x1
V[x]-Y[x], # y2 - y1
fc="k", ec="k", head_width=0.05, head_length=0.1)
plt.xlim([-510,550])
plt.ylim([-510,550])
plt.title('Example of 50 random vectors')
plt.show()
In [239]:
dest_A_cons_I = []
dest_B_cons_I = []
dest_A_cons_p = []
dest_B_cons_p = []
for i in range(1000):
phi = np.random.uniform(0,np.pi*2, 50).reshape((-1,1))
num = np.arange(0,50).reshape((-1,1))
OX = np.random.randint(450,500, 50).reshape((-1,1))
OY = np.random.randint(450,500, 50).reshape((-1,1))
DX = np.cos(phi)*(np.random.randint(450,500, 50)).reshape((-1,1))
DY = np.sin(phi)*np.random.randint(450,500, 50).reshape((-1,1))
vecs = np.hstack([num, OX, OY, DX, DY])
dests = vecs[:, 3:5]
wd = DistanceBand(dests, threshold=9999, alpha=-1.5, binary=False)
vmd = VecMoran(vecs, wd, focus='destination', rand='A', permutations=999)
dest_A_cons_I.append(vmd.I)
dest_A_cons_p.append(vmd.p_z_sim)
vmd = VecMoran(vecs, wd, focus='destination', rand='B', permutations=999)
dest_B_cons_I.append(vmd.I)
dest_B_cons_p.append(vmd.p_z_sim)
In [240]:
X,Y,U,V = zip(*vecs[:,1:])
plt.subplot(111)
for x in range(0,len(vecs[:,1])):
plt.arrow(X[x], #x1
Y[x], # y1
U[x]-X[x], # x2 - x1
V[x]-Y[x], # y2 - y1
fc="k", ec="k", head_width=0.05, head_length=0.1)
plt.xlim([-510,550])
plt.ylim([-510,550])
plt.title('Example of 50 random vectors with constrained origins')
plt.show()
In [247]:
#Method A random
plt.hist(dest_A_rand_I, bins = 25)
plt.title('Distribution of VMD I values from random vectors - Method A')
plt.show()
plt.hist(dest_A_rand_p, bins = 25)
plt.title('Distribution of p values from random vectors - Method A')
plt.show()
In [248]:
#Method A constricted
plt.hist(dest_A_cons_I, bins=25)
plt.title('Distribution of VMD I values from constrained vectors - Method A')
plt.show()
plt.hist(dest_A_cons_p, bins=25)
plt.title('Distribution of p values from constrained vectors - Method A')
plt.show()
In [249]:
#Method B random
plt.hist(dest_B_rand_I, bins=25)
plt.title('Distribution of VMD I values from random vectors - Method B')
plt.show()
plt.hist(dest_B_rand_p, bins=25)
plt.title('Distribution of p values from random vectors - Method B')
plt.show()
In [250]:
#Method B constricted
plt.hist(dest_B_cons_I, bins=25)
plt.title('Distribution of VMD I values from constrained vectors - Method B')
plt.show()
plt.hist(dest_B_cons_p, bins=25)
plt.title('Distribution of p values from constrained vectors - Method B')
plt.show()
In [245]:
print 'a'
In [ ]: