aboutsummaryrefslogtreecommitdiff
path: root/py/stats.py
blob: b79e56f42acd0d84416152a894191d798834c477 (plain)
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
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))