Package org.tribuo.impl
Class ListExample<T extends Output<T>>
java.lang.Object
org.tribuo.Example<T>
org.tribuo.impl.ListExample<T>
- Type Parameters:
T
- the type of the features in this example.
- All Implemented Interfaces:
Serializable
,Iterable<Feature>
,ProtoSerializable<org.tribuo.protos.core.ExampleProto>
This class will not be performant until value types are available in Java. Prefer
ArrayExample
.
An example that's a simple list of features. It is not guaranteed that feature instances are preserved.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Protobuf serialization version.Fields inherited from class org.tribuo.Example
DEFAULT_METADATA_SIZE, DEFAULT_WEIGHT, metadata, NAME, output, weight
Fields inherited from interface org.tribuo.protos.ProtoSerializable
DESERIALIZATION_METHOD_NAME, PROVENANCE_SERIALIZER
-
Constructor Summary
ConstructorDescriptionListExample
(Example<T> other) Copies the supplied example's features, weight, output and metadata into this example.ListExample
(T output) Constructs a ListExample for the specified output with a weight ofExample.DEFAULT_WEIGHT
.ListExample
(T output, float weight) Constructs a ListExample for the specified output and weight.ListExample
(T output, String[] featureNames, double[] featureValues) Constructs a ListExample from the specified output, feature names and feature values.ListExample
(T output, List<? extends Feature> features) Constructs a ListExample using the specified output and feature list. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a feature.void
addAll
(Collection<? extends Feature> features) Adds a collection of features.void
canonicalize
(FeatureMap featureMap) Reassigns feature name Strings in the Example to point to those in theFeatureMap
.void
clear()
Clears the features from this example.copy()
Returns a deep copy of this Example.protected void
Adds zero valued features for each feature name infeatureNames
.static ListExample<?>
deserializeFromProto
(int version, String className, com.google.protobuf.Any message) Deserialization factory.boolean
int
hashCode()
boolean
isDense
(FeatureMap fMap) Is this example dense wrt the supplied feature map.iterator()
Returns the Feature in this Example which has the supplied name, if it's present.void
reduceByName
(Merger merger) Merges features with the same name using the suppliedMerger
.void
removeFeatures
(List<Feature> featureList) Removes all features in this list from the Example.org.tribuo.protos.core.ExampleProto
Serializes this object to a protobuf.void
Overwrites the feature with the matching name.int
size()
Return how many features are in this example.protected void
sort()
Sorts the feature list to maintain the lexicographic order invariant.toString()
void
transform
(TransformerMap transformerMap) Transforms this example by applying the transformations from the suppliedTransformerMap
.boolean
Checks the example to see if all the feature names are unique, the feature values are not NaN, and there is at least one feature.Methods inherited from class org.tribuo.Example
containsMetadata, densify, deserialize, getMetadata, getMetadataValue, getOutput, getWeight, setMetadataValue, setWeight
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
CURRENT_VERSION
public static final int CURRENT_VERSIONProtobuf serialization version.- See Also:
-
-
Constructor Details
-
ListExample
Constructs a ListExample for the specified output and weight.- Parameters:
output
- The output.weight
- The example weight.
-
ListExample
Constructs a ListExample for the specified output with a weight ofExample.DEFAULT_WEIGHT
.- Parameters:
output
- The output.
-
ListExample
Copies the supplied example's features, weight, output and metadata into this example.- Parameters:
other
- The example to copy.
-
ListExample
Constructs a ListExample using the specified output and feature list.- Parameters:
output
- The output.features
- The features.
-
ListExample
Constructs a ListExample from the specified output, feature names and feature values.- Parameters:
output
- The output.featureNames
- The feature names.featureValues
- The feature values.
-
-
Method Details
-
deserializeFromProto
public static ListExample<?> 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
.
-
add
Description copied from class:Example
Adds a feature. This maintains the sorted invariant and has a lg(example.size()) cost per insertion. -
addAll
Description copied from class:Example
Adds a collection of features. This maintains the sorted invariant but is more efficient than adding one at a time due to allocation. -
clear
public void clear()Clears the features from this example. -
size
public int size()Description copied from class:Example
Return how many features are in this example. -
copy
Description copied from class:Example
Returns a deep copy of this Example. -
iterator
-
toString
-
sort
protected void sort()Sorts the feature list to maintain the lexicographic order invariant. -
removeFeatures
Description copied from class:Example
Removes all features in this list from the Example.- Specified by:
removeFeatures
in classExample<T extends Output<T>>
- Parameters:
featureList
- Features to remove from this Example.
-
reduceByName
Description copied from class:Example
Merges features with the same name using the suppliedMerger
.- Specified by:
reduceByName
in classExample<T extends Output<T>>
- Parameters:
merger
- A function to merge two doubles.
-
lookup
Description copied from class:Example
Returns the Feature in this Example which has the supplied name, if it's present. -
set
Description copied from class:Example
Overwrites the feature with the matching name.Throws
IllegalArgumentException
if there isn't a feature with that name in this example. -
validateExample
public boolean validateExample()Description copied from class:Example
Checks the example to see if all the feature names are unique, the feature values are not NaN, and there is at least one feature.- Specified by:
validateExample
in classExample<T extends Output<T>>
- Returns:
- true if the example is valid.
-
transform
Description copied from class:Example
Transforms this example by applying the transformations from the suppliedTransformerMap
.Can be overridden for performance reasons.
-
isDense
Description copied from class:Example
Is this example dense wrt the supplied feature map.An example is "dense" if it contains all the features in the map, and only those features.
-
densify
Adds zero valued features for each feature name infeatureNames
.featureNames
must be sorted lexicographically using theString
comparator, and behaviour is undefined otherwise. -
canonicalize
Description copied from class:Example
Reassigns feature name Strings in the Example to point to those in theFeatureMap
. This significantly reduces memory allocation. It is called when an Example is added to aMutableDataset
, and should not be called outside of that context as it may interact unexpectedly withHashedFeatureMap
.- Specified by:
canonicalize
in classExample<T extends Output<T>>
- Parameters:
featureMap
- The feature map containing canonical feature names.
-
equals
-
hashCode
public int hashCode() -
serialize
public org.tribuo.protos.core.ExampleProto serialize()Description copied from interface:ProtoSerializable
Serializes this object to a protobuf.- Specified by:
serialize
in interfaceProtoSerializable<T extends Output<T>>
- Returns:
- The protobuf.
-