Package com.linkedin.dagli.clustering
Class NearestDoubleArray
java.lang.Object
com.linkedin.dagli.util.cloneable.AbstractCloneable<S>
com.linkedin.dagli.producer.AbstractChildProducer<R,I,S>
com.linkedin.dagli.transformer.AbstractPreparedTransformer1<A,R,S>
com.linkedin.dagli.transformer.AbstractPreparedTransformer1WithInput<double[],com.linkedin.dagli.vector.ScoredVector,NearestDoubleArray>
com.linkedin.dagli.clustering.NearestDoubleArray
- All Implemented Interfaces:
com.linkedin.dagli.producer.ChildProducer<com.linkedin.dagli.vector.ScoredVector>,com.linkedin.dagli.producer.Producer<com.linkedin.dagli.vector.ScoredVector>,com.linkedin.dagli.producer.ProducerType<com.linkedin.dagli.vector.ScoredVector,com.linkedin.dagli.transformer.PreparedTransformer<com.linkedin.dagli.vector.ScoredVector>>,com.linkedin.dagli.transformer.PreparedTransformer<com.linkedin.dagli.vector.ScoredVector>,com.linkedin.dagli.transformer.PreparedTransformer1<double[],com.linkedin.dagli.vector.ScoredVector>,com.linkedin.dagli.transformer.Transformer<com.linkedin.dagli.vector.ScoredVector>,com.linkedin.dagli.transformer.Transformer1<double[],com.linkedin.dagli.vector.ScoredVector>,com.linkedin.dagli.transformer.TransformerWithInputBound<double[],com.linkedin.dagli.vector.ScoredVector>,com.linkedin.dagli.util.named.Named,java.io.Serializable,java.lang.Cloneable
@ValueEquality public class NearestDoubleArray extends com.linkedin.dagli.transformer.AbstractPreparedTransformer1WithInput<double[],com.linkedin.dagli.vector.ScoredVector,NearestDoubleArray>
NearestDoubleArray finds the array that is "closest" (as determined by Euclidean distance) to an input array
from a pre-determined list of candidates. It then returns a structure containing the closest array's index,
distance (the "score"--here, lower is better), and the closest array itself (as a DenseDoubleArrayVector
One use of this class is as the "prediction" transformer for KMeans clustering algorithms.- See Also:
- Serialized Form
-
Nested Class Summary
-
Field Summary
Fields Modifier and Type Field Description protected com.linkedin.dagli.producer.Producer<? extends double[]>_input1 -
Constructor Summary
Constructors Constructor Description NearestDoubleArray() -
Method Summary
Modifier and Type Method Description com.linkedin.dagli.vector.ScoredVectorapply(double[] array)protected NearestDoubleArrayclone()protected booleancomputeEqualsUnsafe(NearestDoubleArray arg0)protected intcomputeHashCode()booleanequals(java.lang.Object arg0)protected com.linkedin.dagli.reducer.ClassReducerTablegetClassReducerTable()protected java.lang.StringgetDefaultName()protected java.lang.StringgetDefaultShortName()protected java.util.Collection<? extends com.linkedin.dagli.reducer.Reducer<? super NearestDoubleArray>>getGraphReducers()protected com.linkedin.dagli.handle.ProducerHandle<NearestDoubleArray>getHandle()protected com.linkedin.dagli.producer.Producer<? extends double[]>getInput1()protected java.util.List<com.linkedin.dagli.producer.Producer<?>>getInputList()java.lang.StringgetName()protected java.lang.reflect.TypegetResultSupertype()java.lang.StringgetShortName()protected booleanhandleEquality(NearestDoubleArray arg0)protected inthandleHashCode()protected booleanhasAlwaysConstantResult()booleanhasConstantResult()inthashCode()protected booleanhasName()protected com.linkedin.dagli.dag.Graph<java.lang.Object>subgraph()java.lang.StringtoString()voidvalidate()protected NearestDoubleArraywithAllInputs(com.linkedin.dagli.producer.Producer<? extends double[]> arg0)NearestDoubleArraywithCandidates(java.util.List<double[]> candidates)Sets the candidate vectors.protected NearestDoubleArraywithInput1(com.linkedin.dagli.producer.Producer<? extends double[]> arg0)NearestDoubleArraywithName(java.lang.String arg0)Methods inherited from class com.linkedin.dagli.transformer.AbstractPreparedTransformer1WithInput
withInputMethods inherited from class com.linkedin.dagli.transformer.AbstractPreparedTransformer1
createInternalAPI, internalAPI
-
Field Details
-
_input1
protected com.linkedin.dagli.producer.Producer<? extends double[]> _input1
-
-
Constructor Details
-
NearestDoubleArray
public NearestDoubleArray()
-
-
Method Details
-
withCandidates
Sets the candidate vectors. Inputs to this transformer will be checked against these candidates to determine which candidate is the closest, and at which distance, in order to calculate the resultantScoredVector.- Parameters:
candidates- the array of candidates to use- Returns:
- a copy of this instance that will use the provided candidates
-
apply
public com.linkedin.dagli.vector.ScoredVector apply(double[] array) -
validate
public void validate()- Specified by:
validatein interfacecom.linkedin.dagli.producer.Producer<com.linkedin.dagli.vector.ScoredVector>- Overrides:
validatein classcom.linkedin.dagli.producer.AbstractChildProducer<com.linkedin.dagli.vector.ScoredVector,com.linkedin.dagli.transformer.internal.PreparedTransformer1InternalAPI<double[],com.linkedin.dagli.vector.ScoredVector,NearestDoubleArray>,NearestDoubleArray>
-
getInputList
protected java.util.List<com.linkedin.dagli.producer.Producer<?>> getInputList() -
getInput1
protected com.linkedin.dagli.producer.Producer<? extends double[]> getInput1() -
withAllInputs
protected NearestDoubleArray withAllInputs(com.linkedin.dagli.producer.Producer<? extends double[]> arg0) -
withInput1
protected NearestDoubleArray withInput1(com.linkedin.dagli.producer.Producer<? extends double[]> arg0) -
getName
public java.lang.String getName()- Specified by:
getNamein interfacecom.linkedin.dagli.util.named.Named- Specified by:
getNamein interfacecom.linkedin.dagli.producer.Producer<R extends java.lang.Object>
-
getShortName
public java.lang.String getShortName()- Specified by:
getShortNamein interfacecom.linkedin.dagli.util.named.Named- Specified by:
getShortNamein interfacecom.linkedin.dagli.producer.Producer<R extends java.lang.Object>
-
hasName
protected boolean hasName() -
getDefaultName
protected java.lang.String getDefaultName() -
getDefaultShortName
protected java.lang.String getDefaultShortName() -
withName
-
getGraphReducers
protected java.util.Collection<? extends com.linkedin.dagli.reducer.Reducer<? super NearestDoubleArray>> getGraphReducers() -
getClassReducerTable
protected com.linkedin.dagli.reducer.ClassReducerTable getClassReducerTable() -
hasAlwaysConstantResult
protected boolean hasAlwaysConstantResult() -
hasConstantResult
public final boolean hasConstantResult()- Specified by:
hasConstantResultin interfacecom.linkedin.dagli.producer.Producer<R extends java.lang.Object>
-
subgraph
protected com.linkedin.dagli.dag.Graph<java.lang.Object> subgraph() -
hashCode
public final int hashCode()- Overrides:
hashCodein classjava.lang.Object
-
equals
public final boolean equals(java.lang.Object arg0)- Overrides:
equalsin classjava.lang.Object
-
computeEqualsUnsafe
-
computeHashCode
protected int computeHashCode() -
handleEquality
-
handleHashCode
protected int handleHashCode() -
clone
- Overrides:
clonein classcom.linkedin.dagli.util.cloneable.AbstractCloneable<S extends com.linkedin.dagli.producer.AbstractProducer<R,I,S>>
-
getHandle
-
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-
getResultSupertype
protected java.lang.reflect.Type getResultSupertype()
-