LSSTApplications
10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
|
The data for GaussianProcess is stored in a KD tree to facilitate nearest-neighbor searches. More...
#include <GaussianProcess.h>
Public Member Functions | |
void | Initialize (ndarray::Array< T, 2, 2 > const &dt) |
Build a KD Tree to store the data for GaussianProcess. More... | |
void | findNeighbors (ndarray::Array< int, 1, 1 > neighdex, ndarray::Array< double, 1, 1 > dd, ndarray::Array< const T, 1, 1 > const &v, int n_nn) const |
Find the nearest neighbors of a point. More... | |
T | getData (int ipt, int idim) const |
Return one element of one node on the tree. More... | |
ndarray::Array< T, 1, 1 > | getData (int ipt) const |
Return an entire node from the tree. More... | |
void | addPoint (ndarray::Array< const T, 1, 1 > const &v) |
Add a point to the tree. Allot more space in _tree and data if needed. More... | |
void | removePoint (int dex) |
Remove a point from the tree. Reorganize what remains so that the tree remains self-consistent. More... | |
int | getPoints () const |
return the number of data points stored in the tree More... | |
void | getTreeNode (ndarray::Array< int, 1, 1 > const &v, int dex) const |
Return the _tree information for a given data point. More... | |
Private Types | |
enum | { DIMENSION, LT, GEQ, PARENT } |
Private Member Functions | |
void | _organize (ndarray::Array< int, 1, 1 > const &use, int ct, int parent, int dir) |
Find the daughter point of a node in the tree and segregate the points around it. More... | |
int | _findNode (ndarray::Array< const T, 1, 1 > const &v) const |
Find the point already in the tree that would be the parent of a point not in the tree. More... | |
void | _lookForNeighbors (ndarray::Array< const T, 1, 1 > const &v, int consider, int from) const |
This method actually looks for the neighbors, determining whether or not to descend branches of the tree. More... | |
int | _testTree () const |
Make sure that the tree is properly constructed. Returns 1 of it is. Return zero if not. More... | |
int | _walkUpTree (int target, int dir, int root) const |
A method to make sure that every data point in the tree is in the correct position relative to its parents. More... | |
void | _count (int where, int *ct) const |
A method which counts the number of nodes descended from a given node (used by removePoint(int)) More... | |
void | _descend (int root) |
Descend the tree from a node which has been removed, reassigning severed nodes as you go. More... | |
void | _reassign (int target) |
Reassign nodes to the tree that were severed by a call to removePoint(int) More... | |
double | _distance (ndarray::Array< const T, 1, 1 > const &p1, ndarray::Array< const T, 1, 1 > const &p2) const |
calculate the Euclidean distance between the points p1 and p2 More... | |
Private Attributes | |
ndarray::Array< int, 2, 2 > | _tree |
ndarray::Array< int, 1, 1 > | _inn |
ndarray::Array< T, 2, 2 > | _data |
int | _pts |
int | _dimensions |
int | _room |
int | _roomStep |
int | _masterParent |
int | _neighborsFound |
int | _neighborsWanted |
ndarray::Array< double, 1, 1 > | _neighborDistances |
ndarray::Array< int, 1, 1 > | _neighborCandidates |
The data for GaussianProcess is stored in a KD tree to facilitate nearest-neighbor searches.
Note: I have removed the ability to arbitrarily specify a distance function. The KD Tree nearest neighbor search algorithm only makes sense in the case of Euclidean distances, so I have forced KdTree to use Euclidean distances.
Definition at line 241 of file GaussianProcess.h.
|
private |
Enumerator | |
---|---|
DIMENSION | |
LT | |
GEQ | |
PARENT |
Definition at line 351 of file GaussianProcess.h.
|
private |
A method which counts the number of nodes descended from a given node (used by removePoint(int))
[in] | where | the node you are currently on |
[in,out] | *ct | keeps track of how many nodes you have encountered as you descend the tree |
Definition at line 676 of file GaussianProcess.cc.
|
private |
Descend the tree from a node which has been removed, reassigning severed nodes as you go.
root | the index of the node where you are currently |
Definition at line 718 of file GaussianProcess.cc.
|
private |
calculate the Euclidean distance between the points p1 and p2
Definition at line 728 of file GaussianProcess.cc.
|
private |
Find the point already in the tree that would be the parent of a point not in the tree.
[in] | v | the points whose prospective parent you want to find |
Definition at line 435 of file GaussianProcess.cc.
|
private |
This method actually looks for the neighbors, determining whether or not to descend branches of the tree.
[in] | v | the point whose neighbors you are looking for |
[in] | consider | the index of the data point you are considering as a possible nearest neighbor |
[in] | from | the index of the point you last considered as a nearest neighbor (so the search does not backtrack along the tree) |
The class KdTree keeps track of how many neighbors you want and how many neighbors you have found and what their distances from v are in the class member variables _neighborsWanted, _neighborsFound, _neighborCandidates, and _neighborDistances
Definition at line 460 of file GaussianProcess.cc.
|
private |
Find the daughter point of a node in the tree and segregate the points around it.
[in] | use | the indices of the data points being considered as possible daughters |
[in] | ct | the number of possible daughters |
[in] | parent | the index of the parent whose daughter we are chosing |
[in] | dir | which side of the parent are we on? dir==1 means that we are on the left side; dir==2 means the right side. |
Definition at line 328 of file GaussianProcess.cc.
|
private |
Reassign nodes to the tree that were severed by a call to removePoint(int)
target | the node you are reassigning |
Definition at line 691 of file GaussianProcess.cc.
|
private |
Make sure that the tree is properly constructed. Returns 1 of it is. Return zero if not.
Definition at line 279 of file GaussianProcess.cc.
|
private |
A method to make sure that every data point in the tree is in the correct position relative to its parents.
[in] | target | is the index of the node you are looking at |
[in] | dir | is the direction (1,2) of the branch you ascended from root |
[in] | root | is the node you started walking up from |
This method returns the value of _masterParent if the branch is correctly contructed. It returns zero otherwise
Definition at line 535 of file GaussianProcess.cc.
void lsst.afw.math::KdTree< T >::addPoint | ( | ndarray::Array< const T, 1, 1 > const & | v | ) |
Add a point to the tree. Allot more space in _tree and data if needed.
[in] | v | the point you are adding to the tree |
pex_exceptions | RuntimeError if the branch ending in the new point is not properly constructed |
Definition at line 196 of file GaussianProcess.cc.
void lsst.afw.math::KdTree< T >::findNeighbors | ( | ndarray::Array< int, 1, 1 > | neighdex, |
ndarray::Array< double, 1, 1 > | dd, | ||
ndarray::Array< const T, 1, 1 > const & | v, | ||
int | n_nn | ||
) | const |
Find the nearest neighbors of a point.
[out] | neighdex | this is where the indices of the nearest neighbor points will be stored |
[out] | dd | this is where the distances to the nearest neighbors will be stored |
[in] | v | the point whose neighbors you want to find |
[in] | n_nn | the number of nearest neighbors you want to find |
neighbors will be returned in ascending order of distance
note that distance is forced to be the Euclidean distance
Definition at line 150 of file GaussianProcess.cc.
T lsst.afw.math::KdTree< T >::getData | ( | int | ipt, |
int | idim | ||
) | const |
Return one element of one node on the tree.
[in] | ipt | the index of the node to return |
[in] | idim | the index of the dimension to return |
Definition at line 184 of file GaussianProcess.cc.
ndarray::Array< T, 1, 1 > lsst.afw.math::KdTree< T >::getData | ( | int | ipt | ) | const |
Return an entire node from the tree.
[in] | ipt | the index of the node to return |
I currently have this as a return-by-value method. When I tried it as a return-by-reference, the compiler gave me
warning: returning reference to local temporary object
Based on my reading of Stack Overflow, this is because ndarray was implicitly creating a new ndarray::Array<T,1,1> object and passing a reference thereto. It is unclear to me whether or not this object would be destroyed once the call to getData was complete.
The code still compiled, ran, and passed the unit tests, but the above behavior seemed to me like it could be dangerous (and, because ndarray was still creating a new object, it did not seem like we were saving any time), so I reverted to return-by-value.
Definition at line 190 of file GaussianProcess.cc.
int lsst.afw.math::KdTree< T >::getPoints | ( | ) | const |
return the number of data points stored in the tree
Definition at line 263 of file GaussianProcess.cc.
void lsst.afw.math::KdTree< T >::getTreeNode | ( | ndarray::Array< int, 1, 1 > const & | v, |
int | dex | ||
) | const |
Return the _tree information for a given data point.
[out] | v | the array in which to store the entry from _tree |
[in] | dex | the index of the node whose information you are requesting |
Definition at line 269 of file GaussianProcess.cc.
void lsst.afw.math::KdTree< T >::Initialize | ( | ndarray::Array< T, 2, 2 > const & | dt | ) |
Build a KD Tree to store the data for GaussianProcess.
[in] | dt | an array, the rows of which are the data points (dt[i][j] is the jth component of the ith data point) |
pex_exceptions | RuntimeError if the tree is not properly constructed |
Definition at line 115 of file GaussianProcess.cc.
void lsst.afw.math::KdTree< T >::removePoint | ( | int | dex | ) |
Remove a point from the tree. Reorganize what remains so that the tree remains self-consistent.
[in] | dex | the index of the point you want to remove from the tree |
pex_exceptions | RuntimeError if the entire tree is not poperly constructed after the point has been removed |
Definition at line 574 of file GaussianProcess.cc.
|
private |
Definition at line 349 of file GaussianProcess.h.
|
private |
Definition at line 367 of file GaussianProcess.h.
|
private |
Definition at line 348 of file GaussianProcess.h.
|
private |
Definition at line 367 of file GaussianProcess.h.
|
mutableprivate |
Definition at line 375 of file GaussianProcess.h.
|
mutableprivate |
Definition at line 374 of file GaussianProcess.h.
|
mutableprivate |
Definition at line 368 of file GaussianProcess.h.
|
mutableprivate |
Definition at line 368 of file GaussianProcess.h.
|
private |
Definition at line 367 of file GaussianProcess.h.
|
private |
Definition at line 367 of file GaussianProcess.h.
|
private |
Definition at line 367 of file GaussianProcess.h.
|
private |
Definition at line 347 of file GaussianProcess.h.