public class BucketedRandomProjectionLSHModel extends Model<T> implements BucketedRandomProjectionLSHParams
BucketedRandomProjectionLSH
, where multiple random vectors are stored. The
vectors are normalized to be unit vectors and each vector is used in a hash function:
h_i(x) = floor(r_i.dot(x) / bucketLength)
where r_i
is the i-th random unit vector. The number of buckets will be (max L2 norm of input
vectors) / bucketLength
.
param: randMatrix A matrix with each row representing a hash function.
Modifier and Type | Method and Description |
---|---|
Dataset<?> |
approxNearestNeighbors(Dataset<?> dataset,
Vector key,
int numNearestNeighbors)
Overloaded method for approxNearestNeighbors.
|
Dataset<?> |
approxNearestNeighbors(Dataset<?> dataset,
Vector key,
int numNearestNeighbors,
String distCol)
Given a large dataset and an item, approximately find at most k items which have the closest
distance to the item.
|
Dataset<?> |
approxSimilarityJoin(Dataset<?> datasetA,
Dataset<?> datasetB,
double threshold)
Overloaded method for approxSimilarityJoin.
|
Dataset<?> |
approxSimilarityJoin(Dataset<?> datasetA,
Dataset<?> datasetB,
double threshold,
String distCol)
Join two datasets to approximately find all pairs of rows whose distance are smaller than
the threshold.
|
DoubleParam |
bucketLength()
The length of each hash bucket, a larger bucket lowers the false negative rate.
|
BucketedRandomProjectionLSHModel |
copy(ParamMap extra)
Creates a copy of this instance with the same UID and some extra params.
|
Param<String> |
inputCol()
Param for input column name.
|
static BucketedRandomProjectionLSHModel |
load(String path) |
IntParam |
numHashTables()
Param for the number of hash tables used in LSH OR-amplification.
|
Param<String> |
outputCol()
Param for output column name.
|
static MLReader<BucketedRandomProjectionLSHModel> |
read() |
BucketedRandomProjectionLSHModel |
setInputCol(String value) |
BucketedRandomProjectionLSHModel |
setOutputCol(String value) |
String |
toString() |
Dataset<Row> |
transform(Dataset<?> dataset)
Transforms the input dataset.
|
StructType |
transformSchema(StructType schema)
Check transform validity and derive the output schema from the input schema.
|
String |
uid()
An immutable unique ID for the object and its derivatives.
|
MLWriter |
write()
Returns an
MLWriter instance for this ML instance. |
transform, transform, transform
params
getBucketLength
clear, copyValues, defaultCopy, defaultParamMap, explainParam, explainParams, extractParamMap, extractParamMap, get, getDefault, getOrDefault, getParam, hasDefault, hasParam, isDefined, isSet, paramMap, params, set, set, set, setDefault, setDefault, shouldOwn
getNumHashTables, validateAndTransformSchema
getInputCol
getOutputCol
save
$init$, initializeForcefully, initializeLogIfNecessary, initializeLogIfNecessary, initializeLogIfNecessary$default$2, initLock, isTraceEnabled, log, logDebug, logDebug, logError, logError, logInfo, logInfo, logName, logTrace, logTrace, logWarning, logWarning, org$apache$spark$internal$Logging$$log__$eq, org$apache$spark$internal$Logging$$log_, uninitialize
public static MLReader<BucketedRandomProjectionLSHModel> read()
public static BucketedRandomProjectionLSHModel load(String path)
public DoubleParam bucketLength()
BucketedRandomProjectionLSHParams
(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
bucketLength
in interface BucketedRandomProjectionLSHParams
public String uid()
Identifiable
uid
in interface Identifiable
public BucketedRandomProjectionLSHModel setInputCol(String value)
public BucketedRandomProjectionLSHModel setOutputCol(String value)
public BucketedRandomProjectionLSHModel copy(ParamMap extra)
Params
defaultCopy()
.copy
in interface Params
copy
in class Model<BucketedRandomProjectionLSHModel>
extra
- (undocumented)public MLWriter write()
MLWritable
MLWriter
instance for this ML instance.write
in interface MLWritable
public String toString()
toString
in interface Identifiable
toString
in class Object
public Dataset<?> approxNearestNeighbors(Dataset<?> dataset, Vector key, int numNearestNeighbors, String distCol)
outputCol
is missing, the method will transform the data; if
the outputCol
exists, it will use the outputCol
. This allows caching of the
transformed data when necessary.
dataset
- The dataset to search for nearest neighbors of the key.key
- Feature vector representing the item to search for.numNearestNeighbors
- The maximum number of nearest neighbors.distCol
- Output column for storing the distance between each result row and the key.public Dataset<?> approxNearestNeighbors(Dataset<?> dataset, Vector key, int numNearestNeighbors)
dataset
- (undocumented)key
- (undocumented)numNearestNeighbors
- (undocumented)public Dataset<?> approxSimilarityJoin(Dataset<?> datasetA, Dataset<?> datasetB, double threshold, String distCol)
outputCol
is missing, the method will transform the data; if the
outputCol
exists, it will use the outputCol
. This allows caching of the transformed
data when necessary.
datasetA
- One of the datasets to join.datasetB
- Another dataset to join.threshold
- The threshold for the distance of row pairs.distCol
- Output column for storing the distance between each pair of rows.public Dataset<?> approxSimilarityJoin(Dataset<?> datasetA, Dataset<?> datasetB, double threshold)
datasetA
- (undocumented)datasetB
- (undocumented)threshold
- (undocumented)public final Param<String> inputCol()
HasInputCol
inputCol
in interface HasInputCol
public final IntParam numHashTables()
LSHParams
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.
numHashTables
in interface LSHParams
public final Param<String> outputCol()
HasOutputCol
outputCol
in interface HasOutputCol
public Dataset<Row> transform(Dataset<?> dataset)
Transformer
transform
in class Transformer
dataset
- (undocumented)public StructType transformSchema(StructType schema)
PipelineStage
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.
transformSchema
in class PipelineStage
schema
- (undocumented)