Class ImmutableFeatureMap
java.lang.Object
org.tribuo.FeatureMap
org.tribuo.ImmutableFeatureMap
- All Implemented Interfaces:
Serializable,Iterable<VariableInfo>,ProtoSerializable<org.tribuo.protos.core.FeatureDomainProto>
- Direct Known Subclasses:
HashedFeatureMap
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final intProtobuf serialization version.protected final Map<Integer, VariableIDInfo> The map from id numbers to the feature infos.protected intThe number of features.Fields inherited from class org.tribuo.FeatureMap
mFields inherited from interface org.tribuo.protos.ProtoSerializable
DESERIALIZATION_METHOD_NAME, PROVENANCE_SERIALIZER -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructs a new empty immutable feature map.ImmutableFeatureMap(List<VariableInfo> infoList) Constructs a new immutable feature map copying the supplied variable infos and generating appropriate ID numbers.Constructs a new immutable version which is a deep copy of the supplied feature map, generating new ID numbers. -
Method Summary
Modifier and TypeMethodDescriptionstatic ImmutableFeatureMapdeserializeFromProto(int version, String className, com.google.protobuf.Any message) Deserialization factory.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.static Map<String, VariableIDInfo> generateIDs(FeatureMap map) Generates the feature ids by sorting the features with the String comparator, then sequentially numbering them.get(int id) Gets theVariableIDInfofor this id number.Gets theVariableIDInfofor this name.intGets the id number for this feature, returns -1 if it's unknown.org.tribuo.protos.core.FeatureDomainProtoSerializes this object to a protobuf.intsize()Returns the number of features in the domain.Methods inherited from class org.tribuo.FeatureMap
deserialize, domainEquals, equals, hashCode, iterator, keySet, toReadableString, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
CURRENT_VERSION
public static final int CURRENT_VERSIONProtobuf serialization version.- See Also:
-
idMap
The map from id numbers to the feature infos. -
size
protected int sizeThe number of features.
-
-
Constructor Details
-
ImmutableFeatureMap
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
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
-
deserializeFromProto
public static ImmutableFeatureMap 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 themessage.
-
serialize
public org.tribuo.protos.core.FeatureDomainProto serialize()Description copied from interface:ProtoSerializableSerializes this object to a protobuf.- Specified by:
serializein interfaceProtoSerializable<org.tribuo.protos.core.FeatureDomainProto>- Returns:
- The protobuf.
-
get
Gets theVariableIDInfofor this id number. Returns null if it's unknown.- Parameters:
id- The id number to lookup.- Returns:
- The VariableInfo, or null.
-
get
Gets theVariableIDInfofor this name. Returns null if it's unknown.- Overrides:
getin classFeatureMap- Parameters:
name- The name to lookup.- Returns:
- The VariableInfo, or null.
-
getID
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:FeatureMapReturns the number of features in the domain.- Overrides:
sizein classFeatureMap- Returns:
- The number of features.
-
generateIDs
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
Generates the feature ids by sorting the features with the String comparator, then sequentially numbering them.- Parameters:
list- A list ofVariableInfos to generate a map from.- Returns:
- A map from feature names to VariableIDInfo objects.
-