Class IndexedArrayExample<T extends Output<T>>

java.lang.Object
org.tribuo.Example<T>
org.tribuo.impl.ArrayExample<T>
org.tribuo.impl.IndexedArrayExample<T>
All Implemented Interfaces:
Serializable, Iterable<Feature>, ProtoSerializable<org.tribuo.protos.core.ExampleProto>

public class IndexedArrayExample<T extends Output<T>> extends ArrayExample<T>
A version of ArrayExample which also has the id numbers.

Used in feature selection to provide log n lookups. May be used elsewhere in the future as a performance optimisation.

Note: output id caching is only valid with single dimensional Outputs like ClusterID, Event and Label. Other outputs may return -1 from getOutputID().

See Also:
  • Field Details

    • CURRENT_VERSION

      public static final int CURRENT_VERSION
      Protobuf serialization version.
      See Also:
    • featureIDs

      protected int[] featureIDs
      Feature id numbers from the internal featureMap.
    • outputID

      protected final int outputID
      Output id from the internal output map. Note this only works for single dimensional outputs, in multi-dimensional cases it is likely to be -1.
  • Constructor Details

    • IndexedArrayExample

      public IndexedArrayExample(IndexedArrayExample<T> other)
      Copy constructor.
      Parameters:
      other - The example to copy.
    • IndexedArrayExample

      public IndexedArrayExample(Example<T> other, ImmutableFeatureMap featureMap, ImmutableOutputInfo<T> outputMap)
      This constructor removes unknown features.
      Parameters:
      other - The example to copy from.
      featureMap - The feature map.
      outputMap - The output info.
  • Method Details

    • deserializeFromProto

      public static ArrayExample<?> deserializeFromProto(int version, String className, com.google.protobuf.Any message) throws com.google.protobuf.InvalidProtocolBufferException
      Deserialization factory.
      Parameters:
      version - The serialized object version.
      className - The class name.
      message - The serialized data.
      Returns:
      The deserialized object.
      Throws:
      com.google.protobuf.InvalidProtocolBufferException - If the protobuf could not be parsed from the message.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class ArrayExample<T extends Output<T>>
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class ArrayExample<T extends Output<T>>
    • growArray

      protected void growArray(int minCapacity)
      Description copied from class: ArrayExample
      Grows the backing arrays storing the names and values.
      Overrides:
      growArray in class ArrayExample<T extends Output<T>>
      Parameters:
      minCapacity - The new minimum capacity required.
    • add

      public void add(Feature feature)
      Description copied from class: Example
      Adds a feature. This maintains the sorted invariant and has a lg(example.size()) cost per insertion.
      Overrides:
      add in class ArrayExample<T extends Output<T>>
      Parameters:
      feature - The feature to add.
    • addAll

      public void addAll(Collection<? extends Feature> features)
      Description copied from class: Example
      Adds a collection of features. This maintains the sorted invariant but is more efficient than adding one at a time due to allocation.
      Overrides:
      addAll in class ArrayExample<T extends Output<T>>
      Parameters:
      features - The features to add.
    • sort

      protected void sort()
      Description copied from class: ArrayExample
      Sorts the feature list to maintain the lexicographic order invariant.
      Overrides:
      sort in class ArrayExample<T extends Output<T>>
    • reduceByName

      public void reduceByName(Merger merger)
      Description copied from class: Example
      Merges features with the same name using the supplied Merger.
      Overrides:
      reduceByName in class ArrayExample<T extends Output<T>>
      Parameters:
      merger - A function to merge two doubles.
    • removeFeatures

      public void removeFeatures(List<Feature> featureList)
      Description copied from class: Example
      Removes all features in this list from the Example.
      Overrides:
      removeFeatures in class ArrayExample<T extends Output<T>>
      Parameters:
      featureList - Features to remove from this Example.
    • contains

      public boolean contains(int i)
      Does this example contain a feature with id i.
      Parameters:
      i - The index to check.
      Returns:
      True if the example contains the id.
    • copy

      public IndexedArrayExample<T> copy()
      Description copied from class: Example
      Returns a deep copy of this Example.
      Overrides:
      copy in class ArrayExample<T extends Output<T>>
      Returns:
      A deep copy of this example.
    • densify

      public void densify(List<String> featureList)
      Unlike ArrayExample.densify(List) this method will throw IllegalArgumentException if one of the feature names is not present in this example's ImmutableFeatureMap.

      featureList must be sorted lexicographically using the String comparator, and behaviour is undefined otherwise.

      Overrides:
      densify in class ArrayExample<T extends Output<T>>
      Parameters:
      featureList - A *sorted* list of feature names.
    • getIdx

      public int getIdx(int i)
      Gets the feature at internal index i.
      Parameters:
      i - The internal index.
      Returns:
      The feature index.
    • getOutputID

      public int getOutputID()
      Gets the output id dimension number.
      Returns:
      The output id.
    • idIterator

      Iterator over the feature ids and values.
      Returns:
      The feature ids and values.
    • serialize

      public org.tribuo.protos.core.ExampleProto serialize()
      Description copied from interface: ProtoSerializable
      Serializes this object to a protobuf.
      Specified by:
      serialize in interface ProtoSerializable<T extends Output<T>>
      Overrides:
      serialize in class ArrayExample<T extends Output<T>>
      Returns:
      The protobuf.