1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
from data2 import trials, fancy
from scipy.stats import cramervonmises
from bisect import bisect_left
from random import random
def distance(pit1, pit2):
out = ((pit2[1]-pit1[1])**2 + (pit2[0]-pit1[0])**2)**(1/2)
if (out == 0):
return 100
else:
return out
def cdf(a,nnsim,tup):
return [bisect_left(nnsim, x)/len(nnsim) for x in a]
def calcpval(trialno):
trial = trials[trialno]
size = trial.size[0]
pits = len(trial.pits)
nnsim = []
for j in range(1000):
curpits = []
k = 0
while k < pits:
add = (random()*size,random()*size)
if trial.method == 'obstacles':
for obs in trial.fake:
if obs.contains(add):
continue
if trial.method == 'pits':
for pit in trial.fake:
if distance(add,pit.loc) < pit.diam/2:
continue
curpits.append(add)
k += 1
for pit in curpits:
l = size
for pit2 in curpits:
l = min(l,distance(pit,pit2))
nnsim.append(l)
nnsim.sort()
nnreal = trials[trialno].nearest_neighbor()
stat = cramervonmises(nnreal,cdf,(nnsim,()))
return stat.pvalue
sizes = [[12,12],[24,24]]
meths = ['obstacles','pits','trails']
pvals = [['']*len(sizes) for x in range(len(meths))]
for n in range(len(trials)):
trial = trials[n]
pvals[meths.index(trial.method)][sizes.index(trial.size)] = '%.4f' % calcpval(n)
print('\\tabrule &$12\\times12$&$24\\times24$\\cr\\tabrule')
for row in range(len(meths)):
print(fancy[meths[row]],end='')
for col in range(len(sizes)):
print('&'+pvals[row][col],end='')
print('\\cr\\tabrule')
|