Changeset cc29f24 in tol


Ignore:
Timestamp:
Jan 6, 2010, 11:38:10 PM (17 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
4f47414
Parents:
f15f246
Message:

Enabling default instances

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@1920 be4846ae-f051-483a-831f-b64e7d08527f

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tol_pkg/MatQuery/KNN.tol

    rf15f246 rcc29f24  
    66
    77//////////////////////////////////////////////////////////////////////////////
    8 //Forward reference
    9 Class @KNN.Neighbourhood;
     8Text _.autodoc.member.KNN.Neighbourhood =
     9"Result of K-Nearest Neighbor Searching ";
     10Class @KNN.Neighbourhood
    1011//////////////////////////////////////////////////////////////////////////////
     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};
    1156
    1257//////////////////////////////////////////////////////////////////////////////
    … …  
    1762{
    1863  //Dimension of points
    19   Real _.n;
     64  Real _.n = 0;
    2065  //Number of reference points
    21   Real _.m;
     66  Real _.m = 0;
    2267  //Reference points by rows: Rows(_.X)==_.m && Columns(_.X)==_.n
    23   Matrix _.X;
     68  Matrix _.X = Rand(0,0,0,0);
    2469
    2570  //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)
    6373};
    6474
    … …  
    7282  //ANN identifier of internal KDTree
    7383  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  };
    75101  ////////////////////////////////////////////////////////////////////////////
    76102  Static @ANN.KDTree New(Matrix X)
    77103  ////////////////////////////////////////////////////////////////////////////
    78104  {
    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
    84108  };
    85109  ////////////////////////////////////////////////////////////////////////////
    … …  
    96120  {
    97121    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])
    99130  }
    100131};
Note: See TracChangeset for help on using the changeset viewer.