Class BucketedRandomProjectionLSH

Object
org.apache.spark.ml.PipelineStage
org.apache.spark.ml.Estimator<T>
org.apache.spark.ml.feature.BucketedRandomProjectionLSH
All Implemented Interfaces:
Serializable, org.apache.spark.internal.Logging, BucketedRandomProjectionLSHParams, LSHParams, Params, HasInputCol, HasOutputCol, HasSeed, DefaultParamsWritable, Identifiable, MLWritable, scala.Serializable

public class BucketedRandomProjectionLSH extends Estimator<T> implements BucketedRandomProjectionLSHParams, HasSeed
This BucketedRandomProjectionLSH implements Locality Sensitive Hashing functions for Euclidean distance metrics.

The input is dense or sparse vectors, each of which represents a point in the Euclidean distance space. The output will be vectors of configurable dimension. Hash values in the same dimension are calculated by the same hash function.

References:

1. Wikipedia on Stable Distributions

2. Wang, Jingdong et al. "Hashing for similarity search: A survey." arXiv preprint arXiv:1408.2927 (2014).

See Also:
  • Constructor Details

    • BucketedRandomProjectionLSH

      public BucketedRandomProjectionLSH(String uid)
    • BucketedRandomProjectionLSH

      public BucketedRandomProjectionLSH()
  • Method Details

    • load

      public static BucketedRandomProjectionLSH load(String path)
    • read

      public static MLReader<T> read()
    • seed

      public final LongParam seed()
      Description copied from interface: HasSeed
      Param for random seed.
      Specified by:
      seed in interface HasSeed
      Returns:
      (undocumented)
    • bucketLength

      public DoubleParam bucketLength()
      Description copied from interface: BucketedRandomProjectionLSHParams
      The length of each hash bucket, a larger bucket lowers the false negative rate. The number of buckets will be (max L2 norm of input vectors) / bucketLength.

      If input vectors are normalized, 1-10 times of pow(numRecords, -1/inputDim) would be a reasonable value

      Specified by:
      bucketLength in interface BucketedRandomProjectionLSHParams
      Returns:
      (undocumented)
    • uid

      public String uid()
      Description copied from interface: Identifiable
      An immutable unique ID for the object and its derivatives.
      Specified by:
      uid in interface Identifiable
      Returns:
      (undocumented)
    • setInputCol

      public BucketedRandomProjectionLSH setInputCol(String value)
    • setOutputCol

      public BucketedRandomProjectionLSH setOutputCol(String value)
    • setNumHashTables

      public BucketedRandomProjectionLSH setNumHashTables(int value)
    • setBucketLength

      public BucketedRandomProjectionLSH setBucketLength(double value)
    • setSeed

      public BucketedRandomProjectionLSH setSeed(long value)
    • transformSchema

      public StructType transformSchema(StructType schema)
      Description copied from class: PipelineStage
      Check transform validity and derive the output schema from the input schema.

      We check validity for interactions between parameters during transformSchema and raise an exception if any parameter value is invalid. Parameter value checks which do not depend on other parameters are handled by Param.validate().

      Typical implementation should first conduct verification on schema change and parameter validity, including complex parameter interaction checks.

      Specified by:
      transformSchema in class PipelineStage
      Parameters:
      schema - (undocumented)
      Returns:
      (undocumented)
    • copy

      Description copied from interface: Params
      Creates a copy of this instance with the same UID and some extra params. Subclasses should implement this method and set the return type properly. See defaultCopy().
      Specified by:
      copy in interface Params
      Specified by:
      copy in class Estimator<BucketedRandomProjectionLSHModel>
      Parameters:
      extra - (undocumented)
      Returns:
      (undocumented)
    • fit

      public BucketedRandomProjectionLSHModel fit(Dataset<?> dataset)
      Description copied from class: Estimator
      Fits a model to the input data.
      Specified by:
      fit in class Estimator<T extends org.apache.spark.ml.feature.LSHModel<T>>
      Parameters:
      dataset - (undocumented)
      Returns:
      (undocumented)
    • inputCol

      public final Param<String> inputCol()
      Description copied from interface: HasInputCol
      Param for input column name.
      Specified by:
      inputCol in interface HasInputCol
      Returns:
      (undocumented)
    • numHashTables

      public final IntParam numHashTables()
      Description copied from interface: LSHParams
      Param for the number of hash tables used in LSH OR-amplification.

      LSH OR-amplification can be used to reduce the false negative rate. Higher values for this param lead to a reduced false negative rate, at the expense of added computational complexity.

      Specified by:
      numHashTables in interface LSHParams
      Returns:
      (undocumented)
    • outputCol

      public final Param<String> outputCol()
      Description copied from interface: HasOutputCol
      Param for output column name.
      Specified by:
      outputCol in interface HasOutputCol
      Returns:
      (undocumented)