Exemple #1
0
def testgendata():
    fname = 'test2.dat'
    querys = 1000
    d = 2
    k=3
    bnds = ((-10,10),)*d
    clsses = (0,1)
    data = getflatcsv(fname)
    kdt = kdtknn(k,method='mode')
    kdt.addEvidence(data)
    kdt.rebuildKDT()
    stime = time.time()
    for x in xrange(querys):
        pnt = numpy.array(gendata.gensingle(d,bnds,clsses))
        reslt = kdt.query(numpy.array([pnt[:-1]]))
        print pnt,"->",reslt
    etime = time.time()
    print etime-stime,'/',querys,'=',(etime-stime)/float(querys),'avg wallclock time per query'
def testgendata():
    fname = "test2.dat"
    querys = 1000
    d = 2
    k = 3
    bnds = ((-10, 10),) * d
    clsses = (0, 1)
    data = getflatcsv(fname)
    kdt = KDTKNN(k)
    kdt.addEvidence(data)
    kdt.rebuildKDT()
    stime = time.time()
    for x in xrange(querys):
        pnt = numpy.array(gendata.gensingle(d, bnds, clsses))
        reslt = kdt.query(numpy.array([pnt[:-1]]))
        print pnt, "->", reslt
    etime = time.time()
    print etime - stime, "/", querys, "=", (etime - stime) / float(querys), "avg wallclock time per query"
Exemple #3
0
def testgendata():
    fname = 'test2.dat'
    querys = 1000
    d = 2
    k=3
    bnds = ((-10,10),)*d
    clsses = (0,1)
    data = getflatcsv(fname)
    kdt = kdtknn(k,method='mode')
    kdt.addEvidence(data)
    kdt.rebuildKDT()
    stime = time.time()
    for x in range(querys):
        pnt = numpy.array(gendata.gensingle(d,bnds,clsses))
        reslt = kdt.query(numpy.array([pnt[:-1]]))
        print(pnt,"->",reslt)
    etime = time.time()
    print(etime-stime,'/',querys,'=',(etime-stime)/float(querys),'avg wallclock time per query')
def testgendata():
	anchors = 200
	fname = 'test2.dat'
	querys = 1000
	d = 2
	k = 3
	bnds = ((-10,10),)*d
	clsses = (0,1)
	foo = FastKNN(anchors,k)
	data = getflatcsv(fname)
	foo.addEvidence(data[:,:-1],data[:,-1])
	foo.num_checks = 0
	for x in range(querys):
		pnt = numpy.array(gendata.gensingle(d,bnds,clsses))
		foo.query(pnt[:-1])
		if x % 50 == 0:
			print(float(foo.num_checks)/float(x+1), end=' ')
			print(x,"/",querys)
	print("Average # queries:", float(foo.num_checks)/float(querys))
def testgendata():
    anchors = 200
    fname = 'test2.dat'
    querys = 1000
    d = 2
    k = 3
    bnds = ((-10, 10), ) * d
    clsses = (0, 1)
    foo = FastKNN(anchors, k)
    data = getflatcsv(fname)
    foo.addEvidence(data[:, :-1], data[:, -1])
    foo.num_checks = 0
    for x in range(querys):
        pnt = numpy.array(gendata.gensingle(d, bnds, clsses))
        foo.query(pnt[:-1])
        if x % 50 == 0:
            print(float(foo.num_checks) / float(x + 1), end=' ')
            print(x, "/", querys)
    print("Average # queries:", float(foo.num_checks) / float(querys))