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
FieldsModifier and TypeFieldDescriptionstatic final intProtobuf serialization version.Fields inherited from class org.tribuo.Example
DEFAULT_METADATA_SIZE, DEFAULT_WEIGHT, metadata, NAME, output, weightFields inherited from interface org.tribuo.protos.ProtoSerializable
DESERIALIZATION_METHOD_NAME, PROVENANCE_SERIALIZER -
Constructor Summary
ConstructorsConstructorDescriptionListExample(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 TypeMethodDescriptionvoidAdds a feature.voidaddAll(Collection<? extends Feature> features) Adds a collection of features.voidcanonicalize(FeatureMap featureMap) Reassigns feature name Strings in the Example to point to those in theFeatureMap.voidclear()Clears the features from this example.copy()Returns a deep copy of this Example.protected voidAdds zero valued features for each feature name infeatureNames.static ListExample<?> deserializeFromProto(int version, String className, com.google.protobuf.Any message) Deserialization factory.booleaninthashCode()booleanisDense(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.voidreduceByName(Merger merger) Merges features with the same name using the suppliedMerger.voidremoveFeatures(List<Feature> featureList) Removes all features in this list from the Example.org.tribuo.protos.core.ExampleProtoSerializes this object to a protobuf.voidOverwrites the feature with the matching name.intsize()Return how many features are in this example.protected voidsort()Sorts the feature list to maintain the lexicographic order invariant.toString()voidtransform(TransformerMap transformerMap) Transforms this example by applying the transformations from the suppliedTransformerMap.booleanChecks 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, setWeightMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods 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
-
ListExample
-
ListExample
-
-
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
-
addAll
Description copied from class:ExampleAdds 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
-
copy
-
iterator
-
toString
-
sort
-
removeFeatures
-
reduceByName
-
lookup
-
set
Description copied from class:ExampleOverwrites the feature with the matching name.Throws
IllegalArgumentExceptionif there isn't a feature with that name in this example. -
validateExample
public boolean validateExample()Description copied from class:ExampleChecks 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:
validateExamplein classExample<T extends Output<T>>- Returns:
- true if the example is valid.
-
transform
Description copied from class:ExampleTransforms this example by applying the transformations from the suppliedTransformerMap.Can be overridden for performance reasons.
-
isDense
Description copied from class:ExampleIs 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.featureNamesmust be sorted lexicographically using theStringcomparator, and behaviour is undefined otherwise. -
canonicalize
Description copied from class:ExampleReassigns 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:
canonicalizein classExample<T extends Output<T>>- Parameters:
featureMap- The feature map containing canonical feature names.
-
equals
-
hashCode
-
serialize
public org.tribuo.protos.core.ExampleProto serialize()Description copied from interface:ProtoSerializableSerializes this object to a protobuf.- Specified by:
serializein interfaceProtoSerializable<T extends Output<T>>- Returns:
- The protobuf.
-