skdim.id.KNN

class skdim.id.KNN(k=None, ps=None, M=1, gamma=2)[source]

Intrinsic dimension estimation using the kNN algorithm. [Carter2010] [IDJohnsson]

This is a simplified version of the kNN dimension estimation method described by Carter et al. (2010), the difference being that block bootstrapping is not used.

Parameters:
X : 2D numeric array

A 2D data set with each row describing a data point.

k : int

Number of distances to neighbors used at a time.

ps : 1D numeric array

Vector with sample sizes; each sample size has to be larger than k and smaller than nrow(data).

M : int, default=1

Number of bootstrap samples for each sample size.

gamma : int, default=2

Weighting constant.

Methods

fit(X[, y]) A reference implementation of a fitting function.
fit_pw(X[, precomputed_knn, smooth, …]) Creates an array of pointwise ID estimates (self.dimension_pw_) by fitting the estimator in kNN of each point.
fit_transform(X[, y]) Fit estimator and return ID
fit_transform_pw(X[, precomputed_knn, …]) Returns an array of pointwise ID estimates by fitting the estimator in kNN of each point.
get_params([deep]) Get parameters for this estimator.
set_params(**params) Set the parameters of this estimator.
transform([X]) Predict dimension after a previous call to self.fit
transform_pw([X]) Return an array of pointwise ID estimates after a previous call to self.fit_pw
fit(X, y=None)[source]

A reference implementation of a fitting function. :param X: The training input samples. :type X: {array-like}, shape (n_samples, n_features) :param y: :type y: dummy parameter to respect the sklearn API

Returns:
  • self (object) – Returns self.
  • self.dimension_ (float) – The estimated intrinsic dimension
  • self.residual_ (float) – Residuals
fit_pw(X, precomputed_knn=None, smooth=False, n_neighbors=100, n_jobs=1)

Creates an array of pointwise ID estimates (self.dimension_pw_) by fitting the estimator in kNN of each point.

Parameters:
X : np.array (n_samples x n_neighbors)

Dataset to fit

precomputed_knn : np.array (n_samples x n_dims)

An array of precomputed (sorted) nearest neighbor indices

n_neighbors

Number of nearest neighbors to use (ignored when using precomputed_knn)

n_jobs : int

Number of processes

smooth : bool, default = False

Additionally computes a smoothed version of pointwise estimates by

taking the ID of a point as the average ID of each point in its neighborhood (self.dimension_pw_)

smooth_

Returns:

self (object) – Returns self

fit_transform(X, y=None)

Fit estimator and return ID

Parameters:
X : {array-like}, shape (n_samples, n_features)

The training input samples.

Returns:

dimension_ ({int, float}) – The estimated intrinsic dimension

fit_transform_pw(X, precomputed_knn=None, smooth=False, n_neighbors=100, n_jobs=1)

Returns an array of pointwise ID estimates by fitting the estimator in kNN of each point.

Parameters:
X : np.array (n_samples x n_neighbors)

Dataset to fit

precomputed_knn : bool

An array of precomputed (sorted) nearest neighbor indices

n_neighbors

Number of nearest neighbors to use (ignored when using precomputed_knn)

n_jobs : int

Number of processes

smooth : bool, default = False

Additionally computes a smoothed version of pointwise estimates by

taking the ID of a point as the average ID of each point in its neighborhood (self.dimension_pw_)

smooth_

Returns:

  • dimension_pw_ (np.array with dtype {int, float}) – Pointwise ID estimates
  • dimension_pw_smooth_ (np.array with dtype float) – Smoothed pointwise ID estimates returned if self.fit_pw(smooth=True)

get_params(deep=True)

Get parameters for this estimator.

Parameters:
deep : bool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params (dict) – Parameter names mapped to their values.

set_params(**params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:
**params : dict

Estimator parameters.

Returns:

self (estimator instance) – Estimator instance.

transform(X=None)

Predict dimension after a previous call to self.fit

Parameters:
X : Dummy parameter

Returns:

dimension_ ({int, float}) – The estimated ID

transform_pw(X=None)

Return an array of pointwise ID estimates after a previous call to self.fit_pw

Parameters:
X : Dummy parameter

Returns:

  • dimension_pw_ (np.array with dtype {int, float}) – Pointwise ID estimates
  • dimension_pw_smooth_ (np.array with dtype float) – Smoothed pointwise ID estimates returned if self.fit_pw(smooth=True)