Package org.tribuo

Class ImmutableFeatureMap

java.lang.Object
org.tribuo.FeatureMap
org.tribuo.ImmutableFeatureMap
All Implemented Interfaces:
Serializable, Iterable<VariableInfo>
Direct Known Subclasses:
HashedFeatureMap

public class ImmutableFeatureMap extends FeatureMap implements Serializable
ImmutableFeatureMap is used when unknown features should not be added to the FeatureMap.

It's also got feature ids as those are only generated for immutable maps.

The feature ids are generated by sorting the feature names by the String comparator. This ensures that any Example with sorted names has sorted int ids, even if some of those features are unobserved. This is an extremely important property of Features, Examples and ImmutableFeatureMap.

See Also:
  • Field Details

    • idMap

      protected final Map<Integer,VariableIDInfo> idMap
      The map from id numbers to the feature infos.
    • size

      protected int size
      The number of features.
  • Constructor Details

    • ImmutableFeatureMap

      public ImmutableFeatureMap(FeatureMap map)
      Constructs a new immutable version which is a deep copy of the supplied feature map, generating new ID numbers.

      The new id numbers will be the same as the old ones (if they existed) assuming this is a regular feature map.

      Parameters:
      map - The map to copy.
    • ImmutableFeatureMap

      public ImmutableFeatureMap(List<VariableInfo> infoList)
      Constructs a new immutable feature map copying the supplied variable infos and generating appropriate ID numbers.
      Parameters:
      infoList - The variable infos.
    • ImmutableFeatureMap

      protected ImmutableFeatureMap()
      Constructs a new empty immutable feature map.

      Used for mocking feature domains in tests.

  • Method Details

    • get

      public VariableIDInfo get(int id)
      Gets the VariableIDInfo for this id number. Returns null if it's unknown.
      Parameters:
      id - The id number to lookup.
      Returns:
      The VariableInfo, or null.
    • get

      public VariableIDInfo get(String name)
      Gets the VariableIDInfo for this name. Returns null if it's unknown.
      Overrides:
      get in class FeatureMap
      Parameters:
      name - The name to lookup.
      Returns:
      The VariableInfo, or null.
    • getID

      public int getID(String name)
      Gets the id number for this feature, returns -1 if it's unknown.
      Parameters:
      name - The name of the feature.
      Returns:
      A non-negative integer if the feature is known, -1 otherwise.
    • size

      public int size()
      Description copied from class: FeatureMap
      Returns the number of features in the domain.
      Overrides:
      size in class FeatureMap
      Returns:
      The number of features.
    • generateIDs

      public static Map<String,VariableIDInfo> generateIDs(FeatureMap map)
      Generates the feature ids by sorting the features with the String comparator, then sequentially numbering them.
      Parameters:
      map - A feature map to convert.
      Returns:
      A map from feature names to VariableIDInfo objects.
    • generateIDs

      public static Map<String,VariableIDInfo> generateIDs(List<? extends VariableInfo> list)
      Generates the feature ids by sorting the features with the String comparator, then sequentially numbering them.
      Parameters:
      list - A list of VariableInfos to generate a map from.
      Returns:
      A map from feature names to VariableIDInfo objects.