18 int cacheId =
InCache(inputs.at(0));
30 std::vector<size_t> indices;
31 std::vector<double> squaredDists;
32 std::tie(indices, squaredDists) =
kdTree->query(input, 1);
34 if(squaredDists.at(0)<std::numeric_limits<double>::epsilon()){
46 const Eigen::VectorXd& newOutput =
function->Evaluate(newPt).at(0);
49 Add(newPt, newOutput);
55 unsigned int FlannCache::Add(Eigen::VectorXd
const& input, Eigen::VectorXd
const& result) {
56 assert(input.size()==
function->inputSizes(0));
57 assert(result.size()==
function->outputSizes(0));
81 if(
id<0 ) {
return; }
95 std::vector<size_t> indices;
96 std::vector<double> squaredDists;
97 std::tie(indices, squaredDists) =
kdTree->query(point, 1);
98 assert(indices.size()==1);
99 assert(squaredDists.size()==1);
105 unsigned int const k,
106 std::vector<Eigen::VectorXd>& neighbors,
107 std::vector<Eigen::VectorXd>& result)
const {
111 std::vector<size_t> indices;
112 std::vector<double> squaredDists;
113 std::tie(indices, squaredDists) =
kdTree->query(point,
k);
114 assert(indices.size()==
k);
115 assert(squaredDists.size()==
k);
119 for(
unsigned int i=0; i<
k; ++i ){
120 neighbors.at(i) =
kdTree->m_data.at(indices[i]);
126 unsigned int const k,
127 std::vector<Eigen::VectorXd>& neighbors)
const {
131 std::vector<size_t> indices;
132 std::vector<double> squaredDists;
133 std::tie(indices, squaredDists) =
kdTree->query(point,
k);
134 assert(indices.size()==
k);
135 assert(squaredDists.size()==
k);
138 for(
unsigned int i=0; i<
k; ++i ){ neighbors.at(i) =
kdTree->m_data.at(indices[i]); }
146 std::vector<Eigen::VectorXd>
FlannCache::Add(std::vector<Eigen::VectorXd>
const& inputs) {
147 std::vector<Eigen::VectorXd> results(inputs.size());
149 for(
unsigned int i=0; i<inputs.size(); ++i ) {
151 const int index =
InCache(inputs[i]);
165 void FlannCache::Add(std::vector<Eigen::VectorXd>
const& inputs, std::vector<Eigen::VectorXd>
const& results) {
166 assert(inputs.size()==results.size());
168 for(
unsigned int i=0; i<inputs.size(); ++i ) {
170 Add(inputs[i], results[i]);
180 assert(index<kdTree->m_data.size());
181 return kdTree->m_data[index];
185 assert(index<kdTree->m_data.size());
186 return kdTree->m_data[index];
std::vector< Eigen::VectorXd > outputCache
virtual void EvaluateImpl(ref_vector< Eigen::VectorXd > const &inputs) override
void UpdateCentroid(Eigen::VectorXd const &point)
Update the centroid when a new point is added to the cache.
std::vector< Eigen::VectorXd > Add(std::vector< Eigen::VectorXd > const &inputs)
Add new points to the cache.
std::shared_ptr< ModPiece > function
The function whose input/outputs we are caching.
std::shared_ptr< DynamicKDTreeAdaptor<> > kdTree
The nearest neighbor index, used to perform searches.
void NearestNeighbors(Eigen::VectorXd const &point, unsigned int const k, std::vector< Eigen::VectorXd > &neighbors) const
Find the nearest neighbors.
FlannCache(std::shared_ptr< ModPiece > function)
Eigen::VectorXd Centroid() const
Get the centroid of the cache.
unsigned int Size() const
Get the size of the cache.
const Eigen::VectorXd at(unsigned int const index) const
Get an input point from the cache.
Eigen::VectorXd centroid
The centroid of the input addPoints.
size_t NearestNeighborIndex(Eigen::VectorXd const &point) const
The index of the nearest neighbor.
void Remove(Eigen::VectorXd const &input)
Remove point from the cache.
int InCache(Eigen::VectorXd const &input) const
Determine if an entry is in the cache.
std::shared_ptr< ModPiece > Function() const
Get the underlying function.
Eigen::VectorXd const & OutputValue(unsigned int index) const
Returns the model for a specific cache index.
Provides an abstract interface for defining vector-valued model components.
const Eigen::VectorXi inputSizes
std::vector< Eigen::VectorXd > outputs
std::vector< std::reference_wrapper< const T > > ref_vector
A vector of references to something ...