public abstract class SharedTreeMojoModel extends MojoModel implements TreeBackedMojoModel, PlattScalingMojoHelper.MojoModelWithCalibration
DrfMojoModel
and GbmMojoModel
.
See also: `hex.tree.SharedTreeModel` and `hex.tree.TreeVisitor` classes.Modifier and Type | Class and Description |
---|---|
static class |
SharedTreeMojoModel.AuxInfo |
static interface |
SharedTreeMojoModel.DecisionPathTracker<T> |
static class |
SharedTreeMojoModel.LeafDecisionPathTracker |
static class |
SharedTreeMojoModel.LeafNodeAssignments |
static class |
SharedTreeMojoModel.StringDecisionPathTracker |
Modifier and Type | Field and Description |
---|---|
static int |
__INTERNAL_MAX_TREE_DEPTH |
protected double[] |
_calib_glm_beta
GLM's beta used for calibrating output probabilities using Platt Scaling.
|
protected byte[][] |
_compressed_trees
Array of binary tree data, each tree being a
byte[] array. |
protected byte[][] |
_compressed_trees_aux
Array of auxiliary binary tree data, each being a
byte[] array. |
protected java.lang.String |
_genmodel_encoding |
protected int |
_ntree_groups
_ntree_groups is the number of trees requested by the user. |
protected int |
_ntrees_per_group |
protected java.lang.String[][] |
_orig_domain_values |
protected java.lang.String[] |
_orig_names |
protected double[] |
_orig_projection_array |
_algoName, _balanceClasses, _category, _defaultThreshold, _h2oVersion, _modelAttributes, _modelClassDistrib, _modelDescriptor, _mojo_version, _nclasses, _nfeatures, _priorClassDistrib, _reproducibilityInformation, _supervised, _uuid
_domains, _names, _offsetColumn, _responseColumn
Modifier | Constructor and Description |
---|---|
protected |
SharedTreeMojoModel(java.lang.String[] columns,
java.lang.String[][] domains,
java.lang.String responseColumn) |
Modifier and Type | Method and Description |
---|---|
SharedTreeGraph |
_computeGraph(int treeId)
Deprecated.
|
boolean |
calibrateClassProbabilities(double[] preds)
Subclasses implement calibration of class probabilities.
|
SharedTreeGraph |
computeGraph(int treeId) |
SharedTreeGraph |
computeGraph(int treeToPrint,
ConvertTreeOptions options)
Compute a graph of the forest.
|
static SharedTreeSubgraph |
computeTreeGraph(int treeNum,
java.lang.String treeName,
byte[] tree,
byte[] auxTreeInfo,
java.lang.String[] names,
java.lang.String[][] domains) |
static SharedTreeSubgraph |
computeTreeGraph(int treeNum,
java.lang.String treeName,
byte[] tree,
byte[] auxTreeInfo,
java.lang.String[] names,
java.lang.String[][] domains,
ConvertTreeOptions options) |
SharedTreeGraph |
convert(int treeNumber,
java.lang.String treeClass) |
SharedTreeGraph |
convert(int treeNumber,
java.lang.String treeClass,
ConvertTreeOptions options)
Converts internal tree representation to a shared representation.
|
static int |
findMaxNodeId(byte[] auxTreeInfo) |
double[] |
getCalibGlmBeta() |
CategoricalEncoding |
getCategoricalEncoding()
Return type of encoding expected by the model implementation.
|
static java.lang.String |
getDecisionPath(double leafAssignment) |
java.lang.String[] |
getDecisionPath(double[] row) |
static <T> T |
getDecisionPath(double leafAssignment,
SharedTreeMojoModel.DecisionPathTracker<T> tr) |
java.lang.String[] |
getDecisionPathNames() |
SharedTreeMojoModel.LeafNodeAssignments |
getLeafNodeAssignments(double[] row) |
static int |
getLeafNodeId(double leafAssignment,
byte[] auxTree) |
int |
getNTreeGroups() |
int |
getNTreesPerGroup() |
java.lang.String[][] |
getOrigDomainValues()
Returns original domain values for all columns including response column.
|
java.lang.String[] |
getOrigNames()
The original names of all columns used, including response and offset columns.
|
double[] |
getOrigProjectionArray()
Returns original Eigen encoder projections array for all columns.
|
protected void |
postInit() |
static java.util.Map<java.lang.Integer,SharedTreeMojoModel.AuxInfo> |
readAuxInfos(byte[] auxTreeInfo) |
protected void |
scoreAllTrees(double[] row,
double[] preds)
Score all trees and fill in the `preds` array.
|
void |
scoreSingleTree(double[] row,
int index,
double[] preds)
Generates a (per-class) prediction using only a single tree.
|
double[] |
scoreStagedPredictions(double[] row,
int predsLength)
Returns staged predictions of tree algorithms (prediction probabilities of trees per iteration).
|
static double |
scoreTree(byte[] tree,
double[] row,
boolean computeLeafAssignment,
java.lang.String[][] domains)
Highly efficient (critical path) tree scoring
Given a tree (in the form of a byte array) and the row of input data, compute either this tree's
predicted value when `computeLeafAssignment` is false, or the the decision path within the tree (but no more
than 64 levels) when `computeLeafAssignment` is true.
|
static double |
scoreTree(byte[] tree,
double[] row,
int nclasses,
boolean computeLeafAssignment,
java.lang.String[][] domains)
Deprecated.
use
scoreTree(byte[], double[], boolean, String[][]) instead. |
static double |
scoreTree0(byte[] tree,
double[] row,
boolean computeLeafAssignment)
SET IN STONE FOR MOJO VERSION "1.00" - DO NOT CHANGE
|
static double |
scoreTree0(byte[] tree,
double[] row,
int nclasses,
boolean computeLeafAssignment)
Deprecated.
use
scoreTree0(byte[], double[], boolean) instead. |
static double |
scoreTree1(byte[] tree,
double[] row,
boolean computeLeafAssignment)
SET IN STONE FOR MOJO VERSION "1.10" - DO NOT CHANGE
|
static double |
scoreTree1(byte[] tree,
double[] row,
int nclasses,
boolean computeLeafAssignment)
Deprecated.
use
scoreTree1(byte[], double[], boolean) instead. |
void |
scoreTreeRange(double[] row,
int fromIndex,
int toIndex,
double[] preds)
Generates (partial, per-class) predictions using only trees from a given range.
|
byte[] |
treeBytes(int groupIndex,
int classIndex) |
static java.lang.String |
treeName(int groupIndex,
int classIndex,
java.lang.String[] domainValues) |
abstract double[] |
unifyPreds(double[] row,
double offset,
double[] preds)
Transforms tree predictions into the final model predictions.
|
static void |
writeUpdatedAuxInfos(byte[] origAux,
java.util.Map<java.lang.Integer,SharedTreeMojoModel.AuxInfo> updatedAuxInfos,
java.nio.ByteBuffer bb) |
getModelCategory, getUUID, isSupervised, load, load, load, nclasses, nfeatures
bitSetContains, bitSetIsInRange, convertDouble2Float, correctProbabilities, createAuxKey, features, GBM_rescale, getColIdx, getDomainValues, getDomainValues, getDomainValues, getHeader, getModelCategories, getNames, getNumClasses, getNumCols, getNumResponseClasses, getOffsetName, getOrigNumCols, getOutputDomains, getOutputNames, getPrediction, getPredictionBinomial, getPredictionMultinomial, getPredsSize, getPredsSize, getResponseIdx, getResponseName, GLM_identityInv, GLM_inverseInv, GLM_logInv, GLM_logitInv, GLM_ologitInv, GLM_tweedieInv, img2pixels, internal_threadSafeInstance, isAutoEncoder, isClassifier, KMeans_closest, KMeans_distance, KMeans_distance, KMeans_distances, Kmeans_preprocessData, Kmeans_preprocessData, KMeans_simplex, log_rescale, mapEnum, nCatFeatures, requiresOffset, score0, score0, setCats, setCats, setInput, setInput
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getInitF
protected int _ntree_groups
_ntree_groups
is the number of trees requested by the user. For
binomial case or regression this is also the total number of trees
trained; however in multinomial case each requested "tree" is actually
represented as a group of trees, with _ntrees_per_group
trees
in each group. Each of these individual trees assesses the likelihood
that a given observation belongs to class A, B, C, etc. of a
multiclass response.protected int _ntrees_per_group
protected byte[][] _compressed_trees
byte[]
array. The
trees are logically grouped into a rectangular grid of dimensions
_ntree_groups
x _ntrees_per_group
, however physically
they are stored as 1-dimensional list, and an [i, j]
logical
tree is mapped to the index treeIndex(int, int)
.protected byte[][] _compressed_trees_aux
byte[]
array.protected double[] _calib_glm_beta
protected java.lang.String _genmodel_encoding
protected java.lang.String[] _orig_names
protected java.lang.String[][] _orig_domain_values
protected double[] _orig_projection_array
public static final int __INTERNAL_MAX_TREE_DEPTH
protected SharedTreeMojoModel(java.lang.String[] columns, java.lang.String[][] domains, java.lang.String responseColumn)
protected void postInit()
public final int getNTreeGroups()
getNTreeGroups
in interface TreeBackedMojoModel
public final int getNTreesPerGroup()
getNTreesPerGroup
in interface TreeBackedMojoModel
@Deprecated public static double scoreTree0(byte[] tree, double[] row, int nclasses, boolean computeLeafAssignment)
scoreTree0(byte[], double[], boolean)
instead.@Deprecated public static double scoreTree1(byte[] tree, double[] row, int nclasses, boolean computeLeafAssignment)
scoreTree1(byte[], double[], boolean)
instead.@Deprecated public static double scoreTree(byte[] tree, double[] row, int nclasses, boolean computeLeafAssignment, java.lang.String[][] domains)
scoreTree(byte[], double[], boolean, String[][])
instead.public static double scoreTree(byte[] tree, double[] row, boolean computeLeafAssignment, java.lang.String[][] domains)
public CategoricalEncoding getCategoricalEncoding()
GenModel
getCategoricalEncoding
in interface IGeneratedModel
getCategoricalEncoding
in class GenModel
public java.lang.String[] getOrigNames()
GenModel
getOrigNames
in interface IGeneratedModel
getOrigNames
in class GenModel
public double[] getOrigProjectionArray()
GenModel
getOrigProjectionArray
in interface IGeneratedModel
getOrigProjectionArray
in class GenModel
public java.lang.String[][] getOrigDomainValues()
IGeneratedModel
getOrigDomainValues
in interface IGeneratedModel
getOrigDomainValues
in class GenModel
public static <T> T getDecisionPath(double leafAssignment, SharedTreeMojoModel.DecisionPathTracker<T> tr)
public static java.lang.String getDecisionPath(double leafAssignment)
public static int getLeafNodeId(double leafAssignment, byte[] auxTree)
public SharedTreeGraph computeGraph(int treeToPrint, ConvertTreeOptions options)
public SharedTreeGraph computeGraph(int treeId)
@Deprecated public SharedTreeGraph _computeGraph(int treeId)
public static SharedTreeSubgraph computeTreeGraph(int treeNum, java.lang.String treeName, byte[] tree, byte[] auxTreeInfo, java.lang.String[] names, java.lang.String[][] domains)
public static SharedTreeSubgraph computeTreeGraph(int treeNum, java.lang.String treeName, byte[] tree, byte[] auxTreeInfo, java.lang.String[] names, java.lang.String[][] domains, ConvertTreeOptions options)
public static java.util.Map<java.lang.Integer,SharedTreeMojoModel.AuxInfo> readAuxInfos(byte[] auxTreeInfo)
public static int findMaxNodeId(byte[] auxTreeInfo)
public static void writeUpdatedAuxInfos(byte[] origAux, java.util.Map<java.lang.Integer,SharedTreeMojoModel.AuxInfo> updatedAuxInfos, java.nio.ByteBuffer bb)
public static java.lang.String treeName(int groupIndex, int classIndex, java.lang.String[] domainValues)
protected void scoreAllTrees(double[] row, double[] preds)
public abstract double[] unifyPreds(double[] row, double offset, double[] preds)
row
- input row.offset
- offset.preds
- final output, same structure as of GenModel.score0(double[], double[])
.public final void scoreSingleTree(double[] row, int index, double[] preds)
row
- input rowindex
- index of the tree (0..N-1)preds
- array of partial predictions.public final void scoreTreeRange(double[] row, int fromIndex, int toIndex, double[] preds)
row
- input rowfromIndex
- low endpoint (inclusive) of the tree rangetoIndex
- high endpoint (exclusive) of the tree rangepreds
- array of partial predictions.
To get final predictions pass the result to unifyPreds(double[], double, double[])
.public java.lang.String[] getDecisionPathNames()
public SharedTreeMojoModel.LeafNodeAssignments getLeafNodeAssignments(double[] row)
getLeafNodeAssignments
in interface TreeBackedMojoModel
public java.lang.String[] getDecisionPath(double[] row)
getDecisionPath
in interface TreeBackedMojoModel
public final byte[] treeBytes(int groupIndex, int classIndex)
public static double scoreTree0(byte[] tree, double[] row, boolean computeLeafAssignment)
tree
- row
- computeLeafAssignment
- public static double scoreTree1(byte[] tree, double[] row, boolean computeLeafAssignment)
tree
- row
- computeLeafAssignment
- public boolean calibrateClassProbabilities(double[] preds)
GenModel
calibrateClassProbabilities
in class GenModel
public double[] getCalibGlmBeta()
getCalibGlmBeta
in interface PlattScalingMojoHelper.MojoModelWithCalibration
public SharedTreeGraph convert(int treeNumber, java.lang.String treeClass)
convert
in interface SharedTreeGraphConverter
public SharedTreeGraph convert(int treeNumber, java.lang.String treeClass, ConvertTreeOptions options)
SharedTreeGraphConverter
convert
in interface SharedTreeGraphConverter
treeNumber
- Number of the tree in the model to converttreeClass
- Tree's class. If not specified, all the classes form a forest in the resulting SharedTreeGraph
options
- Allows to fine-tune the conversion process (eg. disable some internal consistency self-checks)SharedTreeGraph
containing a single tree or a forest of multiple trees.public double[] scoreStagedPredictions(double[] row, int predsLength)
row
- Input row.predsLength
- Length of prediction result.