Table of Contents

Class RandomProjection<T>

Namespace
AiDotNet.Preprocessing.DimensionalityReduction
Assembly
AiDotNet.dll

Random Projection for dimensionality reduction.

public class RandomProjection<T> : TransformerBase<T, Matrix<T>, Matrix<T>>, IDataTransformer<T, Matrix<T>, Matrix<T>>

Type Parameters

T

The numeric type for calculations (e.g., float, double).

Inheritance
TransformerBase<T, Matrix<T>, Matrix<T>>
RandomProjection<T>
Implements
IDataTransformer<T, Matrix<T>, Matrix<T>>
Inherited Members

Remarks

Random projection reduces dimensionality by projecting data onto a random subspace. Despite its simplicity, it has strong theoretical guarantees via the Johnson-Lindenstrauss lemma: pairwise distances are approximately preserved with high probability.

Two projection types are supported: - Gaussian: Random matrix with entries from N(0, 1/k) - Sparse: Random matrix with mostly zeros (faster, memory efficient)

For Beginners: Random projection is surprisingly effective: - It's very fast (just matrix multiplication) - It preserves distances approximately (guaranteed by math!) - Great for preprocessing before other algorithms - Works well for very high-dimensional data

Use cases:

  • Speeding up distance-based algorithms (kNN, clustering)
  • Reducing memory for large datasets
  • Preprocessing before other dimensionality reduction

Constructors

RandomProjection(int?, double?, RandomProjectionType, double, int?, int[]?)

Creates a new instance of RandomProjection<T>.

public RandomProjection(int? nComponents = null, double? eps = 0.1, RandomProjectionType projectionType = RandomProjectionType.Gaussian, double density = 0, int? randomState = null, int[]? columnIndices = null)

Parameters

nComponents int?

Target dimensionality. If null, computed from eps.

eps double?

Maximum distortion ratio. Used to compute nComponents if not specified. Defaults to 0.1.

projectionType RandomProjectionType

Type of random projection. Defaults to Gaussian.

density double

Density for sparse projection (proportion of non-zeros). Defaults to auto.

randomState int?

Random seed for reproducibility.

columnIndices int[]

The column indices to use, or null for all columns.

Properties

NComponents

Gets the number of components.

public int NComponents { get; }

Property Value

int

ProjectionMatrix

Gets the projection matrix.

public double[,]? ProjectionMatrix { get; }

Property Value

double[,]

ProjectionType

Gets the projection type.

public RandomProjectionType ProjectionType { get; }

Property Value

RandomProjectionType

SupportsInverseTransform

Gets whether this transformer supports inverse transformation.

public override bool SupportsInverseTransform { get; }

Property Value

bool

Methods

FitCore(Matrix<T>)

Fits the random projection by generating the projection matrix.

protected override void FitCore(Matrix<T> data)

Parameters

data Matrix<T>

GetFeatureNamesOut(string[]?)

Gets the output feature names after transformation.

public override string[] GetFeatureNamesOut(string[]? inputFeatureNames = null)

Parameters

inputFeatureNames string[]

Returns

string[]

InverseTransformCore(Matrix<T>)

Inverse transformation is not supported.

protected override Matrix<T> InverseTransformCore(Matrix<T> data)

Parameters

data Matrix<T>

Returns

Matrix<T>

TransformCore(Matrix<T>)

Transforms data by projecting onto the random subspace.

protected override Matrix<T> TransformCore(Matrix<T> data)

Parameters

data Matrix<T>

Returns

Matrix<T>