Changeset cc29f24 in tol
- Timestamp:
- Jan 6, 2010, 11:38:10 PM (17 years ago)
- Branches:
- 1941-docker-image-to-test, devel, master
- Children:
- 4f47414
- Parents:
- f15f246
- File:
-
- 1 edited
-
tol_pkg/MatQuery/KNN.tol (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tol_pkg/MatQuery/KNN.tol
rf15f246 rcc29f24 6 6 7 7 ////////////////////////////////////////////////////////////////////////////// 8 //Forward reference 9 Class @KNN.Neighbourhood; 8 Text _.autodoc.member.KNN.Neighbourhood = 9 "Result of K-Nearest Neighbor Searching "; 10 Class @KNN.Neighbourhood 10 11 ////////////////////////////////////////////////////////////////////////////// 12 { 13 //Number of searched neigbours 14 Real _.k = 0; 15 //Number of queried points 16 Real _.q = 0; 17 //Query points by rows: Rows(_.Q)==_.q && Columns(_.Q)==_.k 18 Matrix _.Q = Rand(0,0,0,0); 19 //Indexes of neighbours in the searcher engine 20 Matrix _.neighbour = Rand(0,0,0,0); 21 //Distance from queried points to its found neighbours 22 Matrix _.distance2 = Rand(0,0,0,0); 23 24 //////////////////////////////////////////////////////////////////////////// 25 Static @KNN.Neighbourhood Default(Real void) 26 //////////////////////////////////////////////////////////////////////////// 27 { 28 @KNN.Neighbourhood new 29 }; 30 //////////////////////////////////////////////////////////////////////////// 31 Real set.data( 32 Matrix Q, 33 Matrix neighbour, 34 Matrix distance2) 35 //////////////////////////////////////////////////////////////////////////// 36 { 37 Real _.k := Columns(Q); 38 Real _.q := Rows(Q); 39 Matrix _.Q := Q; 40 Matrix _.neighbour := neighbour; 41 Matrix _.distance2 := distance2; 42 True 43 }; 44 //////////////////////////////////////////////////////////////////////////// 45 Static @KNN.Neighbourhood New( 46 Matrix Q, 47 Matrix neighbour, 48 Matrix distance2) 49 //////////////////////////////////////////////////////////////////////////// 50 { 51 @KNN.Neighbourhood new; 52 Real new::set.data(Q,neighbour,distance2); 53 new 54 } 55 }; 11 56 12 57 ////////////////////////////////////////////////////////////////////////////// … … 17 62 { 18 63 //Dimension of points 19 Real _.n ;64 Real _.n = 0; 20 65 //Number of reference points 21 Real _.m ;66 Real _.m = 0; 22 67 //Reference points by rows: Rows(_.X)==_.m && Columns(_.X)==_.n 23 Matrix _.X ;68 Matrix _.X = Rand(0,0,0,0); 24 69 25 70 //Searches 26 @KNN.Neighbourhood search(Matrix Q, Real k) 27 }; 28 29 ////////////////////////////////////////////////////////////////////////////// 30 Text _.autodoc.member.KNN.Neighbourhood = 31 "Result of K-Nearest Neighbor Searching "; 32 Class @KNN.Neighbourhood 33 ////////////////////////////////////////////////////////////////////////////// 34 { 35 //Number of searched neigbours 36 Real _.k; 37 //Number of queried points 38 Real _.q; 39 //Query points by rows: Rows(_.Q)==_.q && Columns(_.Q)==_.k 40 Matrix _.Q; 41 //Neighbour searcher engine 42 @KNN _.knn; 43 //Indexes of neighbours in the searcher engine 44 Matrix _.neighbour; 45 //Distance from queried points to its found neighbours 46 Matrix _.distance2; 47 //////////////////////////////////////////////////////////////////////////// 48 Static @KNN.Neighbourhood New( 49 @KNN knn, 50 Matrix Q, 51 Matrix neighbour, 52 Matrix distance2) 53 //////////////////////////////////////////////////////////////////////////// 54 { 55 @KNN.Neighbourhood new = [[ 56 @KNN _.knn = knn; 57 Real _.k = Columns(Q); 58 Real _.q = Rows(Q); 59 Matrix _.Q = Q; 60 Matrix _.neighbour = neighbour; 61 Matrix _.distance2 = distance2 ]] 62 } 71 @KNN.Neighbourhood search(Matrix Q, Real k); 72 Real update.search(Matrix Q, Real k, @KNN.Neighbourhood ngbh) 63 73 }; 64 74 … … 72 82 //ANN identifier of internal KDTree 73 83 Real _id = ?; 74 84 85 //////////////////////////////////////////////////////////////////////////// 86 Static @ANN.KDTree Default(Real void) 87 //////////////////////////////////////////////////////////////////////////// 88 { 89 @ANN.KDTree new 90 }; 91 //////////////////////////////////////////////////////////////////////////// 92 Real set.data(Matrix X) 93 //////////////////////////////////////////////////////////////////////////// 94 { 95 Real __destroy(0); 96 Real _.n := Columns(X); 97 Real _.m := Rows(X); 98 Matrix _.X := X; 99 Real _id := ANN.KDTree.New(_.X) 100 }; 75 101 //////////////////////////////////////////////////////////////////////////// 76 102 Static @ANN.KDTree New(Matrix X) 77 103 //////////////////////////////////////////////////////////////////////////// 78 104 { 79 @ANN.KDTree new = [[ 80 Real _.n = Columns(X); 81 Real _.m = Rows(X); 82 Matrix _.X = X; 83 Real _id = ANN.KDTree.New(_.X) ]] 105 @ANN.KDTree new; 106 Real set.data(X); 107 new 84 108 }; 85 109 //////////////////////////////////////////////////////////////////////////// … … 96 120 { 97 121 Set aux=ANN.KDTree.KSearch(_id,Q,k); 98 @KNN.Neighbourhood::New(_this,Q,aux[1],aux[2]) 122 @KNN.Neighbourhood::New(Q,aux[1],aux[2]) 123 }; 124 //////////////////////////////////////////////////////////////////////////// 125 Real update.search(Matrix Q, Real k, @KNN.Neighbourhood ngbh) 126 //////////////////////////////////////////////////////////////////////////// 127 { 128 Set aux=ANN.KDTree.KSearch(_id,Q,k); 129 ngbh::set.data(Q,aux[1],aux[2]) 99 130 } 100 131 };
Note: See TracChangeset
for help on using the changeset viewer.
