T
- The type of output that this example contains.public abstract class Example<T extends Output<T>> extends Object implements Iterable<Feature>, Serializable
OutputFactory.getUnknownOutput()
and a list of features that can be used for prediction.
An example is a sorted set of features, sorted by the String comparator on the feature name.
Examples have metadata associated with them, stored as a map from a String key, to an Object value. This metadata is append only for any given example, and the metadata values should be immutable (as they will be referenced rather than copied when an example is copied).
Modifier and Type | Field and Description |
---|---|
protected static int |
DEFAULT_METADATA_SIZE
The default initial size of the metadata map.
|
static float |
DEFAULT_WEIGHT
The default weight.
|
protected Map<String,Object> |
metadata
The example metadata.
|
static String |
NAME
By convention the example name is stored using this metadata key.
|
protected T |
output
The output associated with this example.
|
protected float |
weight
The weight associated with this example.
|
Modifier | Constructor and Description |
---|---|
protected |
Example(Example<T> other)
Copies the output, weight and metadata into this example.
|
protected |
Example(T output)
Construct an empty example using the supplied output and
DEFAULT_WEIGHT as the weight. |
protected |
Example(T output,
float weight)
Construct an empty example using the supplied output and weight.
|
protected |
Example(T output,
float weight,
Map<String,Object> metadata)
Construct an empty example using the supplied output, weight and metadata.
|
protected |
Example(T output,
Map<String,Object> metadata)
Construct an empty example using the supplied output, metadata and
DEFAULT_WEIGHT as the weight. |
Modifier and Type | Method and Description |
---|---|
abstract void |
add(Feature feature)
Adds a feature.
|
abstract void |
addAll(Collection<? extends Feature> features)
Adds a collection of features.
|
abstract void |
canonicalize(FeatureMap featureMap)
Reassigns feature name Strings in the Example to point to those in the
FeatureMap . |
boolean |
containsMetadata(String key)
Test if the metadata contains the supplied key.
|
abstract Example<T> |
copy()
Returns a deep copy of this Example.
|
protected void |
densify(FeatureMap fMap)
Converts all implicit zeros into explicit zeros based on the supplied feature map.
|
protected abstract void |
densify(List<String> featureNames)
Converts all implicit zeros into explicit zeros based on the supplied feature names.
|
Map<String,Object> |
getMetadata()
Returns a copy of this example's metadata.
|
Optional<Object> |
getMetadataValue(String key)
Gets the associated metadata value for this key, if it exists.
|
T |
getOutput()
Gets the example's
Output . |
float |
getWeight()
Gets the example's weight.
|
Feature |
lookup(String i)
Returns the Feature in this Example which has the supplied name, if it's present.
|
abstract void |
reduceByName(Merger merger)
Merges features with the same name using the
supplied
Merger . |
abstract void |
removeFeatures(List<Feature> featureList)
Removes all features in this list from the Example.
|
abstract void |
set(Feature feature)
Overwrites the feature with the matching name.
|
void |
setMetadataValue(String key,
Object value)
Puts the specified key, value pair into the metadata.
|
void |
setWeight(float weight)
Sets the example's weight.
|
abstract int |
size()
Return how many features are in this example.
|
protected abstract void |
sort()
Sorts the example by the string comparator.
|
void |
transform(TransformerMap transformerMap)
Transforms this example by applying the transformations from the supplied
TransformerMap . |
abstract boolean |
validateExample()
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, iterator, spliterator
protected static final int DEFAULT_METADATA_SIZE
public static final float DEFAULT_WEIGHT
public static final String NAME
Note: not all examples are named.
protected float weight
protected Example(T output, float weight, Map<String,Object> metadata)
output
- The output.weight
- The weight.metadata
- The metadata.protected Example(T output, float weight)
output
- The output.weight
- The weight.protected Example(T output, Map<String,Object> metadata)
DEFAULT_WEIGHT
as the weight.output
- The output.metadata
- The metadata.protected Example(T output)
DEFAULT_WEIGHT
as the weight.output
- The output.public float getWeight()
public void setWeight(float weight)
weight
- The new weight.public Optional<Object> getMetadataValue(String key)
Optional.empty()
.key
- The key to check.public void setMetadataValue(String key, Object value)
Example metadata is append only, and so this method
throws IllegalArgumentException
if the key is already present.
key
- The key.value
- The value.public boolean containsMetadata(String key)
key
- The key to test.public Map<String,Object> getMetadata()
protected abstract void sort()
public abstract void add(Feature feature)
feature
- The feature to add.public abstract void addAll(Collection<? extends Feature> features)
features
- The features to add.public abstract int size()
public abstract void removeFeatures(List<Feature> featureList)
featureList
- Features to remove from this Example.public abstract void reduceByName(Merger merger)
Merger
.merger
- A function to merge two doubles.public abstract boolean validateExample()
public void transform(TransformerMap transformerMap)
TransformerMap
.
Can be overridden for performance reasons.
transformerMap
- The transformations to apply.protected void densify(FeatureMap fMap)
fMap
- The feature map to use for densification.protected abstract void densify(List<String> featureNames)
featureNames
- A *sorted* list of feature names.public abstract Example<T> copy()
public Feature lookup(String i)
i
- The feature name to lookup.public abstract void set(Feature feature)
Throws IllegalArgumentException
if there isn't a feature with that
name in this example.
feature
- The new feature value.public abstract void canonicalize(FeatureMap featureMap)
FeatureMap
.
This significantly reduces memory allocation. It is called when an Example is added
to a MutableDataset
, and should not be called outside of that context as it may interact
unexpectedly with HashedFeatureMap
.featureMap
- The feature map containing canonical feature names.Copyright © 2015–2021 Oracle and/or its affiliates. All rights reserved.