Class ListExample<T extends Output<T>>

java.lang.Object
org.tribuo.Example<T>
org.tribuo.impl.ListExample<T>
Type Parameters:
T - the type of the features in this example.
All Implemented Interfaces:
Serializable, Iterable<Feature>

public class ListExample<T extends Output<T>> extends Example<T> implements Serializable
This class will not be performant until value types are available in Java. Prefer ArrayExample.

An example that's a simple list of features. It is not guaranteed that feature instances are preserved.

See Also:
  • Constructor Details

    • ListExample

      public ListExample(T output, float weight)
      Constructs a ListExample for the specified output and weight.
      Parameters:
      output - The output.
      weight - The example weight.
    • ListExample

      public ListExample(T output)
      Constructs a ListExample for the specified output with a weight of Example.DEFAULT_WEIGHT.
      Parameters:
      output - The output.
    • ListExample

      public ListExample(Example<T> other)
      Copies the supplied example's features, weight, output and metadata into this example.
      Parameters:
      other - The example to copy.
    • ListExample

      public ListExample(T output, List<? extends Feature> features)
      Constructs a ListExample using the specified output and feature list.
      Parameters:
      output - The output.
      features - The features.
    • ListExample

      public ListExample(T output, String[] featureNames, double[] featureValues)
      Constructs a ListExample from the specified output, feature names and feature values.
      Parameters:
      output - The output.
      featureNames - The feature names.
      featureValues - The feature values.
  • Method Details

    • 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.
      Specified by:
      add in class Example<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.
      Specified by:
      addAll in class Example<T extends Output<T>>
      Parameters:
      features - The features to add.
    • clear

      public void clear()
      Clears the features from this example.
    • size

      public int size()
      Description copied from class: Example
      Return how many features are in this example.
      Specified by:
      size in class Example<T extends Output<T>>
      Returns:
      The number of features.
    • copy

      public ListExample<T> copy()
      Description copied from class: Example
      Returns a deep copy of this Example.
      Specified by:
      copy in class Example<T extends Output<T>>
      Returns:
      A deep copy of this example.
    • iterator

      public Iterator<Feature> iterator()
      Specified by:
      iterator in interface Iterable<T extends Output<T>>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • sort

      protected void sort()
      Sorts the feature list to maintain the lexicographic order invariant.
      Specified by:
      sort in class Example<T extends Output<T>>
    • removeFeatures

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

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

      public Feature lookup(String i)
      Description copied from class: Example
      Returns the Feature in this Example which has the supplied name, if it's present.
      Overrides:
      lookup in class Example<T extends Output<T>>
      Parameters:
      i - The feature name to lookup.
      Returns:
      The feature object.
    • set

      public void set(Feature feature)
      Description copied from class: Example
      Overwrites the feature with the matching name.

      Throws IllegalArgumentException if there isn't a feature with that name in this example.

      Specified by:
      set in class Example<T extends Output<T>>
      Parameters:
      feature - The new feature value.
    • validateExample

      public boolean validateExample()
      Description copied from class: Example
      Checks the example to see if all the feature names are unique, the feature values are not NaN, and there is at least one feature.
      Specified by:
      validateExample in class Example<T extends Output<T>>
      Returns:
      true if the example is valid.
    • transform

      public void transform(TransformerMap transformerMap)
      Description copied from class: Example
      Transforms this example by applying the transformations from the supplied TransformerMap.

      Can be overridden for performance reasons.

      Overrides:
      transform in class Example<T extends Output<T>>
      Parameters:
      transformerMap - The transformations to apply.
    • isDense

      public boolean isDense(FeatureMap fMap)
      Description copied from class: Example
      Is this example dense wrt the supplied feature map.

      An example is "dense" if it contains all the features in the map, and only those features.

      Specified by:
      isDense in class Example<T extends Output<T>>
      Parameters:
      fMap - The feature map to check against.
      Returns:
      True if this example contains only the features in the map, and all the features in the map.
    • densify

      protected void densify(List<String> featureList)
      Description copied from class: Example
      Converts all implicit zeros into explicit zeros based on the supplied feature names.
      Specified by:
      densify in class Example<T extends Output<T>>
      Parameters:
      featureList - A *sorted* list of feature names.
    • canonicalize

      public void canonicalize(FeatureMap featureMap)
      Description copied from class: Example
      Reassigns feature name Strings in the Example to point to those in the FeatureMap. This significantly reduces memory allocation. It is called when an Example is added to a MutableDataset, and should not be called outside of that context as it may interact unexpectedly with HashedFeatureMap.
      Specified by:
      canonicalize in class Example<T extends Output<T>>
      Parameters:
      featureMap - The feature map containing canonical feature names.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object