T
- The output type.public final class BinaryFeaturesExample<T extends Output<T>> extends Example<T>
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
:
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_SIZE |
protected String[] |
featureNames |
protected int |
size |
DEFAULT_METADATA_SIZE, DEFAULT_WEIGHT, metadata, NAME, output, weight
Constructor and Description |
---|
BinaryFeaturesExample(Example<T> other)
Copy constructor.
|
BinaryFeaturesExample(T output)
Constructs an example from an output.
|
BinaryFeaturesExample(T output,
Example<U> other,
float weight)
Clones an example's features, but uses the supplied output and weight.
|
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,
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.
|
BinaryFeaturesExample(T output,
String[] names)
Constructs an example from an output and an array of names.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Feature feature)
Adds a feature to this example.
|
void |
add(String name)
Adds a single feature with a value of 1.
|
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 the
FeatureMap . |
static void |
checkIsBinary(Feature feature) |
BinaryFeaturesExample<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.
|
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.
|
int |
hashCode() |
static boolean |
isBinary(Feature feature) |
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, 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 int size
public BinaryFeaturesExample(T output, float weight, int initialSize)
output
- The output.weight
- The weight.initialSize
- The initial size of the feature arrays.public BinaryFeaturesExample(T output, float weight, Map<String,Object> metadata)
output
- The output.weight
- The weight.metadata
- The metadata.public BinaryFeaturesExample(T output, float weight)
output
- The output.weight
- The example weight.public BinaryFeaturesExample(T output, Map<String,Object> metadata)
output
- The output.metadata
- The metadata.public BinaryFeaturesExample(T output)
output
- The output.public BinaryFeaturesExample(T output, String[] names)
output
- The output.names
- The feature names.public BinaryFeaturesExample(T output, List<? extends Feature> features)
IllegalArgumentException
if any of the features have a
feature value that does not equal 1.0.output
- The output (e.g., label) of the examplefeatures
- The list of features.public BinaryFeaturesExample(Example<T> other)
IllegalArgumentException
if any of the features have a feature value
that does not equal 1.0.other
- The example to copy.public BinaryFeaturesExample(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)
name
- The name of the feature.public static boolean isBinary(Feature feature)
public static void checkIsBinary(Feature feature)
public void add(Feature feature)
IllegalArgumentException
if
any of the features have a feature value that does not equal 1.0.public void addAll(Collection<? extends Feature> features)
IllegalArgumentException
if any of the features have a feature value
that does not equal 1.0.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 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 boolean validateExample()
Example
validateExample
in class Example<T extends Output<T>>
public BinaryFeaturesExample<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 reduceByName(Merger merger)
Example
Merger
.reduceByName
in class Example<T extends Output<T>>
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.public void densify(List<String> featureList)
Example
protected void densify(FeatureMap fMap)
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.