Class ArrayExample<T extends Output<T>>
java.lang.Object
org.tribuo.Example<T>
org.tribuo.impl.ArrayExample<T>
- All Implemented Interfaces:
Serializable,Iterable<Feature>
- Direct Known Subclasses:
IndexedArrayExample
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault initial size of the backing arrays.protected String[]Feature names array.protected double[]Feature values array.protected intNumber of valid features in this example.Fields inherited from class org.tribuo.Example
DEFAULT_METADATA_SIZE, DEFAULT_WEIGHT, metadata, NAME, output, weight -
Constructor Summary
ConstructorsModifierConstructorDescriptionArrayExample(Example<T> other) Copy constructor.ArrayExample(T output) Constructs an example from an output.ArrayExample(T output, float weight) Constructs an example from an output and a weight.ArrayExample(T output, float weight, int initialSize) Constructs an example from an output and a weight, with an initial size for the feature arrays.ArrayExample(T output, float weight, Map<String, Object> metadata) Constructs an example from an output, a weight and the metadata.ArrayExample(T output, String[] names, double[] values) Constructs an example from an output, an array of names and an array of values.ArrayExample(T output, List<? extends Feature> features) Constructs an example from an output and a list of features.ArrayExample(T output, Map<String, Object> metadata) Constructs an example from an output and the metadata.<U extends Output<U>>ArrayExample(T output, Example<U> other, float weight) Clones an example's features, but uses the supplied output and weight. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a single feature.voidAdds 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.copy()Returns a deep copy of this Example.double[]copyValues(int newSize) Returns a copy of the feature values array at the specific size.voidConverts all implicit zeros into explicit zeros based on the supplied feature names.booleanprotected voidGrows the backing arrays by size+1.protected voidgrowArray(int minCapacity) Grows the backing arrays storing the names and values.inthashCode()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.protected intnewCapacity(int minCapacity) Returns a capacity at least as large as the given minimum capacity.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.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, 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
-
DEFAULT_SIZE
public static final int DEFAULT_SIZEDefault initial size of the backing arrays.- See Also:
-
featureNames
Feature names array. -
featureValues
protected double[] featureValuesFeature values array. -
size
protected int sizeNumber of valid features in this example.
-
-
Constructor Details
-
ArrayExample
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.
-
ArrayExample
-
ArrayExample
Constructs an example from an output and a weight.- Parameters:
output- The output.weight- The example weight.
-
ArrayExample
-
ArrayExample
Constructs an example from an output.- Parameters:
output- The output.
-
ArrayExample
-
ArrayExample
-
ArrayExample
-
ArrayExample
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
Adds a single feature.- Parameters:
name- The name of the feature.value- The value of the feature.
-
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. -
growArray
protected void growArray(int minCapacity) Grows the backing arrays storing the names and values.- Parameters:
minCapacity- The new minimum capacity required.
-
growArray
protected void growArray()Grows the backing arrays by size+1. -
newCapacity
protected int newCapacity(int minCapacity) 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
-
copyValues
public double[] copyValues(int newSize) Returns a copy of the feature values array at the specific size.- Parameters:
newSize- The new size.- Returns:
- A copy of the feature values.
-
size
-
removeFeatures
-
reduceByName
-
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.
-
copy
-
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. -
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
-
iterator
-
toString
-
equals
-
hashCode
-
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.
-