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
TThe numeric type for calculations (e.g., float, double).
- Inheritance
-
RandomProjection<T>
- Implements
- 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
nComponentsint?Target dimensionality. If null, computed from eps.
epsdouble?Maximum distortion ratio. Used to compute nComponents if not specified. Defaults to 0.1.
projectionTypeRandomProjectionTypeType of random projection. Defaults to Gaussian.
densitydoubleDensity for sparse projection (proportion of non-zeros). Defaults to auto.
randomStateint?Random seed for reproducibility.
columnIndicesint[]The column indices to use, or null for all columns.
Properties
NComponents
Gets the number of components.
public int NComponents { get; }
Property Value
ProjectionMatrix
Gets the projection matrix.
public double[,]? ProjectionMatrix { get; }
Property Value
- double[,]
ProjectionType
Gets the projection type.
public RandomProjectionType ProjectionType { get; }
Property Value
SupportsInverseTransform
Gets whether this transformer supports inverse transformation.
public override bool SupportsInverseTransform { get; }
Property Value
Methods
FitCore(Matrix<T>)
Fits the random projection by generating the projection matrix.
protected override void FitCore(Matrix<T> data)
Parameters
dataMatrix<T>
GetFeatureNamesOut(string[]?)
Gets the output feature names after transformation.
public override string[] GetFeatureNamesOut(string[]? inputFeatureNames = null)
Parameters
inputFeatureNamesstring[]
Returns
- string[]
InverseTransformCore(Matrix<T>)
Inverse transformation is not supported.
protected override Matrix<T> InverseTransformCore(Matrix<T> data)
Parameters
dataMatrix<T>
Returns
- Matrix<T>
TransformCore(Matrix<T>)
Transforms data by projecting onto the random subspace.
protected override Matrix<T> TransformCore(Matrix<T> data)
Parameters
dataMatrix<T>
Returns
- Matrix<T>