Package org.tribuo.hash
Class HashedFeatureMap
java.lang.Object
org.tribuo.FeatureMap
org.tribuo.ImmutableFeatureMap
org.tribuo.hash.HashedFeatureMap
- All Implemented Interfaces:
Serializable
,Iterable<VariableInfo>
A
FeatureMap
used by the HashingTrainer
to
provide feature name hashing and guarantee that the Model
does not contain feature name information, but still works
with unhashed features names.- See Also:
-
Field Summary
Fields inherited from class org.tribuo.ImmutableFeatureMap
idMap, size
Fields inherited from class org.tribuo.FeatureMap
m
-
Method Summary
Modifier and TypeMethodDescriptionstatic HashedFeatureMap
generateHashedFeatureMap
(FeatureMap map, Hasher hasher) Converts a standardFeatureMap
by hashing each entry using the supplied hash functionHasher
.Gets theVariableIDInfo
for this name.int
Gets the id number for this feature, returns -1 if it's unknown.void
The salt is not serialised with theModel
.Methods inherited from class org.tribuo.ImmutableFeatureMap
generateIDs, generateIDs, get, size
Methods inherited from class org.tribuo.FeatureMap
domainEquals, iterator, keySet, toReadableString, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
get
Description copied from class:ImmutableFeatureMap
Gets theVariableIDInfo
for this name. Returns null if it's unknown.- Overrides:
get
in classImmutableFeatureMap
- 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.- Overrides:
getID
in classImmutableFeatureMap
- Parameters:
name
- The name of the feature.- Returns:
- A non-negative integer if the feature is known, -1 otherwise.
-
setSalt
The salt is not serialised with theModel
. It must be set after deserialisation to the same value from training time.If the salt is invalid it will throw
IllegalArgumentException
.- Parameters:
salt
- The salt value. Must be the same as the one from training time.
-
generateHashedFeatureMap
Converts a standardFeatureMap
by hashing each entry using the supplied hash functionHasher
.This preserves the index ordering of the original feature names, which is important for making sure test time performance is good.
It guarantees any collisions will produce an feature id number lower than the previous feature's number, and so can be easily removed.
- Parameters:
map
- TheFeatureMap
to hash.hasher
- The hashing function.- Returns:
- A
HashedFeatureMap
.
-