public class Regressor extends Object implements Output<Regressor>, Iterable<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.
Modifier and Type | Class and Description |
---|---|
static class |
Regressor.DimensionTuple
A
Regressor which contains a single dimension, used internally
when the model implementation doesn't natively support multi-dimensional
regression outputs. |
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_NAME |
static double |
TOLERANCE |
Constructor and Description |
---|
Regressor(Regressor.DimensionTuple[] dimensions)
Constructs a regressor from the supplied dimension tuples.
|
Regressor(String[] names,
double[] values)
Constructs a regressor from the supplied named values.
|
Regressor(String[] names,
double[] values,
double[] variances)
Constructs a regressor from the supplied named values.
|
Regressor(String name,
double value)
Constructs a regressor containing a single dimension, using
Double.NaN as the variance. |
Regressor(String name,
double value,
double variance)
Constructs a regressor containing a single dimension.
|
Modifier and Type | Method and Description |
---|---|
Regressor |
copy()
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 |
equals(Object o)
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.
|
Optional<Regressor.DimensionTuple> |
getDimension(String name)
Returns a dimension tuple for the requested dimension, or optional empty if
it's not valid.
|
String |
getDimensionNamesString()
Returns a comma separated list of the dimension names.
|
String |
getDimensionNamesString(char separator)
Returns a delimiter separated list of the dimension names.
|
String[] |
getNames()
The names of the dimensions.
|
String |
getSerializableForm(boolean includeConfidence)
Generates a String suitable for writing to a csv or json file.
|
double[] |
getValues()
Returns the regression values.
|
double[] |
getVariances()
The variances of the regressed values, if known.
|
int |
hashCode()
Regressor's hashcode is based on the hash of the dimension names.
|
Iterator<Regressor.DimensionTuple> |
iterator() |
static com.oracle.labs.mlrg.olcut.util.Pair<String,Double> |
parseElement(int idx,
String s)
Parses a string of the form:
|
static Regressor |
parseString(String s)
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.
|
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
forEach, spliterator
public static final double TOLERANCE
public static final String DEFAULT_NAME
public Regressor(String[] names, double[] values, double[] variances)
IllegalArgumentException
if the arrays are not all the same size.names
- The names of the dimensions.values
- The values of the dimensions.variances
- The variances of the specified values.public Regressor(String[] names, double[] values)
Double.NaN
as
the variances.names
- The names of the dimensions.values
- The values of the dimensions.public Regressor(Regressor.DimensionTuple[] dimensions)
dimensions
- The named values to use.public Regressor(String name, double value)
Double.NaN
as the variance.name
- The name of the dimension.value
- The value of the dimension.public Regressor(String name, double value, double variance)
name
- The name of the dimension.value
- The value of the dimension.variance
- The variance of this value.public int size()
public String[] getNames()
public double[] getValues()
public double[] getVariances()
public Optional<Regressor.DimensionTuple> getDimension(String name)
name
- The dimension name.public Iterator<Regressor.DimensionTuple> iterator()
iterator
in interface Iterable<Regressor.DimensionTuple>
public Regressor copy()
Output
public String getSerializableForm(boolean includeConfidence)
Output
getSerializableForm
in interface Output<Regressor>
includeConfidence
- Include whatever confidence score the label contains, if known.public boolean fullEquals(Regressor other)
Output
fullEquals
in interface Output<Regressor>
other
- Another output instance.public boolean equals(Object o)
public int hashCode()
It's cached on first access.
public String getDimensionNamesString()
public String getDimensionNamesString(char separator)
separator
- The separator to use.public static String[] extractNames(OutputInfo<Regressor> info)
info
- The OutputInfo to use.public static Regressor parseString(String s)
dimension-name=output,...,dimension-name=outputwhere output must be readable by
Double.parseDouble(java.lang.String)
.s
- The string form of a multiple regressor.public static Regressor parseString(String s, char splitChar)
dimension-name=output<splitChar>...<splitChar>dimension-name=outputwhere output must be readable by
Double.parseDouble(java.lang.String)
.s
- The string form of a regressor.splitChar
- The char to split on.public static com.oracle.labs.mlrg.olcut.util.Pair<String,Double> parseElement(int idx, String s)
dimension-name=output-doublewhere the output must be readable by
Double.parseDouble(java.lang.String)
.idx
- The index of this string in a list.s
- The string form of a single dimension from a regressor.Copyright © 2015–2021 Oracle and/or its affiliates. All rights reserved.