25 #ifndef LSST_AFW_MATH_GAUSSIAN_PROCESS_H
26 #define LSST_AFW_MATH_GAUSSIAN_PROCESS_H
28 #include <Eigen/Dense>
31 #include "ndarray/eigen.h"
34 #include "lsst/daf/base/Citizen.h"
35 #include "lsst/daf/base/DateTime.h"
36 #include "lsst/pex/exceptions.h"
37 #include "lsst/pex/policy.h"
38 #include "lsst/pex/policy/Policy.h"
111 double _before, _beginning;
112 double _eigenTime, _iterationTime, _searchTime, _varianceTime, _totalTime;
113 int _interpolationCount;
122 template <
typename T>
138 explicit Covariogram() : lsst::daf::base::Citizen(typeid(this)){};
147 virtual T
operator()(ndarray::Array<const T, 1, 1>
const &p1,
148 ndarray::Array<const T, 1, 1>
const &p2)
const;
160 template <
typename T>
173 virtual T
operator()(ndarray::Array<const T, 1, 1>
const &, ndarray::Array<const T, 1, 1>
const &)
const;
189 template <
typename T>
206 virtual T
operator()(ndarray::Array<const T, 1, 1>
const &, ndarray::Array<const T, 1, 1>
const &)
const;
209 double _sigma0, _sigma1;
220 template <
typename T>
242 void Initialize(ndarray::Array<T, 2, 2>
const &dt);
259 void findNeighbors(ndarray::Array<int, 1, 1> neighdex, ndarray::Array<double, 1, 1> dd,
260 ndarray::Array<const T, 1, 1>
const &v,
int n_nn)
const;
269 T
getData(
int ipt,
int idim)
const;
292 ndarray::Array<T, 1, 1>
getData(
int ipt)
const;
301 void addPoint(ndarray::Array<const T, 1, 1>
const &v);
325 void getTreeNode(ndarray::Array<int, 1, 1>
const &v,
int dex)
const;
328 ndarray::Array<int, 2, 2> _tree;
329 ndarray::Array<int, 1, 1> _inn;
330 ndarray::Array<T, 2, 2> _data;
332 enum { DIMENSION, LT, GEQ, PARENT };
347 int _npts, _dimensions, _room, _roomStep, _masterParent;
348 mutable int _neighborsFound, _neighborsWanted;
354 mutable ndarray::Array<double, 1, 1> _neighborDistances;
355 mutable ndarray::Array<int, 1, 1> _neighborCandidates;
369 void _organize(ndarray::Array<int, 1, 1>
const &use,
int ct,
int parent,
int dir);
376 int _findNode(ndarray::Array<const T, 1, 1>
const &v)
const;
394 void _lookForNeighbors(ndarray::Array<const T, 1, 1>
const &v,
int consider,
int from)
const;
399 int _testTree()
const;
414 int _walkUpTree(
int target,
int dir,
int root)
const;
424 void _count(
int where,
int *ct)
const;
431 void _descend(
int root);
438 void _reassign(
int target);
443 double _distance(ndarray::Array<const T, 1, 1>
const &p1, ndarray::Array<const T, 1, 1>
const &p2)
const;
467 template <
typename T>
490 GaussianProcess(ndarray::Array<T, 2, 2>
const &dataIn, ndarray::Array<T, 1, 1>
const &ff,
512 GaussianProcess(ndarray::Array<T, 2, 2>
const &dataIn, ndarray::Array<T, 1, 1>
const &mn,
513 ndarray::Array<T, 1, 1>
const &mx, ndarray::Array<T, 1, 1>
const &ff,
527 GaussianProcess(ndarray::Array<T, 2, 2>
const &dataIn, ndarray::Array<T, 2, 2>
const &ff,
545 GaussianProcess(ndarray::Array<T, 2, 2>
const &dataIn, ndarray::Array<T, 1, 1>
const &mn,
546 ndarray::Array<T, 1, 1>
const &mx, ndarray::Array<T, 2, 2>
const &ff,
569 void getData(ndarray::Array<T, 2, 2> pts, ndarray::Array<T, 1, 1> fn,
570 ndarray::Array<int, 1, 1> indices)
const;
581 void getData(ndarray::Array<T, 2, 2> pts, ndarray::Array<T, 2, 2> fn,
582 ndarray::Array<int, 1, 1> indices)
const;
602 int numberOfNeighbors)
const;
618 void interpolate(ndarray::Array<T, 1, 1> mu, ndarray::Array<T, 1, 1> variance,
619 ndarray::Array<T, 1, 1>
const &vin,
int numberOfNeighbors)
const;
640 T
selfInterpolate(ndarray::Array<T, 1, 1> variance,
int dex,
int numberOfNeighbors)
const;
656 void selfInterpolate(ndarray::Array<T, 1, 1> mu, ndarray::Array<T, 1, 1> variance,
int dex,
657 int numberOfNeighbors)
const;
680 void batchInterpolate(ndarray::Array<T, 1, 1> mu, ndarray::Array<T, 1, 1> variance,
681 ndarray::Array<T, 2, 2>
const &queries)
const;
700 void batchInterpolate(ndarray::Array<T, 1, 1> mu, ndarray::Array<T, 2, 2>
const &queries)
const;
706 void batchInterpolate(ndarray::Array<T, 2, 2> mu, ndarray::Array<T, 2, 2> variance,
707 ndarray::Array<T, 2, 2>
const &queries)
const;
713 void batchInterpolate(ndarray::Array<T, 2, 2> mu, ndarray::Array<T, 2, 2>
const &queries)
const;
731 void addPoint(ndarray::Array<T, 1, 1>
const &vin, T f);
742 void addPoint(ndarray::Array<T, 1, 1>
const &vin, ndarray::Array<T, 1, 1>
const &f);
803 int _npts, _useMaxMin, _dimensions, _room, _roomStep, _nFunctions;
805 T _krigingParameter, _lambda;
807 ndarray::Array<T, 1, 1> _max, _min;
808 ndarray::Array<T, 2, 2> _function;
812 std::shared_ptr<Covariogram<T> > _covariogram;
819 #endif //#ifndef LSST_AFW_MATH_GAUSSIAN_PROCESS_H
void getData(ndarray::Array< T, 2, 2 > pts, ndarray::Array< T, 1, 1 > fn, ndarray::Array< int, 1, 1 > indices) const
Return a sub-sample the data underlying the Gaussian Process.
void setCovariogram(std::shared_ptr< Covariogram< T > > const &covar)
Assign a different covariogram to this GaussianProcess.
GaussianProcess(const GaussianProcess &)=delete
void setSigma1(double sigma1)
set the _sigma1 hyper parameter
void addPoint(ndarray::Array< const T, 1, 1 > const &v)
Add a point to the tree.
T getData(int ipt, int idim) const
Return one element of one node on the tree.
void setSigma0(double sigma0)
set the _sigma0 hyper parameter
Stores values of a function sampled on an image and allows you to interpolate the function to unsampl...
void addToTotal(int i)
Adds time to _totalTime and adds counts to _interpolationCount.
This is a structure for keeping track of how long the interpolation methods spend on different parts ...
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.
The parent class of covariogram functions for use in Gaussian Process interpolation.
void setKrigingParameter(T kk)
Assign a value to the Kriging paramter.
int getNPoints() const
return the number of data points stored in the GaussianProcess
void start()
Starts the timer for an individual call to an interpolation routine.
void addToVariance()
Adds time to _varianceTime.
int getNPoints() const
return the number of data points stored in the tree
void setLambda(T lambda)
set the value of the hyperparameter _lambda
Covariogram & operator=(const Covariogram &)=delete
void Initialize(ndarray::Array< T, 2, 2 > const &dt)
Build a KD Tree to store the data for GaussianProcess.
T selfInterpolate(ndarray::Array< T, 1, 1 > variance, int dex, int numberOfNeighbors) const
This method will interpolate the function on a data point for purposes of optimizing hyper parameters...
void batchInterpolate(ndarray::Array< T, 1, 1 > mu, ndarray::Array< T, 1, 1 > variance, ndarray::Array< T, 2, 2 > const &queries) const
Interpolate a list of query points using all of the input data (rather than nearest neighbors) ...
void addToIteration()
Adds time to _iterationTime.
The data for GaussianProcess is stored in a KD tree to facilitate nearest-neighbor searches...
a Covariogram that recreates a neural network with one hidden layer and infinite units in that layer ...
GaussianProcessTimer & getTimes() const
Give the user acces to _timer, an object keeping track of the time spent on various processes within ...
Covariogram()
construct a Covariogram assigning default values to the hyper parameters
void removePoint(int dex)
Remove a point from the tree.
virtual ~SquaredExpCovariogram()
void getTreeNode(ndarray::Array< int, 1, 1 > const &v, int dex) const
Return the _tree information for a given data point.
virtual T operator()(ndarray::Array< const T, 1, 1 > const &, ndarray::Array< const T, 1, 1 > const &) const
Actually evaluate the covariogram function relating two points you want to interpolate from...
void addToSearch()
Adds time to _searchTime.
void removePoint(int dex)
This will remove a point from the data set.
virtual T operator()(ndarray::Array< const T, 1, 1 > const &, ndarray::Array< const T, 1, 1 > const &) const
Actually evaluate the covariogram function relating two points you want to interpolate from...
KdTree & operator=(const KdTree &)=delete
virtual T operator()(ndarray::Array< const T, 1, 1 > const &p1, ndarray::Array< const T, 1, 1 > const &p2) const
Actually evaluate the covariogram function relating two points you want to interpolate from...
void addPoint(ndarray::Array< T, 1, 1 > const &vin, T f)
Add a point to the pool of data used by GaussianProcess for interpolation.
GaussianProcess & operator=(const GaussianProcess &)=delete
int getDim() const
return the dimensionality of data points stored in the GaussianProcess
T interpolate(ndarray::Array< T, 1, 1 > variance, ndarray::Array< T, 1, 1 > const &vin, int numberOfNeighbors) const
Interpolate the function value at one point using a specified number of nearest neighbors.
virtual ~NeuralNetCovariogram()
void setEllSquared(double ellSquared)
set the _ellSquared hyper parameter (the square of the characteristic length scale of the covariogram...
void display()
Displays the current values of all times and _interpolationCount.
void reset()
Resets all of the data members of GaussianProcessTimer to zero.
void addToEigen()
Adds time to _eigenTime.