Package org.tribuo.transform
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
Transformer
s 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:
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Protobuf serialization version.Fields inherited from interface org.tribuo.protos.ProtoSerializable
DESERIALIZATION_METHOD_NAME, PROVENANCE_SERIALIZER
-
Constructor Summary
ConstructorDescriptionTransformerMap
(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. -
Method Summary
Modifier and TypeMethodDescriptionstatic double
applyTransformerList
(double value, List<Transformer> transformerList) Applies aList
ofTransformer
s to the supplied double value, returning the transformed value.static TransformerMap
deserialize
(org.tribuo.protos.core.TransformerMapProto proto) Deserializes aTransformerMapProto
into aTransformerMap
.entrySet()
Get the feature names and associated list of transformers.boolean
Gets the transformers associated with a given feature name.int
hashCode()
org.tribuo.protos.core.TransformerMapProto
Serializes this object to a protobuf.int
size()
Gets the size of the map.toString()
<T extends Output<T>>
MutableDataset<T>transformDataset
(Dataset<T> dataset) Copies the supplied dataset and applies the transformers to each example in it.<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.transformExample
(Example<T> example) Copies the supplied example and applies the transformers to it.transformExample
(Example<T> example, List<String> featureNames) Copies the supplied example and applies the transformers to it.
-
Field Details
-
CURRENT_VERSION
public static final int CURRENT_VERSIONProtobuf 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
Deserializes aTransformerMapProto
into aTransformerMap
.- Parameters:
proto
- The proto to deserialize.- Returns:
- The deserialized TransformerMap.
-
applyTransformerList
Applies aList
ofTransformer
s 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
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
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
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
-
equals
-
hashCode
public int hashCode() -
entrySet
Get the feature names and associated list of transformers.- Returns:
- The entry set of the transformer map.
-
getProvenance
- Specified by:
getProvenance
in interfacecom.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 interfaceProtoSerializable<org.tribuo.protos.core.TransformerMapProto>
- Returns:
- The protobuf.
-