Class BinaryFeaturesExample<T extends Output<T>>
java.lang.Object
org.tribuo.Example<T>
org.tribuo.impl.BinaryFeaturesExample<T>
- Type Parameters:
T
- The output type.
- All Implemented Interfaces:
Serializable
,Iterable<Feature>
An
Example
backed by a single array of feature names. This
implementation is modeled after ArrayExample
but does not store
feature values because it assumes only binary features - i.e., features with a
feature value of 1.0. The following methods throw an
UnsupportedOperationException
:
- See Also:
-
Field Summary
FieldsFields inherited from class org.tribuo.Example
DEFAULT_METADATA_SIZE, DEFAULT_WEIGHT, metadata, NAME, output, weight
-
Constructor Summary
ConstructorsModifierConstructorDescriptionBinaryFeaturesExample
(Example<T> other) Copy constructor.BinaryFeaturesExample
(T output) Constructs an example from an output.BinaryFeaturesExample
(T output, float weight) Constructs an example from an output and a weight.BinaryFeaturesExample
(T output, float weight, int initialSize) Constructs an example from an output and a weight, with an initial size for the feature arrays.BinaryFeaturesExample
(T output, float weight, Map<String, Object> metadata) Constructs an example from an output, a weight and the metadata.BinaryFeaturesExample
(T output, String[] names) Constructs an example from an output and an array of names.BinaryFeaturesExample
(T output, List<? extends Feature> features) Constructs an example from an output and a list of features.BinaryFeaturesExample
(T output, Map<String, Object> metadata) Constructs an example from an output and the metadata.<U extends Output<U>>
BinaryFeaturesExample
(T output, Example<U> other, float weight) Clones an example's features, but uses the supplied output and weight. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a single feature with a value of 1.void
Adds a feature to this example.void
addAll
(Collection<? extends Feature> features) Adds a collection of features to this example.void
canonicalize
(FeatureMap featureMap) Reassigns feature name Strings in the Example to point to those in theFeatureMap
.static void
checkIsBinary
(Feature feature) copy()
Returns a deep copy of this Example.void
Converts all implicit zeros into explicit zeros based on the supplied feature names.protected void
densify
(FeatureMap fMap) Converts all implicit zeros into explicit zeros based on the supplied feature map.boolean
protected void
Grows the backing arrays by size+1.protected void
growArray
(int minCapacity) Grows the backing arrays storing the names.int
hashCode()
static boolean
iterator()
Returns the Feature in this Example which has the supplied name, if it's present.protected int
newCapacity
(int minCapacity) Returns a capacity at least as large as the given minimum capacity.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, 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
-
DEFAULT_SIZE
- See Also:
-
featureNames
-
size
-
-
Constructor Details
-
BinaryFeaturesExample
Constructs an example from an output and a weight, with an initial size for the feature arrays.- Parameters:
output
- The output.weight
- The weight.initialSize
- The initial size of the feature arrays.
-
BinaryFeaturesExample
Constructs an example from an output, a weight and the metadata.- Parameters:
output
- The output.weight
- The weight.metadata
- The metadata.
-
BinaryFeaturesExample
Constructs an example from an output and a weight.- Parameters:
output
- The output.weight
- The example weight.
-
BinaryFeaturesExample
Constructs an example from an output and the metadata.- Parameters:
output
- The output.metadata
- The metadata.
-
BinaryFeaturesExample
Constructs an example from an output.- Parameters:
output
- The output.
-
BinaryFeaturesExample
Constructs an example from an output and an array of names. This is currently the most efficient constructor.- Parameters:
output
- The output.names
- The feature names.
-
BinaryFeaturesExample
Constructs an example from an output and a list of features. This constructor will throw anIllegalArgumentException
if any of the features have a feature value that does not equal 1.0.- Parameters:
output
- The output (e.g., label) of the examplefeatures
- The list of features.
-
BinaryFeaturesExample
Copy constructor. This constructor will throw anIllegalArgumentException
if any of the features have a feature value that does not equal 1.0.- Parameters:
other
- The example to copy.
-
BinaryFeaturesExample
Clones an example's features, but uses the supplied output and weight.- Type Parameters:
U
- The output type of the other example.- Parameters:
output
- The output to use.other
- The features to use.weight
- The weight to use.
-
-
Method Details
-
add
-
isBinary
-
checkIsBinary
-
add
-
addAll
Adds a collection of features to this example. This method will throw anIllegalArgumentException
if any of the features have a feature value that does not equal 1.0. -
growArray
Grows the backing arrays storing the names.- Parameters:
minCapacity
- The new minimum capacity required.
-
growArray
Grows the backing arrays by size+1. -
newCapacity
Returns a capacity at least as large as the given minimum capacity. Returns the current capacity increased by 50% if that suffices. Will not return a capacity greater than MAX_ARRAY_SIZE unless the given minimum capacity is greater than MAX_ARRAY_SIZE.- Parameters:
minCapacity
- the desired minimum capacity- Returns:
- The new capacity.
- Throws:
OutOfMemoryError
- if minCapacity is less than zero
-
sort
-
size
-
removeFeatures
-
validateExample
-
copy
-
lookup
-
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. -
transform
Description copied from class:Example
Transforms this example by applying the transformations from the suppliedTransformerMap
.Can be overridden for performance reasons.
-
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
- this parameter is ignored because we do not store feature values in this class. So, the 'merging' can be thought of as a logical AND.
-
densify
-
densify
-
iterator
-
toString
-
equals
-
hashCode
-
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.
-