SOT
Public Member Functions | Protected Attributes | List of all members
sot::kNN Class Reference

k-nearest neighbors More...

#include <kNN.h>

Inheritance diagram for sot::kNN:
sot::Surrogate

Public Member Functions

 kNN (int maxPoints, int dim, int k)
 Constructor. More...
 
int dim () const
 Method for getting the number of dimensions. More...
 
int numPoints () const
 Method for getting the current number of points. More...
 
mat X () const
 Method for getting the current points. More...
 
vec X (int i) const
 Method for getting current point number i (0 is the first) More...
 
vec fX () const
 Method for getting the values of the current points. More...
 
double fX (int i) const
 Method for getting the value of current point number i (0 is the first) More...
 
void addPoint (const vec &point, double funVal)
 Method for adding a point with a known value. More...
 
void addPoints (const mat &points, const vec &funVals)
 Method for adding multiple points with known values. More...
 
double eval (const vec &point) const
 Method for evaluating the surrogate model at a point. More...
 
double eval (const vec &point, const vec &dists) const
 Method for evaluating the surrogate at multiple points. More...
 
vec evals (const mat &points) const
 Method for evaluating the surrogate at multiple points. More...
 
vec evals (const mat &points, const mat &dists) const
 Method for evaluating the surrogate at multiple points. More...
 
vec deriv (const vec &point) const
 Method for evaluating the kNN derivative at one point (not implemented) More...
 
void reset ()
 Method for resetting the surrogate model.
 
void fit ()
 Fits kNN (does nothing)
 

Protected Attributes

int mDim
 
int mMaxPoints
 
int mNumPoints
 
int mk
 
mat mX
 
vec mfX
 

Detailed Description

k-nearest neighbors

The kNN method is a robust regression method that approximates the value at a given point as the average of the k closest points.

Author
David Eriksson, dme65.nosp@m.@cor.nosp@m.nell..nosp@m.edu

Constructor & Destructor Documentation

sot::kNN::kNN ( int  maxPoints,
int  dim,
int  k 
)
inline

Constructor.

Parameters
maxPointsCapacity
dimNumber of dimensions
k(number of neighbors used in averaging)

Member Function Documentation

void sot::kNN::addPoint ( const vec point,
double  funVal 
)
inlinevirtual

Method for adding a point with a known value.

Parameters
pointPoint to be added
funValFunction value at point
Exceptions
std::logic_errorif one point is supplied or if capacity is exceeded

Implements sot::Surrogate.

void sot::kNN::addPoints ( const mat points,
const vec funVals 
)
inlinevirtual

Method for adding multiple points with known values.

Parameters
pointsPoints to be added
funValsFunction values at the points
Exceptions
std::logic_errorif one point is supplied or if capacity is exceeded

Implements sot::Surrogate.

vec sot::kNN::deriv ( const vec point) const
inlinevirtual

Method for evaluating the kNN derivative at one point (not implemented)

Exceptions
std::logic_errorNot available for kNN

Implements sot::Surrogate.

int sot::kNN::dim ( ) const
inlinevirtual

Method for getting the number of dimensions.

Returns
Number of dimensions

Implements sot::Surrogate.

double sot::kNN::eval ( const vec point) const
inlinevirtual

Method for evaluating the surrogate model at a point.

Parameters
pointPoint for which to evaluate the surrogate
Returns
Value of the surrogate model at the point

Implements sot::Surrogate.

double sot::kNN::eval ( const vec point,
const vec dists 
) const
inlinevirtual

Method for evaluating the surrogate at multiple points.

Parameters
pointPoints for which to evaluate the surrogate model
distsDistances between the interpolation nodes and point
Returns
Values of the surrogate model at the points

Implements sot::Surrogate.

vec sot::kNN::evals ( const mat points) const
inlinevirtual

Method for evaluating the surrogate at multiple points.

Parameters
pointsPoints for which to evaluate the surrogate model
Returns
Values of the surrogate model at the points

Implements sot::Surrogate.

vec sot::kNN::evals ( const mat points,
const mat dists 
) const
inlinevirtual

Method for evaluating the surrogate at multiple points.

Parameters
pointsPoints for which to evaluate the surrogate model
distsDistances between the interpolation nodes and the points
Returns
Values of the surrogate model at the points

Implements sot::Surrogate.

vec sot::kNN::fX ( ) const
inlinevirtual

Method for getting the values of the current points.

Returns
Values of current points

Implements sot::Surrogate.

double sot::kNN::fX ( int  i) const
inlinevirtual

Method for getting the value of current point number i (0 is the first)

Returns
Value of point number i

Implements sot::Surrogate.

int sot::kNN::numPoints ( ) const
inlinevirtual

Method for getting the current number of points.

Returns
Current number of points

Implements sot::Surrogate.

mat sot::kNN::X ( ) const
inlinevirtual

Method for getting the current points.

Returns
Current points

Implements sot::Surrogate.

vec sot::kNN::X ( int  i) const
inlinevirtual

Method for getting current point number i (0 is the first)

Returns
Point number i

Implements sot::Surrogate.

Member Data Documentation

int sot::kNN::mDim
protected

Number of dimensions

vec sot::kNN::mfX
protected

Current point values

int sot::kNN::mk
protected

k (number of neighbors used in averaging)

int sot::kNN::mMaxPoints
protected

Capacity

int sot::kNN::mNumPoints
protected

Current number of points

mat sot::kNN::mX
protected

Current points


The documentation for this class was generated from the following file: