public class ArrayExample<T extends Output<T>> extends Example<T>
Example
backed by two arrays, one of String and one of double.Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_SIZE |
protected String[] |
featureNames |
protected double[] |
featureValues |
protected int |
size |
DEFAULT_METADATA_SIZE, DEFAULT_WEIGHT, metadata, NAME, output, weight
Constructor and Description |
---|
ArrayExample(Example<T> other)
Copy constructor.
|
ArrayExample(T output)
Constructs an example from an output.
|
ArrayExample(T output,
Example<U> other,
float weight)
Clones an example's features, but uses the supplied output and weight.
|
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,
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.
|
ArrayExample(T output,
String[] names,
double[] values)
Constructs an example from an output, an array of names and an array of values.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Feature feature)
Adds a feature.
|
void |
add(String name,
double value)
Adds a single 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 the
FeatureMap . |
ArrayExample<T> |
copy()
Returns a deep copy of this Example.
|
double[] |
copyValues(int newSize)
Returns a copy of the feature values array at the specific size.
|
void |
densify(List<String> featureList)
Converts all implicit zeros into explicit zeros based on the supplied feature names.
|
boolean |
equals(Object o) |
protected void |
growArray()
Grows the backing arrays by size+1.
|
protected void |
growArray(int minCapacity)
Grows the backing arrays storing the names and values.
|
int |
hashCode() |
Iterator<Feature> |
iterator() |
Feature |
lookup(String i)
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
supplied
Merger . |
void |
removeFeatures(List<Feature> featureList)
Removes all features in this list from the Example.
|
void |
set(Feature feature)
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.
|
String |
toString() |
void |
transform(TransformerMap transformerMap)
Transforms this example by applying the transformations from the supplied
TransformerMap . |
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.
|
containsMetadata, densify, getMetadata, getMetadataValue, getOutput, getWeight, setMetadataValue, setWeight
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
forEach, spliterator
public static final int DEFAULT_SIZE
protected String[] featureNames
protected double[] featureValues
protected int size
public ArrayExample(T output, float weight, int initialSize)
output
- The output.weight
- The weight.initialSize
- The initial size of the feature arrays.public ArrayExample(T output, float weight, Map<String,Object> metadata)
output
- The output.weight
- The weight.metadata
- The metadata.public ArrayExample(T output, float weight)
output
- The output.weight
- The example weight.public ArrayExample(T output, Map<String,Object> metadata)
output
- The output.metadata
- The metadata.public ArrayExample(T output)
output
- The output.public ArrayExample(T output, String[] names, double[] values)
output
- The output.names
- The feature names.values
- The feature values.public ArrayExample(T output, List<? extends Feature> features)
output
- The output.features
- The list of features.public ArrayExample(Example<T> other)
other
- The example to copy.public ArrayExample(T output, Example<U> other, float weight)
U
- The output type of the other example.output
- The output to use.other
- The features to use.weight
- The weight to use.public void add(String name, double value)
name
- The name of the feature.value
- The value of the feature.public void add(Feature feature)
Example
public void addAll(Collection<? extends Feature> features)
Example
protected void growArray(int minCapacity)
minCapacity
- The new minimum capacity required.protected void growArray()
protected int newCapacity(int minCapacity)
minCapacity
- the desired minimum capacityOutOfMemoryError
- if minCapacity is less than zeroprotected void sort()
public double[] copyValues(int newSize)
newSize
- The new size.public int size()
Example
public void removeFeatures(List<Feature> featureList)
Example
removeFeatures
in class Example<T extends Output<T>>
featureList
- Features to remove from this Example.public void reduceByName(Merger merger)
Example
Merger
.reduceByName
in class Example<T extends Output<T>>
merger
- A function to merge two doubles.public boolean validateExample()
Example
validateExample
in class Example<T extends Output<T>>
public ArrayExample<T> copy()
Example
public Feature lookup(String i)
Example
public void set(Feature feature)
Example
Throws IllegalArgumentException
if there isn't a feature with that
name in this example.
public void transform(TransformerMap transformerMap)
Example
TransformerMap
.
Can be overridden for performance reasons.
public void densify(List<String> featureList)
Example
public void canonicalize(FeatureMap featureMap)
Example
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
.canonicalize
in class Example<T extends Output<T>>
featureMap
- The feature map containing canonical feature names.Copyright © 2015–2021 Oracle and/or its affiliates. All rights reserved.