#!/usr/bin/env python
# -*- coding: utf-8 -*-
 
'''
file: kd_tree_kNN.py
author: xjump.me#at#gmail#dot#com

REF:
    http://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.KDTree.html
'''

import numpy as np
import operator
from scipy.spatial import cKDTree as KDTree

import sys
sys.setrecursionlimit(10000)

if __name__=="__main__":
    v0 = np.array([1,2,3,4,5,6])
    train_data_set = np.array([
        [1.2,3,6,7,3,2],
        [2,9,17,7,6,59],
        [1.2,44,6,3,3,23],
        [9,3,51,7,3,100],
        [18,4,39,7,3,21],
        [66,8,28,7,3,88],
        [3,1,2,7,3,33],
        [24,0.5,1,7,3,56],
        [22,99,7,7,3,0.6],
        [70,13,9,7,3,2],
    ])
    tree = KDTree(train_data_set)
    for k in range(1,10):
        print 'k=',k
        #test sample v0, return 3 nearest point, dimesion is k
        print tree.query(v0,k=3,p=k)