Class ModHashCodeHasher

java.lang.Object
org.tribuo.hash.Hasher
org.tribuo.hash.ModHashCodeHasher
All Implemented Interfaces:
com.oracle.labs.mlrg.olcut.config.Configurable, com.oracle.labs.mlrg.olcut.provenance.Provenancable<com.oracle.labs.mlrg.olcut.provenance.ConfiguredObjectProvenance>, Serializable, ProtoSerializable<org.tribuo.protos.core.HasherProto>

public final class ModHashCodeHasher extends Hasher
Hashes names using String.hashCode(), then reduces the dimension.

ModHashCodeHasher does not serialize the salt in its serialized forms, and thus the salt must be set after deserialization.

See Also:
  • Field Details

    • CURRENT_VERSION

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

    • ModHashCodeHasher

      public ModHashCodeHasher(String salt)
      Constructs a ModHashCodeHasher with a fixed dimensionality of 100.
      Parameters:
      salt - The salt value.
    • ModHashCodeHasher

      public ModHashCodeHasher(int dimension, String salt)
      Constructs a ModHashCodeHasher with the supplied parameters.
      Parameters:
      dimension - The dimensionality.
      salt - The salt value.
  • Method Details

    • deserializeFromProto

      public static ModHashCodeHasher deserializeFromProto(int version, String className, com.google.protobuf.Any message) throws com.google.protobuf.InvalidProtocolBufferException
      Deserialization constructor.

      Note the salt must be set after the hasher has been deserialized.

      Parameters:
      version - The version number.
      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.
    • serialize

      public org.tribuo.protos.core.HasherProto serialize()
      Description copied from interface: ProtoSerializable
      Serializes this object to a protobuf.
      Returns:
      The protobuf.
    • postConfig

      public void postConfig() throws com.oracle.labs.mlrg.olcut.config.PropertyException
      Used by the OLCUT configuration system, and should not be called by external code.
      Throws:
      com.oracle.labs.mlrg.olcut.config.PropertyException
    • hash

      public String hash(String name)
      Description copied from class: Hasher
      Hashes the supplied input using the hashing function.

      If the salt is not set then this throws IllegalStateException.

      Specified by:
      hash in class Hasher
      Parameters:
      name - The input to hash.
      Returns:
      A String representation of the hashed output.
    • setSalt

      public void setSalt(String salt)
      Description copied from class: Hasher
      The salt is transient, it must be set **to the same value as it was trained with** after the Model is deserialized.
      Specified by:
      setSalt in class Hasher
      Parameters:
      salt - Salt value.
    • getProvenance

      public com.oracle.labs.mlrg.olcut.provenance.ConfiguredObjectProvenance getProvenance()
    • toString

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

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

      public int hashCode()
      Overrides:
      hashCode in class Object