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>
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
Fields inherited from class org.tribuo.Example
DEFAULT_METADATA_SIZE, DEFAULT_WEIGHT, metadata, NAME, output, weight
-
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
Converts all implicit zeros into explicit zeros based on the supplied feature names.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.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, 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
-
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
-
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
Description copied from class:Example
Converts all implicit zeros into explicit zeros based on the supplied feature names. -
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()
-