flurs.utils.projection

Utility classes for vector projection.

Classes

BaseProjection(k, p)

Base class for projection of feature vectors.

RandomMaclaurinProjection(k, p)

Random Maclaurin Projection.

RandomProjection(k, p[, density])

Projection based on a randomly initialized matrix.

Raw(k, p)

Raw projector that does nothing regardless of the parameters i.e., a projector is an identity matrix.

TensorSketchProjection(k, p)

Tensor Sketch Projection.

class flurs.utils.projection.BaseProjection(k, p)[source]

Base class for projection of feature vectors.

Parameters
  • k (int) – Number of reduced dimensions (i.e. rows of projection mat.).

  • p (int) – Number of input dimensions (i.e. cols of projection mat.). p will be increased in the future due to new user/item/context insersion.

insert_proj_col(offset)[source]

Insert a new column into a projection matrix.

Parameters

offset (int) – Column index of where the new dimension is inserted

reduce(Y)[source]

Apply projection to an input matrix.

Parameters

Y (numpy array, (p, n)) – Input p-by-n matrix projected to a k-by-n matrix.

Returns

A k-by-n projected matrix.

Return type

array

class flurs.utils.projection.RandomMaclaurinProjection(k, p)[source]

Random Maclaurin Projection.

Parameters
  • k (int) – Number of reduced dimensions (i.e. rows of projection mat.).

  • p (int) – Number of input dimensions (i.e. cols of projection mat.). p will be increased in the future due to new user/item/context insersion.

insert_proj_col(offset)[source]

Insert a new column into a projection matrix.

Parameters

offset (int) – Column index of where the new dimension is inserted

reduce(Y)[source]

Apply projection to an input matrix.

Parameters

Y (numpy array, (p, n)) – Input p-by-n matrix projected to a k-by-n matrix.

Returns

A k-by-n projected matrix.

Return type

array

class flurs.utils.projection.RandomProjection(k, p, density=0.2)[source]

Projection based on a randomly initialized matrix.

Parameters
  • k (int) – Number of reduced dimensions (i.e. rows of projection mat.).

  • p (int) – Number of input dimensions (i.e. cols of projection mat.). p will be increased in the future due to new user/item/context insersion.

  • density (float, default=0.2) – Density parameter used to create a projection matrix.

References

1

D. Achlioptas. Database-friendly random projections: Johnson-Lindenstrauss with binary coins.

2
  1. Li, et al. Very sparse random projections.

3

Scikit-learn documentation: Sparse random projection.

insert_proj_col(offset)[source]

Insert a new column into a projection matrix.

Parameters

offset (int) – Column index of where the new dimension is inserted

reduce(Y)[source]

Apply projection to an input matrix.

Parameters

Y (numpy array, (p, n)) – Input p-by-n matrix projected to a k-by-n matrix.

Returns

A k-by-n projected matrix.

Return type

array

class flurs.utils.projection.Raw(k, p)[source]

Raw projector that does nothing regardless of the parameters i.e., a projector is an identity matrix.

Parameters
  • k (int) – Number of reduced dimensions (i.e. rows of projection mat.).

  • p (int) – Number of input dimensions (i.e. cols of projection mat.). p will be increased in the future due to new user/item/context insersion.

insert_proj_col(offset)[source]

Insert a new column into a projection matrix.

Parameters

offset (int) – Column index of where the new dimension is inserted

reduce(Y)[source]

Apply projection to an input matrix.

Parameters

Y (numpy array, (p, n)) – Input p-by-n matrix projected to a k-by-n matrix.

Returns

A k-by-n projected matrix.

Return type

array

class flurs.utils.projection.TensorSketchProjection(k, p)[source]

Tensor Sketch Projection.

Parameters
  • k (int) – Number of reduced dimensions (i.e. rows of projection mat.).

  • p (int) – Number of input dimensions (i.e. cols of projection mat.). p will be increased in the future due to new user/item/context insersion.

insert_proj_col(offset)[source]

Insert a new column into a projection matrix.

Parameters

offset (int) – Column index of where the new dimension is inserted

reduce(Y)[source]

Apply projection to an input matrix.

Parameters

Y (numpy array, (p, n)) – Input p-by-n matrix projected to a k-by-n matrix.

Returns

A k-by-n projected matrix.

Return type

array