diff options
author | Holden Rohrer <hr@hrhr.dev> | 2021-01-21 03:33:31 -0500 |
---|---|---|
committer | Holden Rohrer <hr@hrhr.dev> | 2021-01-21 04:00:19 -0500 |
commit | 2b146b8391fd5ca9c8c70d7530ad3968721324e9 (patch) | |
tree | bba07d17b7396006f9bc717d054e68099521a3fb /py | |
parent | 4dc09d93cc9a6df1f0a7d6b228300252192c1fc0 (diff) |
have a complete build for secondary docs, but tables and imgs not fully integrated
Diffstat (limited to 'py')
-rw-r--r-- | py/data2.py | 21 | ||||
-rw-r--r-- | py/deathtable2.py | 2 | ||||
-rw-r--r-- | py/pvals.py | 61 | ||||
-rw-r--r-- | py/stats.py | 38 |
4 files changed, 79 insertions, 43 deletions
diff --git a/py/data2.py b/py/data2.py index 505a79d..a073f4b 100644 --- a/py/data2.py +++ b/py/data2.py @@ -2,6 +2,7 @@ from scipy.spatial import Voronoi, voronoi_plot_2d, KDTree, distance from enum import Enum import matplotlib.pyplot as plt +from matplotlib.path import Path fancy = {'pits':'Artificial Pits', 'obstacles':'Artificial Obstacles', 'trails':'Trail Erasure'} @@ -38,6 +39,9 @@ class Trial: def plot(self, save=False): vor = Voronoi([pit.loc for pit in self.pits]) voronoi_plot_2d(vor) + if self.method == 'obstacles': + for obstacle in self.fake: + plt.fill(*obstacle.unzip()) plt.xlabel('%s (dimension %dx%dcm)' % (fancy[self.method], self.size[0], self.size[1])) if save: plt.savefig('%s-%dx%d.png'%(self.method,self.size[0],self.size[1]), @@ -53,6 +57,16 @@ class Trial: class Obstacle: def __init__(self, coords): self.coords = coords + self.path = Path(coords) + + def contains(self, point): + return self.path.contains_point(point) + + def multicontains(self, points): + return self.path.contains_points(points) + + def unzip(self): + return ([x[0] for x in self.coords],[x[1] for x in self.coords]) trials = [ Trial('trails', 1, 2, [24,24], [ @@ -135,8 +149,8 @@ trials = [ Pit((22,16),2,4), ], fake=[ Obstacle([(8,3),(1,7),(7,16)]), - Obstacle([(18,1),(16,7),(21,4),(21,7)]), - Obstacle([(17,15),(18,20),(23,19),(21,20)]) + Obstacle([(18,1),(16,7),(21,7),(21,4)]), + Obstacle([(17,15),(18,20),(21,20),(23,19)]) ]), Trial('obstacles', 3, 0, [12,12], [ Pit((2,11),2,3), @@ -149,6 +163,5 @@ trials = [ Pit((10,11),2,4), Pit((6,3),3,5), Pit((12,9),1,2), - ], fake=[ Obstacle([(10,2),(11,9),(3,5),(3,8)]) ]), + ], fake=[ Obstacle([(10,2),(11,9),(3,8),(3,5)]) ]), ] - diff --git a/py/deathtable2.py b/py/deathtable2.py index 401d42e..ec0f171 100644 --- a/py/deathtable2.py +++ b/py/deathtable2.py @@ -6,7 +6,7 @@ Nearest Neighbor (avg) & Width (avg) & Depth (avg)\\cr\\tabrule') for trial in trials: print('& '.join(['$'+'\\times'.join([str(el) for el in trial.size])+'$', - names[trial.method], str(trial.recl), str(trial.dead), + fancy[trial.method], str(trial.recl), str(trial.dead), str(len(trial.pits)), '%.2f' % mean(trial.nearest_neighbor()), '%.2f' % mean([pit.diam for pit in trial.pits]), '%.2f' % mean([pit.depth for pit in trial.pits])])+'\\cr\\tabrule') diff --git a/py/pvals.py b/py/pvals.py new file mode 100644 index 0000000..9f46826 --- /dev/null +++ b/py/pvals.py @@ -0,0 +1,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') diff --git a/py/stats.py b/py/stats.py deleted file mode 100644 index b79e56f..0000000 --- a/py/stats.py +++ /dev/null @@ -1,38 +0,0 @@ -from data2 import trials -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): - size = trials[trialno].size[0] - pits = len(trials[trialno].pits) - - nnsim = [] - for j in range(10000): - curpits = [] - for k in range(pits): - curpits.append([random()*size,random()*size]) - 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 - -for n in range(len(trials)): - print(calcpval(n)) |