Class TransformerMap

java.lang.Object
org.tribuo.transform.TransformerMap
All Implemented Interfaces:
com.oracle.labs.mlrg.olcut.provenance.Provenancable<TransformerMap.TransformerMapProvenance>, Serializable, ProtoSerializable<org.tribuo.protos.core.TransformerMapProto>

public final class TransformerMap extends Object implements ProtoSerializable<org.tribuo.protos.core.TransformerMapProto>, com.oracle.labs.mlrg.olcut.provenance.Provenancable<TransformerMap.TransformerMapProvenance>, Serializable
A collection of Transformers which can be applied to a Dataset or Example. A TransformerMap is created by applying a TransformationMap to a Dataset. It contains Transformers which are specific to the Dataset which created it, for example the range of a feature used in binning is fixed to the value from that Dataset.

Transformations only operate on observed values. To operate on implicit zeros then first call MutableDataset.densify() on the datasets. See org.tribuo.transform for a more detailed discussion of densify.

See Also:
  • Field Details

    • CURRENT_VERSION

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

    • TransformerMap

      public TransformerMap(Map<String,List<Transformer>> map, DatasetProvenance datasetProvenance, com.oracle.labs.mlrg.olcut.provenance.ConfiguredObjectProvenance transformationMapProvenance)
      Constructs a transformer map which encapsulates a set of transformers that can be applied to features.
      Parameters:
      map - The transformers, one per transformed feature.
      datasetProvenance - The provenance of the dataset the transformers were fit against.
      transformationMapProvenance - The provenance of the transformation map that was fit.
  • Method Details

    • deserialize

      public static TransformerMap deserialize(org.tribuo.protos.core.TransformerMapProto proto)
      Deserializes a TransformerMapProto into a TransformerMap.
      Parameters:
      proto - The proto to deserialize.
      Returns:
      The deserialized TransformerMap.
    • applyTransformerList

      public static double applyTransformerList(double value, List<Transformer> transformerList)
      Applies a List of Transformers to the supplied double value, returning the transformed value.
      Parameters:
      value - The value to transform.
      transformerList - The transformers to apply.
      Returns:
      The transformed value.
    • transformExample

      public <T extends Output<T>> Example<T> transformExample(Example<T> example)
      Copies the supplied example and applies the transformers to it.
      Type Parameters:
      T - The type of Output.
      Parameters:
      example - The example to transform.
      Returns:
      A copy of the example with the transformers applied to it's features.
    • transformExample

      public <T extends Output<T>> Example<T> transformExample(Example<T> example, List<String> featureNames)
      Copies the supplied example and applies the transformers to it.
      Type Parameters:
      T - The type of Output.
      Parameters:
      example - The example to transform.
      featureNames - The feature names to densify.
      Returns:
      A copy of the example with the transformers applied to it's features.
    • transformDataset

      public <T extends Output<T>> MutableDataset<T> transformDataset(Dataset<T> dataset)
      Copies the supplied dataset and applies the transformers to each example in it.

      Does not densify the dataset first.

      Type Parameters:
      T - The type of Output.
      Parameters:
      dataset - The dataset to transform.
      Returns:
      A deep copy of the dataset (and it's examples) with the transformers applied to it's features.
    • transformDataset

      public <T extends Output<T>> MutableDataset<T> transformDataset(Dataset<T> dataset, boolean densify)
      Copies the supplied dataset and applies the transformers to each example in it.
      Type Parameters:
      T - The type of Output.
      Parameters:
      dataset - The dataset to transform.
      densify - Densify the dataset before transforming it.
      Returns:
      A deep copy of the dataset (and it's examples) with the transformers applied to it's features.
    • size

      public int size()
      Gets the size of the map.
      Returns:
      the size of the map of feature names to transformers.
    • get

      public List<Transformer> get(String featureName)
      Gets the transformers associated with a given feature name.
      Parameters:
      featureName - the name of the feature for which we want the transformer
      Returns:
      the transformer list associated with the feature name, which may be null if there is no feature with that name.
    • 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
    • entrySet

      public Set<Map.Entry<String,List<Transformer>>> entrySet()
      Get the feature names and associated list of transformers.
      Returns:
      The entry set of the transformer map.
    • getProvenance

      Specified by:
      getProvenance in interface com.oracle.labs.mlrg.olcut.provenance.Provenancable<TransformerMap.TransformerMapProvenance>
    • serialize

      public org.tribuo.protos.core.TransformerMapProto serialize()
      Description copied from interface: ProtoSerializable
      Serializes this object to a protobuf.
      Specified by:
      serialize in interface ProtoSerializable<org.tribuo.protos.core.TransformerMapProto>
      Returns:
      The protobuf.