# nearest_neighbor.py¶

Surrogate model based on the N-Dimensional Interpolation library by Stephen Marone.

https://github.com/SMarone/NDInterp

class`openmdao.surrogate_models.nearest_neighbor.`

`NearestNeighbor`

(**kwargs)[source]Bases:

`openmdao.surrogate_models.surrogate_model.SurrogateModel`

Surrogate model that approximates values using a nearest neighbor approximation.

- Parameters

**kwargsdictOptions dictionary.

- Attributes

interpolantobjectInterpolator object

interpolant_init_argsdictInput keyword arguments for the interpolator.

`__init__`

(**kwargs)[source]Initialize all attributes.

- Parameters

**kwargsdictoptions dictionary.

`linearize`

(x,**kwargs)[source]Calculate the jacobian of the interpolant at the requested point.

- Parameters

xarray-likePoint at which the surrogate Jacobian is evaluated.

**kwargsdictAdditional keyword arguments passed to the interpolant.

- Returns

- ndarray
Jacobian of surrogate output wrt inputs.

`predict`

(x,**kwargs)[source]Calculate a predicted value of the response based on the current trained model.

- Parameters

xarray-likePoint(s) at which the surrogate is evaluated.

**kwargsdictAdditional keyword arguments passed to the interpolant.

- Returns

- float
Predicted value.

`train`

(x,y)[source]Train the surrogate model with the given set of inputs and outputs.

- Parameters

xarray-likeTraining input locations.

yarray-likeModel responses at given inputs.

`vectorized_predict`

(x)Calculate predicted values of the response based on the current trained model.

- Parameters

xarray-likeVectorized point(s) at which the surrogate is evaluated.