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

    Nested classes/interfaces inherited from class com.linkedin.dagli.transformer.AbstractPreparedTransformer1

    com.linkedin.dagli.transformer.AbstractPreparedTransformer1.InternalAPI
  • 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.ScoredVector apply​(double[] array)  
    protected NearestDoubleArray clone()  
    protected boolean computeEqualsUnsafe​(NearestDoubleArray arg0)  
    protected int computeHashCode()  
    boolean equals​(java.lang.Object arg0)  
    protected com.linkedin.dagli.reducer.ClassReducerTable getClassReducerTable()  
    protected java.lang.String getDefaultName()  
    protected java.lang.String getDefaultShortName()  
    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.String getName()  
    protected java.lang.reflect.Type getResultSupertype()  
    java.lang.String getShortName()  
    protected boolean handleEquality​(NearestDoubleArray arg0)  
    protected int handleHashCode()  
    protected boolean hasAlwaysConstantResult()  
    boolean hasConstantResult()  
    int hashCode()  
    protected boolean hasName()  
    protected com.linkedin.dagli.dag.Graph<java.lang.Object> subgraph()  
    java.lang.String toString()  
    void validate()  
    protected NearestDoubleArray withAllInputs​(com.linkedin.dagli.producer.Producer<? extends double[]> arg0)  
    NearestDoubleArray withCandidates​(java.util.List<double[]> candidates)
    Sets the candidate vectors.
    protected NearestDoubleArray withInput1​(com.linkedin.dagli.producer.Producer<? extends double[]> arg0)  
    NearestDoubleArray withName​(java.lang.String arg0)  

    Methods inherited from class com.linkedin.dagli.transformer.AbstractPreparedTransformer1WithInput

    withInput

    Methods inherited from class com.linkedin.dagli.transformer.AbstractPreparedTransformer1

    createInternalAPI, internalAPI

    Methods inherited from class com.linkedin.dagli.util.cloneable.AbstractCloneable

    clone

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface com.linkedin.dagli.transformer.PreparedTransformer1

    applyAll

    Methods inherited from interface com.linkedin.dagli.producer.Producer

    getName, getShortName, hasConstantResult
  • Field Details

    • _input1

      protected com.linkedin.dagli.producer.Producer<? extends double[]> _input1
  • Constructor Details

  • Method Details

    • withCandidates

      public NearestDoubleArray withCandidates​(java.util.List<double[]> candidates)
      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 resultant ScoredVector.
      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:
      validate in interface com.linkedin.dagli.producer.Producer<com.linkedin.dagli.vector.ScoredVector>
      Overrides:
      validate in class com.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:
      getName in interface com.linkedin.dagli.util.named.Named
      Specified by:
      getName in interface com.linkedin.dagli.producer.Producer<R extends java.lang.Object>
    • getShortName

      public java.lang.String getShortName()
      Specified by:
      getShortName in interface com.linkedin.dagli.util.named.Named
      Specified by:
      getShortName in interface com.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

      public NearestDoubleArray withName​(java.lang.String arg0)
    • 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:
      hasConstantResult in interface com.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:
      hashCode in class java.lang.Object
    • equals

      public final boolean equals​(java.lang.Object arg0)
      Overrides:
      equals in class java.lang.Object
    • computeEqualsUnsafe

      protected boolean computeEqualsUnsafe​(NearestDoubleArray arg0)
    • computeHashCode

      protected int computeHashCode()
    • handleEquality

      protected boolean handleEquality​(NearestDoubleArray arg0)
    • handleHashCode

      protected int handleHashCode()
    • clone

      protected NearestDoubleArray clone()
      Overrides:
      clone in class com.linkedin.dagli.util.cloneable.AbstractCloneable<S extends com.linkedin.dagli.producer.AbstractProducer<R,​I,​S>>
    • getHandle

      protected final com.linkedin.dagli.handle.ProducerHandle<NearestDoubleArray> getHandle()
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
    • getResultSupertype

      protected java.lang.reflect.Type getResultSupertype()