public class FeatureValue
extends java.lang.Object
implements java.io.Serializable, com.esotericsoftware.kryo.KryoSerializable
FeatureValue| Modifier and Type | Field and Description |
|---|---|
static float |
DEFAULT_VALUE |
static java.lang.String |
EMPTY_TERM |
| Constructor and Description |
|---|
FeatureValue()
Deprecated.
Use the static factory methods such as
createNumeric(Number) to construct features instead |
FeatureValue(FeatureValue featureValueInternal) |
FeatureValue(java.util.Map<java.lang.String,java.lang.Float> value)
Deprecated.
Use the static factory methods such as
createStringTermVector(Map) to construct features instead |
FeatureValue(java.lang.Object value)
Deprecated.
Use the static factory methods such as
createNumeric(Number) to construct features instead
N.B. Although this takes Object, there are runtime type checks to ensure the passed type can be converted
to a feature value. |
FeatureValue(java.lang.Object value,
FeatureTypes type)
Deprecated.
Use the static factory methods such as
createNumeric(Number) to construct features instead |
FeatureValue(TypedTensor tensor)
Constructor to create FeatureValue with a tensor object
|
| Modifier and Type | Method and Description |
|---|---|
static FeatureValue |
createBoolean(java.lang.Boolean b)
Creates a boolean feature.
|
static FeatureValue |
createCategorical(java.lang.Character term)
Creates a categorical feature from a character term
|
static FeatureValue |
createCategorical(java.lang.CharSequence term)
Creates a categorical feature from a string term
|
static FeatureValue |
createCategorical(java.lang.Number term)
Deprecated.
|
static FeatureValue |
createCharacterCategoricalSet(java.util.Collection<java.lang.Character> characters)
Creates a categorical set feature from character terms
|
static <T extends java.lang.Number> |
createDenseVector(java.util.List<T> vec)
Creates a dense vector feature from a
List of numbers |
static <T extends java.lang.Number> |
createDenseVector(T[] vec)
Creates a dense vector feature from an array of numbers
|
static FeatureValue |
createNumeric(java.lang.Number num)
Creates a numeric feature.
|
static <T extends java.lang.Number> |
createNumericCategoricalSet(java.util.Collection<T> terms)
Creates a categorical set feature from a collection of Numbers that are whole numbers
|
static <K extends java.lang.Number,V extends java.lang.Number> |
createNumericTermVector(java.util.Collection<java.util.Map<K,V>> termValues)
Creates a term vector feature (e.g.
|
static <K extends java.lang.Number,V extends java.lang.Number> |
createNumericTermVector(java.util.Map<K,V> inputMap)
Creates a term vector feature (e.g.
|
static <T extends java.lang.CharSequence> |
createStringCategoricalSet(java.util.Collection<T> terms)
Creates a categorical set feature from string terms
|
static <K extends java.lang.CharSequence,V extends java.lang.Number> |
createStringTermVector(java.util.Collection<java.util.Map<K,V>> termValues)
Creates a term vector feature (AKA sparse vector) from multiple term vectors with string terms
|
static <K extends java.lang.CharSequence,V extends java.lang.Number> |
createStringTermVector(java.util.Map<K,V> inputMap)
Creates a term vector feature (aka sparse vector) using strings for the terms
|
static FeatureValue |
createTensor(java.lang.Object value,
TensorType type)
Creates a (tensor) FeatureValue based on the provided TensorType.
|
static FeatureValue |
createTensor(TensorData tensorData)
Create a FeatureValue from a TensorData (adding a TensorType inferred from the primitives of the TensorData).
|
boolean |
equals(java.lang.Object o) |
java.lang.Boolean |
getAsBoolean()
Get feature value as boolean
|
java.lang.String |
getAsCategorical()
Returns the single categorical value associated with the feature
Note: this method will return
String even if the feature was created using createCategorical(Number)
because categorical are meant to contain only discrete values which are represented by String |
java.lang.Float |
getAsNumeric()
get feature value as number
|
java.lang.String |
getAsString()
Deprecated.
use
getAsCategorical() instead |
TensorData |
getAsTensorData() |
java.util.Map<java.lang.String,java.lang.Float> |
getAsTermVector()
Gets the feature in an NTV term-vector representation.
|
TypedTensor |
getAsTypedTensor() |
FeatureType |
getFeatureType() |
int |
getNumTerms()
Deprecated.
|
java.util.Map<java.lang.String,java.lang.Float> |
getValue()
Deprecated.
Prefer to use
getAsTermVector() which has a more descriptive name |
int |
hashCode() |
boolean |
isEmpty()
Check if the FeatureValue is empty or not.
|
void |
put(java.lang.String key,
java.lang.Float value)
Deprecated.
mutability in FeatureValue is deprecated; see class-level Javadoc
|
void |
read(com.esotericsoftware.kryo.Kryo kryo,
com.esotericsoftware.kryo.io.Input input) |
int |
size()
Deprecated.
Prefer to use
getNumTerms() which has a more descriptive name |
java.lang.String |
toString() |
void |
write(com.esotericsoftware.kryo.Kryo kryo,
com.esotericsoftware.kryo.io.Output output) |
public static final float DEFAULT_VALUE
public static final java.lang.String EMPTY_TERM
public FeatureValue(FeatureValue featureValueInternal)
@Deprecated public FeatureValue(java.lang.Object value)
createNumeric(Number) to construct features instead
N.B. Although this takes Object, there are runtime type checks to ensure the passed type can be converted
to a feature value.@Deprecated public FeatureValue()
createNumeric(Number) to construct features instead@Deprecated
public FeatureValue(java.lang.Object value,
FeatureTypes type)
createNumeric(Number) to construct features insteadpublic FeatureValue(TypedTensor tensor)
tensor - TypedTensorjava.lang.NullPointerException - if tensor parameter is null@Deprecated public FeatureValue(java.util.Map<java.lang.String,java.lang.Float> value)
createStringTermVector(Map) to construct features instead@Deprecated
public void put(java.lang.String key,
java.lang.Float value)
java.lang.RuntimeException - if not mutablepublic boolean isEmpty()
@Deprecated public int size()
getNumTerms() which has a more descriptive namejava.lang.RuntimeException - if this instance stores a tensor of rank greater than 1@Deprecated public java.util.Map<java.lang.String,java.lang.Float> getValue()
getAsTermVector() which has a more descriptive name@Deprecated public int getNumTerms()
java.lang.RuntimeException - if this instance stores a tensor of rank greater than 1public FeatureType getFeatureType()
public TypedTensor getAsTypedTensor()
public TensorData getAsTensorData()
public java.util.Map<java.lang.String,java.lang.Float> getAsTermVector()
Map from String term names to Float valuesjava.lang.RuntimeException - if the feature is a tensor of rank greater than 1, then this feature cannot be represented
as an NTV term vectorpublic java.lang.Float getAsNumeric()
java.lang.RuntimeException - if this is not a valid numeric feature@Deprecated public java.lang.String getAsString()
getAsCategorical() insteadpublic java.lang.String getAsCategorical()
String even if the feature was created using createCategorical(Number)
because categorical are meant to contain only discrete values which are represented by Stringjava.lang.RuntimeException - if this is not a valid categorical featurepublic java.lang.Boolean getAsBoolean()
java.lang.RuntimeException - if this is not a valid boolean featurepublic static FeatureValue createNumeric(java.lang.Number num)
num - NumberFeatureValue@Deprecated public static FeatureValue createCategorical(java.lang.Number term)
String.
Only whole number terms are accepted because categorical are meant to contain discrete values. The common use case
for using number as the term would be to represent some entity ID (e.g. y, x)term - Number the numeric term which will be stored as a String termFeatureValuejava.lang.RuntimeException - if num is not within some precision of a whole numberpublic static FeatureValue createCategorical(java.lang.CharSequence term)
term - CharSequenceFeatureValuepublic static FeatureValue createCategorical(java.lang.Character term)
term - CharacterFeatureValuepublic static <T extends java.lang.Number> FeatureValue createDenseVector(java.util.List<T> vec)
List of numbersT - the type of Numbervec - ListFeatureValuepublic static <T extends java.lang.Number> FeatureValue createDenseVector(T[] vec)
T - the type of Numbervec - T[] array of itemsFeatureValuepublic static <K extends java.lang.CharSequence,V extends java.lang.Number> FeatureValue createStringTermVector(java.util.Map<K,V> inputMap)
K - the string term typeV - the numeric value typeinputMap - Map from a string term to numeric valuesFeatureValuepublic static <K extends java.lang.Number,V extends java.lang.Number> FeatureValue createNumericTermVector(java.util.Map<K,V> inputMap)
K - the numeric term typeV - the numeric value typeinputMap - Map from a number term (within some precision of a whole numbers) to numeric valueFeatureValuejava.lang.RuntimeException - if input numeric key is a not within some precision of a whole numbers (e.g. 1.5f)java.lang.RuntimeException - if multiple input numeric keys map to the same whole number (e.g. 1.00f and 1.0000d)public static <K extends java.lang.CharSequence,V extends java.lang.Number> FeatureValue createStringTermVector(java.util.Collection<java.util.Map<K,V>> termValues)
K - the string term typeV - the numeric value typetermValues - Collection of Map from string term to numeric valueFeatureValuejava.lang.RuntimeException - if input numeric key is a not within some precision of a whole numbersjava.lang.RuntimeException - if multiple input numeric keys map to the same whole number (e.g. 1.00f and 1.0000d)public static <K extends java.lang.Number,V extends java.lang.Number> FeatureValue createNumericTermVector(java.util.Collection<java.util.Map<K,V>> termValues)
K - the numeric term typeV - the numeric value typetermValues - Map from a number term to numeric valueFeatureValuejava.lang.RuntimeException - if input numeric keys are not within some precision of a whole numbers (e.g. 1.5f)java.lang.RuntimeException - if multiple input numeric keys map to the same whole number (e.g. 1.00f and 1.0000d)public static <T extends java.lang.Number> FeatureValue createNumericCategoricalSet(java.util.Collection<T> terms)
T - the numeric typeterms - Collection of Number termsFeatureValuejava.lang.RuntimeException - if input numeric elements are not within some precision of a whole numbers (e.g. 1.5f)public static <T extends java.lang.CharSequence> FeatureValue createStringCategoricalSet(java.util.Collection<T> terms)
T - the string term typeterms - Collection of CharSequence termsFeatureValuepublic static FeatureValue createCharacterCategoricalSet(java.util.Collection<java.lang.Character> characters)
characters - Collection of CharacterFeatureValuepublic static FeatureValue createBoolean(java.lang.Boolean b)
b - BooleanFeatureValuepublic static FeatureValue createTensor(java.lang.Object value, TensorType type)
value - The data used to creates the the tensor.type - The corresponding type needed to create the tensor.java.lang.IllegalArgumentException - if the data type is not supported or if create a 2-d or higher dimension tensor.public static FeatureValue createTensor(TensorData tensorData)
public java.lang.String toString()
toString in class java.lang.Objectpublic boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic void write(com.esotericsoftware.kryo.Kryo kryo,
com.esotericsoftware.kryo.io.Output output)
write in interface com.esotericsoftware.kryo.KryoSerializablepublic void read(com.esotericsoftware.kryo.Kryo kryo,
com.esotericsoftware.kryo.io.Input input)
read in interface com.esotericsoftware.kryo.KryoSerializable