Class IndexedArrayExample<T extends Output<T>>
java.lang.Object
org.tribuo.Example<T>
org.tribuo.impl.ArrayExample<T>
org.tribuo.impl.IndexedArrayExample<T>
- All Implemented Interfaces:
Serializable,Iterable<Feature>,ProtoSerializable<org.tribuo.protos.core.ExampleProto>
A version of ArrayExample which also has the id numbers.
Used in feature selection to provide log n lookups. May be used elsewhere in the future as a performance optimisation.
Note: output id caching is only valid with single dimensional Outputs like ClusterID, Event and Label.
Other outputs may return -1 from getOutputID().
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA tuple of the feature name, id and value. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intProtobuf serialization version.protected int[]Feature id numbers from the internal featureMap.protected final intOutput id from the internal output map.Fields inherited from class org.tribuo.impl.ArrayExample
DEFAULT_SIZE, featureNames, featureValues, sizeFields 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
ConstructorsConstructorDescriptionIndexedArrayExample(Example<T> other, ImmutableFeatureMap featureMap, ImmutableOutputInfo<T> outputMap) This constructor removes unknown features.IndexedArrayExample(IndexedArrayExample<T> other) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a feature.voidaddAll(Collection<? extends Feature> features) Adds a collection of features.booleancontains(int i) Does this example contain a feature with id i.copy()Returns a deep copy of this Example.voidUnlikeArrayExample.densify(List)this method will throwIllegalArgumentExceptionif one of the feature names is not present in this example'sImmutableFeatureMap.static ArrayExample<?> deserializeFromProto(int version, String className, com.google.protobuf.Any message) Deserialization factory.booleanintgetIdx(int i) Gets the feature at internal index i.intGets the output id dimension number.protected voidgrowArray(int minCapacity) Grows the backing arrays storing the names and values.inthashCode()Iterator over the feature ids and values.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.protected voidsort()Sorts the feature list to maintain the lexicographic order invariant.Methods inherited from class org.tribuo.impl.ArrayExample
add, canonicalize, copyValues, growArray, isDense, iterator, lookup, newCapacity, set, size, toString, transform, validateExampleMethods 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:
-
featureIDs
protected int[] featureIDsFeature id numbers from the internal featureMap. -
outputID
protected final int outputIDOutput id from the internal output map. Note this only works for single dimensional outputs, in multi-dimensional cases it is likely to be -1.
-
-
Constructor Details
-
IndexedArrayExample
Copy constructor.- Parameters:
other- The example to copy.
-
IndexedArrayExample
public IndexedArrayExample(Example<T> other, ImmutableFeatureMap featureMap, ImmutableOutputInfo<T> outputMap) This constructor removes unknown features.- Parameters:
other- The example to copy from.featureMap- The feature map.outputMap- The output info.
-
-
Method Details
-
deserializeFromProto
public static ArrayExample<?> 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.
-
equals
-
hashCode
public int hashCode()- Overrides:
hashCodein classArrayExample<T extends Output<T>>
-
growArray
protected void growArray(int minCapacity) Description copied from class:ArrayExampleGrows the backing arrays storing the names and values.- Overrides:
growArrayin classArrayExample<T extends Output<T>>- Parameters:
minCapacity- The new minimum capacity required.
-
add
-
addAll
-
sort
protected void sort()Description copied from class:ArrayExampleSorts the feature list to maintain the lexicographic order invariant.- Overrides:
sortin classArrayExample<T extends Output<T>>
-
reduceByName
Description copied from class:ExampleMerges features with the same name using the suppliedMerger.- Overrides:
reduceByNamein classArrayExample<T extends Output<T>>- Parameters:
merger- A function to merge two doubles.
-
removeFeatures
Description copied from class:ExampleRemoves all features in this list from the Example.- Overrides:
removeFeaturesin classArrayExample<T extends Output<T>>- Parameters:
featureList- Features to remove from this Example.
-
contains
public boolean contains(int i) Does this example contain a feature with id i.- Parameters:
i- The index to check.- Returns:
- True if the example contains the id.
-
copy
-
densify
UnlikeArrayExample.densify(List)this method will throwIllegalArgumentExceptionif one of the feature names is not present in this example'sImmutableFeatureMap.featureListmust be sorted lexicographically using theStringcomparator, and behaviour is undefined otherwise.- Overrides:
densifyin classArrayExample<T extends Output<T>>- Parameters:
featureList- A *sorted* list of feature names.
-
getIdx
public int getIdx(int i) Gets the feature at internal index i.- Parameters:
i- The internal index.- Returns:
- The feature index.
-
getOutputID
public int getOutputID()Gets the output id dimension number.- Returns:
- The output id.
-
idIterator
Iterator over the feature ids and values.- Returns:
- The feature ids and values.
-
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>>- Overrides:
serializein classArrayExample<T extends Output<T>>- Returns:
- The protobuf.
-