Class Regressor
- All Implemented Interfaces:
Serializable
,Iterable<Regressor.DimensionTuple>
,Output<Regressor>
- Direct Known Subclasses:
Regressor.DimensionTuple
Output
for n-dimensional real valued regression.
In addition to the regressed values, it may optionally contain
variances. Otherwise the variances are set to Double.NaN
.
Within a DataSource
or Dataset
each Regressor must contain the same set of named dimensions. The dimensions stored in a
Regressor are sorted by the natural ordering of their names (i.e., using the String comparator).
This allows the use of direct indexing into the elements.
Note fullEquals(org.tribuo.regression.Regressor)
compares the dimensions, the regressed values and the
variances. However unlike Double.equals(java.lang.Object)
, if the two variances being compared are
set to the sentinel value of Double.NaN
, then they are considered equal.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
ARegressor
which contains a single dimension, used internally when the model implementation doesn't natively support multi-dimensional regression outputs. -
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Default name used for dimensions which are unnamed when parsed from Strings.static final double
The tolerance value for determining if two regressed values are equal. -
Constructor Summary
ConstructorDescriptionConstructs a regressor from the supplied named values.Constructs a regressor from the supplied named values.Constructs a regressor containing a single dimension, usingDouble.NaN
as the variance.Constructs a regressor containing a single dimension.Regressor
(Regressor.DimensionTuple[] dimensions) Constructs a regressor from the supplied dimension tuples. -
Method Summary
Modifier and TypeMethodDescriptioncopy()
Deep copy of the output up to it's immutable state.static Regressor
createFromPairList
(List<com.oracle.labs.mlrg.olcut.util.Pair<String, Double>> dimensions) Creates a Regressor from a list of dimension tuples.boolean
Regressors are equal if they have the same number of dimensions and equal dimension names.static String[]
extractNames
(OutputInfo<Regressor> info) Extracts the names from the supplied Regressor domain in their canonical order.boolean
fullEquals
(Regressor other) Compares other to this output.getDimension
(int idx) Returns a dimension tuple for the requested dimension index.getDimension
(String name) Returns a dimension tuple for the requested dimension, or optional empty if it's not valid.Returns a comma separated list of the dimension names.getDimensionNamesString
(char separator) Returns a delimiter separated list of the dimension names.String[]
getNames()
The names of the dimensions.getSerializableForm
(boolean includeConfidence) Generates a String suitable for writing to a csv or json file.double[]
Returns the regression values.double[]
The variances of the regressed values, if known.int
hashCode()
Regressor's hashcode is based on the hash of the dimension names.iterator()
parseElement
(int idx, String s) Parses a string of the form:static Regressor
Parses a string of the form:static Regressor
parseString
(String s, char splitChar) Parses a string of the form:int
size()
Returns the number of dimensions in this regressor.toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
TOLERANCE
public static final double TOLERANCEThe tolerance value for determining if two regressed values are equal.- See Also:
-
DEFAULT_NAME
Default name used for dimensions which are unnamed when parsed from Strings.- See Also:
-
-
Constructor Details
-
Regressor
Constructs a regressor from the supplied named values. ThrowsIllegalArgumentException
if the arrays are not all the same size.- Parameters:
names
- The names of the dimensions.values
- The values of the dimensions.variances
- The variances of the specified values.
-
Regressor
Constructs a regressor from the supplied named values. UsesDouble.NaN
as the variances.- Parameters:
names
- The names of the dimensions.values
- The values of the dimensions.
-
Regressor
Constructs a regressor from the supplied dimension tuples.- Parameters:
dimensions
- The named values to use.
-
Regressor
Constructs a regressor containing a single dimension, usingDouble.NaN
as the variance.- Parameters:
name
- The name of the dimension.value
- The value of the dimension.
-
Regressor
Constructs a regressor containing a single dimension.- Parameters:
name
- The name of the dimension.value
- The value of the dimension.variance
- The variance of this value.
-
-
Method Details
-
size
public int size()Returns the number of dimensions in this regressor.- Returns:
- The number of dimensions.
-
getNames
The names of the dimensions. Always sorted by their natural ordering.- Returns:
- The names of the dimensions.
-
getValues
public double[] getValues()Returns the regression values.The index corresponds to the index of the name.
In a single dimensional regression this is a single element array.
- Returns:
- The regression values.
-
getVariances
public double[] getVariances()The variances of the regressed values, if known. If the variances are unknown (or not set by the model) they are filled withDouble.NaN
.The index corresponds to the index of the name.
In a single dimensional regression this is a single element array.
- Returns:
- The variance of the regressed values.
-
toString
-
getDimension
Returns a dimension tuple for the requested dimension, or optional empty if it's not valid.- Parameters:
name
- The dimension name.- Returns:
- A tuple representing that dimension.
-
getDimension
Returns a dimension tuple for the requested dimension index.- Parameters:
idx
- The dimension index.- Returns:
- A tuple representing that dimension.
- Throws:
IndexOutOfBoundsException
- if the index is outside the range.
-
iterator
- Specified by:
iterator
in interfaceIterable<Regressor.DimensionTuple>
-
copy
Description copied from interface:Output
Deep copy of the output up to it's immutable state. -
getSerializableForm
Description copied from interface:Output
Generates a String suitable for writing to a csv or json file.- Specified by:
getSerializableForm
in interfaceOutput<Regressor>
- Parameters:
includeConfidence
- Include whatever confidence score the label contains, if known.- Returns:
- A String representation of this Output.
-
fullEquals
Description copied from interface:Output
Compares other to this output. Uses all score values and the strings.- Specified by:
fullEquals
in interfaceOutput<Regressor>
- Parameters:
other
- Another output instance.- Returns:
- True if the other instance has value equality to this instance. False otherwise.
-
equals
Regressors are equal if they have the same number of dimensions and equal dimension names. -
hashCode
public int hashCode()Regressor's hashcode is based on the hash of the dimension names.It's cached on first access.
-
getDimensionNamesString
Returns a comma separated list of the dimension names.- Returns:
- The dimension names comma separated.
-
getDimensionNamesString
Returns a delimiter separated list of the dimension names.- Parameters:
separator
- The separator to use.- Returns:
- The dimension names.
-
extractNames
Extracts the names from the supplied Regressor domain in their canonical order.- Parameters:
info
- The OutputInfo to use.- Returns:
- The dimension names from this domain.
-
parseString
Parses a string of the form:dimension-name=output,...,dimension-name=output
oroutput,...,output
where output must be readable byDouble.parseDouble(java.lang.String)
. If there are no dimension names specified then they are automatically generated based on the position in the string.- Parameters:
s
- The string form of a multiple regressor.- Returns:
- A regressor parsed from the input string.
-
parseString
Parses a string of the form:dimension-name=output<splitChar>...<splitChar>dimension-name=output
oroutput<splitChar>...<splitChar>output
where output must be readable byDouble.parseDouble(java.lang.String)
. If there are no dimension names specified then they are automatically generated based on the position in the string.- Parameters:
s
- The string form of a regressor.splitChar
- The char to split on.- Returns:
- A regressor parsed from the input string.
-
parseElement
Parses a string of the form:dimension-name=output-double
oroutput-double
where the output must be readable byDouble.parseDouble(java.lang.String)
. If there is no dimension name then one is constructed by appending idx toDEFAULT_NAME
.- Parameters:
idx
- The index of this string in a list.s
- The string form of a single dimension from a regressor.- Returns:
- A tuple representing the dimension name and the value.
-
createFromPairList
public static Regressor createFromPairList(List<com.oracle.labs.mlrg.olcut.util.Pair<String, Double>> dimensions) Creates a Regressor from a list of dimension tuples.- Parameters:
dimensions
- The dimensions to use.- Returns:
- A Regressor representing these dimensions.
-