Overview / Machine learning

Ml::Trees

Beta

Loads a tree model trained in LightGBM or XGBoost and predicts with the same numbers as the source library. The model is converted once by the <code>etl-trees</code> tool to a memory-mapped format, with no parsing at load time.

Optional module: turn it on with -DETHEREAL_ML_TREES=ONInclude #include <ethereal/cpp/ml/trees/tree_format.hpp>C layer

tree_format.hpp

#include <ethereal/cpp/ml/trees/tree_format.hpp>

File format of a tree model ('.etltree').

Fixed width, little-endian, explicit padding. The file is mapped and used as is, with no parsing step.

Layout: the header (96 bytes), the section table (24 bytes per section), then the sections, each aligned to 16 bytes.

Sections:

  • TREES: u32 per tree, the output (class) the tree adds to.
  • NODES: the nodes (16 bytes each), in global level order.
  • LEAF_VALUES: f64 per leaf.
  • FEATURE_NAMES: u32 offsets[n+1], then the name bytes (UTF-8, no terminator).
  • FEATURE_TYPES: u8 per feature, 0 numeric, 1 categorical.
  • CATEGORY_WORDS: the category sets. Per node, a u32 count and the words.
  • LEAF_IDS: u32 per leaf, its number in the source library (for 'LeafIndices').
  • NODE_COVERS: f64 per node, how many training samples went through it (for the contributions).
  • BASE_SCORES: f64 per output, the starting margin of each output when it is not the same for all of them (XGBoost multiclass stores one per class). Required when present, since a reader that skipped it would give wrong margins.

An unknown section is skipped when optional. An unknown required section makes the model fail with 'eUnsupported'. This lets a future format add data without an old client reading it wrong.

Global level order: the roots of all trees come first (tree i is node i), then the level 1 nodes of all trees, and so on. The two children of a node sit side by side (right = left + 1). The top levels of all trees, which every prediction goes through, stay together in the cache. It also gives a cheap proof that the file is a forest. Walking the nodes in order, the children of the internal nodes must show up in the same order, two by two. Each node then has a single parent, and there are no cycles or shared subtrees (which a hostile file would use to make the descent exponential).

A leaf points to itself ('uLeft' is its own index). The descent always takes 'uMaxDepth' steps with no branch. On a leaf, the next step stays where it is.

const

TREE_MAGIC

Ethereal::Ml::Trees#
constexpr ETL_UINT32 TREE_MAGIC = 0x544C5445u;

'ETLT' in little-endian.

const

TREE_FORMAT_VERSION

Ethereal::Ml::Trees#
constexpr ETL_UINT16 TREE_FORMAT_VERSION = 1u;

Format version this code writes and reads.

const

TREE_HEADER_SIZE

Ethereal::Ml::Trees#
constexpr ETL_UINT32 TREE_HEADER_SIZE = 96u;

Size of the file header, in bytes.

const

TREE_SECTION_ENTRY_SIZE

Ethereal::Ml::Trees#
constexpr ETL_UINT32 TREE_SECTION_ENTRY_SIZE = 24u;

Size of one section table entry, in bytes.

const

TREE_SECTION_ALIGN

Ethereal::Ml::Trees#
constexpr ETL_UINT32 TREE_SECTION_ALIGN = 16u;

Alignment of every section, in bytes.

const

TREE_MAX_DEPTH

Ethereal::Ml::Trees#
constexpr ETL_UINT32 TREE_MAX_DEPTH = 64u;

Maximum depth of a tree.

const

TREE_MAX_INDEX

Ethereal::Ml::Trees#
constexpr ETL_UINT32 TREE_MAX_INDEX = 0x00FFFFFFu;

Feature, leaf and category indices fit in 24 bits.

enum

EObjective

Ethereal::Ml::Trees#
C++
enum class   EObjective : ETL_UINT8
{
    /// @brief  Binary classification.
    eBinary = 0,

    /// @brief  Multiclass classification.
    eMulticlass,

    /// @brief  Regression.
    eRegression,

    /// @brief  Ranking.
    eRanking,

    /// @brief  An Isolation Forest (Ml::Anomaly). The leaves are path lengths.
    eAnomaly
};

What the model learned to predict.

enum

ETransform

Ethereal::Ml::Trees#
C++
enum class   ETransform : ETL_UINT8
{
    /// @brief  Regression, ranking, or raw margins on request.
    eIdentity = 0,

    /// @brief  Binary: 1 / (1 + exp(-scale * x)).
    eSigmoid,

    /// @brief  Multiclass.
    eSoftmax,

    /// @brief  Poisson, gamma, tweedie.
    eExp,

    /// @brief  Isolation Forest: 2^(-x). The leaves hold (depth + c(n)) / (T c(psi)),
    ///             and the margin is the normalized mean path length. The output is the
    ///             anomaly score (0.5 normal, close to 1 anomalous), the scikit-learn
    ///             'score_samples' with the sign flipped.
    eIsolation
};

What is applied to the margins to give the model output.

enum

EAccumulation

Ethereal::Ml::Trees#
C++
enum class   EAccumulation : ETL_UINT8
{
    /// @brief  Sum in double (LightGBM).
    eDouble = 0,

    /// @brief  Sum in float, tree by tree (XGBoost).
    eFloat
};

Precision used to add up the leaves.

The sum must match the source library, in the same order. LightGBM adds in double. XGBoost adds in float, tree by tree. Adding an XGBoost model in double would change the last bits.

enum

ESection

Ethereal::Ml::Trees#
C++
enum class   ESection : ETL_UINT32
{
    /// @brief  Output of each tree.
    eTrees = 1,

    /// @brief  The nodes.
    eNodes = 2,

    /// @brief  Leaf values.
    eLeafValues = 3,

    /// @brief  Feature name offsets and bytes.
    eFeatureNames = 4,

    /// @brief  Feature types.
    eFeatureTypes = 5,

    /// @brief  Category sets of the categorical nodes.
    eCategoryWords = 6,

    /// @brief  Leaf numbers in the source library.
    eLeafIds = 7,

    /// @brief  Training cover of each node.
    eNodeCovers = 8,

    /// @brief  Starting margin of each output.
    eBaseScores = 9
};

Section identifiers.

const

TREE_SECTION_REQUIRED

Ethereal::Ml::Trees#
constexpr ETL_UINT32 TREE_SECTION_REQUIRED = 1u;

Section flag: the section is required. A reader that does not know it rejects the model.

const

TREE_HAS_CATEGORICAL

Ethereal::Ml::Trees#
constexpr ETL_UINT8 TREE_HAS_CATEGORICAL = 1u;

Header flag: there are categorical nodes.

const

TREE_HAS_ZERO_MISSING

Ethereal::Ml::Trees#
constexpr ETL_UINT8 TREE_HAS_ZERO_MISSING = 2u;

Header flag: there are nodes where zero means "missing".

struct

STreeFileHeader

Ethereal::Ml::Trees#
C++
struct   STreeFileHeader   final
{
    /// @brief  TREE_MAGIC.
    ETL_UINT32    uMagic;

    /// @brief  Format version of the file.
    ETL_UINT16    uFormatVersion;

    /// @brief  Header size, in bytes.
    ETL_UINT16    uHeaderSize;

    /// @brief  EObjective, as a byte.
    ETL_UINT8    eObjective;

    /// @brief  ETransform, as a byte.
    ETL_UINT8    eTransform;

    /// @brief  EAccumulation, as a byte.
    ETL_UINT8    eAccumulation;

    /// @brief  TREE_HAS_* flags.
    ETL_UINT8    uFlags;

    /// @brief  Number of trees.
    ETL_UINT32    uTreeCount;

    /// @brief  Number of features.
    ETL_UINT32    uFeatureCount;

    /// @brief  Outputs: the classes in a multiclass model, 1 otherwise.
    ETL_UINT32    uOutputCount;

    /// @brief  Number of nodes.
    ETL_UINT32    uNodeCount;

    /// @brief  Number of leaves.
    ETL_UINT32    uLeafCount;

    /// @brief  Depth of the deepest tree.
    ETL_UINT32    uMaxDepth;

    /// @brief  Number of entries in the section table.
    ETL_UINT32    uSectionCount;

    /// @brief  Offset of the section table.
    ETL_UINT64    uSectionTableOffset;

    /// @brief  Size of the whole file.
    ETL_UINT64    uFileSize;

    /// @brief  Starting margin of each output ('base_score', already in margin space).
    ETL_DOUBLE    dBaseScore;

    /// @brief  Sigmoid scale ('sigmoid:k' in LightGBM, 1 in XGBoost).
    ETL_DOUBLE    dSigmoidScale;

    /// @brief  Hash of the feature specification the model was trained with
    ///             (Ml::Features). Zero means none.
    ETL_UINT64    uSpecHash;

    /// @brief  Reserved, zero.
    ETL_UINT8    aReserved[ 16 ];
};

The file header, exactly as stored.

struct

STreeSectionEntry

Ethereal::Ml::Trees#
C++
struct   STreeSectionEntry   final
{
    /// @brief  ESection identifier.
    ETL_UINT32    uId;

    /// @brief  TREE_SECTION_* flags.
    ETL_UINT32    uFlags;

    /// @brief  Offset of the section in the file.
    ETL_UINT64    uOffset;

    /// @brief  Size of the section, in bytes.
    ETL_UINT64    uSize;
};

One entry of the section table.

const

NODE_LEAF

Ethereal::Ml::Trees#
constexpr ETL_UINT32 NODE_LEAF = 0x01u;

Node flag: the node is a leaf. Node flags live in the low byte of 'uMeta'.

const

NODE_DEFAULT_LEFT

Ethereal::Ml::Trees#
constexpr ETL_UINT32 NODE_DEFAULT_LEFT = 0x02u;

Node flag: a missing value goes left.

const

NODE_CATEGORICAL

Ethereal::Ml::Trees#
constexpr ETL_UINT32 NODE_CATEGORICAL = 0x04u;

Node flag: the node is categorical.

const

NODE_MISSING_ZERO

Ethereal::Ml::Trees#
constexpr ETL_UINT32 NODE_MISSING_ZERO = 0x08u;

Node flag: |x| <= 1e-35 counts as missing (LightGBM).

const

NODE_MISSING_NAN

Ethereal::Ml::Trees#
constexpr ETL_UINT32 NODE_MISSING_NAN = 0x10u;

Node flag: NaN counts as missing. Without it, NaN is 0.

const

NODE_CAT_OUT_LEFT

Ethereal::Ml::Trees#
constexpr ETL_UINT32 NODE_CAT_OUT_LEFT = 0x20u;

Node flag: a category outside the known set goes left.

const

NODE_CAT_NEG_FLOAT

Ethereal::Ml::Trees#
constexpr ETL_UINT32 NODE_CAT_NEG_FLOAT = 0x40u;

Node flag: any x < 0 is "outside" (XGBoost). Without it, only int(x) < 0 is.

const

NODE_FLAG_MASK

Ethereal::Ml::Trees#
constexpr ETL_UINT32 NODE_FLAG_MASK = 0x7Fu;

All valid node flags.

struct

STreeNode

Ethereal::Ml::Trees#
C++
struct   STreeNode   final
{
    /// @brief  Column the node compares (0 on a leaf).
    ETL_UINT32    uFeature;

    /// @brief  Goes left when x <= threshold.
    float        fThreshold;

    /// @brief  Left child. The right child is the next node. On a leaf, the node itself.
    ETL_UINT32    uLeft;

    /// @brief  Flags in the low byte. The upper 24 bits hold the value index on a
    ///             leaf and the set offset on a categorical node.
    ETL_UINT32    uMeta;
};

A node, 16 bytes.

The library thresholds are converted at the source to the 'x <= threshold' form, which is exact for float inputs. The LightGBM '<= double' becomes the largest float below the threshold, and the XGBoost '< float' becomes the previous float.

tree_model.hpp

#include <ethereal/cpp/ml/trees/tree_model.hpp>

Tree model of the Ml::Trees module.

Loads without copying, predicts without allocating, and explains its predictions.

Training stays in Python (LightGBM, XGBoost). The 'etl-trees convert' tool turns the model into this format. Nobody trains in C++, and what matters on the client is a fast prediction that is always the same and comes with an explanation.

Check the feature names with 'VerifyFeatureNames'. Features swapped between training and prediction are the most common failure of ML on tables. The answers look plausible, are wrong, and nothing in the data shows it.

A missing value is passed as NaN and follows the rule of each node, which is the rule of the library that trained it (the default direction, zero as missing, NaN as zero).

enum

ELoadCheck

Ethereal::Ml::Trees#
C++
enum class   ELoadCheck : ETL_UINT8
{
    /// @brief  Everything: the header, the sections, and every node (the forest,
    ///             the indices, the depths). A broken or hostile file is rejected, and
    ///             the prediction never reads outside the model. The cost is one pass
    ///             over the nodes.
    eFull = 0,

    /// @brief  Only the header and the sections, without the pass over the nodes.
    ///             Only for a model whose origin was already checked (the ModelGuard
    ///             signature). A file with broken nodes can give wrong answers or read
    ///             out of bounds.
    eTrusted
};

How much is checked on load.

const

TREE_DENSE_MAX_DEPTH

Ethereal::Ml::Trees#
constexpr ETL_UINT32 TREE_DENSE_MAX_DEPTH = 12u;

Maximum depth of the dense descent (a complete tree of 12 levels is 4095 nodes, 32 KB).

const

ETL_UINT64

Ethereal::Ml::Trees#
constexpr ETL_UINT64 TREE_DENSE_MAX_BYTES = ETL_UINT64( 256 ) << 20;

Maximum the dense descent allocates (the nodes and the leaves).

class

CTreeModel

Ethereal::Ml::Trees#

A loaded tree model.

class CTreeModel final

It does not copy. With 'Load' the bytes belong to the caller and must outlive the model. With 'LoadFile' the model maps the file read only and unmaps it at the end. Neither of them allocates.

It has no mutable state. The predictions are 'const' and can run on several threads at the same time over the same model.

constructor

CTreeModel

#
CTreeModel() noexcept;

Default constructor. The model starts empty.

constructor

CTreeModel

#
CTreeModel( CTreeModel && Other ) noexcept;

Move constructor. Other is left empty.

operator

operator=

#
CTreeModel & operator=( CTreeModel && Other ) noexcept;

Move assignment. Other is left empty.

function

Load

#
static EStatus Load( std::span< const ETL_UINT8 > Model, CTreeModel * pOut, ELoadCheck eCheck = ELoadCheck::eFull ) noexcept;

Loads from bytes in memory. It borrows them and does not copy.

The bytes must be aligned to 16, or to 8 on 32 bit platforms (a 'std::vector' or a mapping is). An invalid model leaves pOut empty.

Model
The model bytes.
pOut
Receives the model.
eCheck
How much is checked.
eOk, or the matching failure: EStatus::eTruncated, EStatus::eBadMagic, EStatus::eVersionTooNew, EStatus::eCorrupt, EStatus::eUnsupported. EStatus::eNotLicensed when the library is not licensed.
function

LoadFile

#
static EStatus LoadFile( std::string_view sPath, CTreeModel * pOut, ELoadCheck eCheck = ELoadCheck::eFull ) noexcept;

Maps the file read only and loads it.

sPath
File path (UTF-8).
pOut
Receives the model.
eCheck
How much is checked.
eOk, eIoError, or the failures of Load. EStatus::eNotLicensed when the library is not licensed.
function

Reset

#
void Reset() noexcept;

Drops the model (and the mapping, if any).

function

Predict

#
EStatus Predict( std::span< const float > Features, float * pOut ) const noexcept;

Output of the model for one row, in a single output model (binary, regression, ranking). The margin with the model transform applied.

Features
One row, FeatureCount values.
pOut
Receives the output.
eOk. A multiclass model returns EStatus::eInvalidArgument.
function

PredictRaw

#
EStatus PredictRaw( std::span< const float > Features, std::span< float > Out ) const noexcept;

Raw margins (one per output), with no transform.

Features
One row, FeatureCount values.
Out
Receives OutputCount margins.
eOk, eNotLoaded, eFeatureMismatch or eBufferTooSmall.
function

PredictProbabilities

#
EStatus PredictProbabilities( std::span< const float > Features, std::span< float > Out ) const noexcept;

Transformed output, one per output: the probability in a binary model, the probabilities in a multiclass one (they add up to 1), the value in a regression.

Features
One row, FeatureCount values.
Out
Receives OutputCount values.
eOk, eNotLoaded, eFeatureMismatch or eBufferTooSmall.
function

PredictBatch

#
EStatus PredictBatch( const SFeatureMatrix & In, std::span< float > Out ) const noexcept;

Many rows at once. Out receives 'rows * outputs' transformed values, row by row.

This is the fast path. The rows go down the trees interleaved, so the memory wait of one row overlaps the work of another. The answer is the same, bit for bit, as 'PredictProbabilities' row by row.

In
The rows.
Out
Receives the outputs.
eOk, eNotLoaded, eFeatureMismatch, eInvalidArgument or eBufferTooSmall.
function

PredictBatchRaw

#
EStatus PredictBatchRaw( const SFeatureMatrix & In, std::span< float > Out ) const noexcept;

Same as PredictBatch, with the raw margins.

In
The rows.
Out
Receives the margins.
Same as PredictBatch.
function

EnableDenseDescent

#
EStatus EnableDenseDescent() noexcept;

Compiles the trees for the dense descent, the single row descent with AVX2.

Each tree is completed to the model depth. Nodes take 8 bytes ({feature and flags, threshold}). The children of k are at 2k+1 and 2k+2, so neither the child nor the flags are read (two gathers per level instead of four). With up to 16 features, the feature is read by a register permute (no fifth gather).

This is the only call that allocates: '(2^depth - 1) 8' bytes per tree, and '2^depth 8' for the leaves (about 300 KB for 100 trees of depth 8). Call it after the load and before the predictions, never concurrently with them. A new load undoes it. The answer is the same, bit for bit, as the regular descent (same node rule, same sum order). Without AVX2 on the processor the predictions keep the regular descent. Outside 64 bit x86 it returns EStatus::eUnsupported.

Meant for shallow, numeric trees (the Isolation Forest, fixed depth models). The gain is measured in 'ml.anomaly.measurements'.

eOk, EStatus::eNotLoaded, EStatus::eUnsupported (categorical nodes, depth 0 or above TREE_DENSE_MAX_DEPTH, or more than TREE_DENSE_MAX_BYTES), or EStatus::eOutOfMemory.
function

DenseDescentEnabled

#
bool DenseDescentEnabled() const noexcept

The dense descent is compiled (and runs, when AVX2 is present).

function

Contributions

#
EStatus Contributions( std::span< const float > Features, std::span< float > Out ) const noexcept;

Contribution of each feature (exact TreeSHAP), per output.

Writes 'outputs * (features + 1)' values. The last value of each output is the expected value, and they add up to the raw margin.

This is what turns a score into an explanation. A ban decision has to be justified, and "the model said so" is no justification. It needs the node covers section. A model without it returns EStatus::eUnsupported.

Features
One row, FeatureCount values.
Out
Receives the contributions.
eOk, eNotLoaded, eFeatureMismatch, eBufferTooSmall or eUnsupported.
function

LeafIndices

#
EStatus LeafIndices( std::span< const float > Features, std::span< ETL_UINT32 > Out ) const noexcept;

Leaf reached in each tree, numbered as in the source library.

Features
One row, FeatureCount values.
Out
Receives TreeCount indices.
eOk, eNotLoaded, eFeatureMismatch or eBufferTooSmall.
function

IsLoaded

#
bool IsLoaded() const noexcept

A model is loaded.

function

FeatureCount

#
std::size_t FeatureCount() const noexcept

Number of features.

function

OutputCount

#
std::size_t OutputCount() const noexcept

Number of outputs.

function

TreeCount

#
std::size_t TreeCount() const noexcept

Number of trees.

function

NodeCount

#
std::size_t NodeCount() const noexcept

Number of nodes.

function

MaxDepth

#
ETL_UINT32 MaxDepth() const noexcept

Depth of the deepest tree.

function

Objective

#
EObjective Objective() const noexcept

What the model predicts.

function

Transform

#
ETransform Transform() const noexcept

Transform applied to the margins.

function

SpecHash

#
ETL_UINT64 SpecHash() const noexcept

Hash of the feature specification (zero when none).

function

FeatureName

#
std::string_view FeatureName( std::size_t u ) const noexcept;

Name of feature u (empty when out of range).

function

IsCategorical

#
bool IsCategorical( std::size_t u ) const noexcept;

Feature u is categorical.

function

VerifyFeatureNames

#
EStatus VerifyFeatureNames( std::span< const std::string_view > Names ) const noexcept;

Checks that the names (and their order) are exactly these.

Names
Expected names, in order.
eOk, eNotLoaded, or EStatus::eFeatureMismatch when the count or any name differs.
function

Nodes

#
const STreeNode * Nodes() const noexcept

The nodes.

function

LeafValues

#
const ETL_DOUBLE * LeafValues() const noexcept

The leaf values.

function

CategoryWords

#
const ETL_UINT32 * CategoryWords() const noexcept

The category sets.

function

TreeOutputs

#
const ETL_UINT32 * TreeOutputs() const noexcept

Output of each tree.

function

CategoryWordCount

#
ETL_UINT64 CategoryWordCount() const noexcept

Number of words in the category sets section.

function

Accumulation

#
EAccumulation Accumulation() const noexcept

Precision of the leaf sum.

function

LeafCount

#
ETL_UINT32 LeafCount() const noexcept

Number of leaves.

function

SigmoidScale

#
ETL_DOUBLE SigmoidScale() const noexcept

Sigmoid scale.

function

LeafIds

#
const ETL_UINT32 * LeafIds() const noexcept

Number of each leaf in the source library (null without the section).

function

NodeCovers

#
const ETL_DOUBLE * NodeCovers() const noexcept

Cover of each node (null without the section).

function

BaseScores

#
const ETL_DOUBLE * BaseScores() const noexcept

Starting margins per output (null when the file has one for all).

function

BaseScore

#
ETL_DOUBLE BaseScore( const std::size_t k ) const noexcept

Starting margin of output k.

function

PredictRawReference

Ethereal::Ml::Trees#
EStatus PredictRawReference( const CTreeModel & Model, std::span< const float > Features, std::span< float > Out ) noexcept;

The oracle: the simple descent, with branches, node by node, with no optimization.

It exists for the tests. The optimized descents must give exactly what this one gives, bit for bit.

Model
The model.
Features
One row, FeatureCount values.
Out
Receives the raw margins (one per output).
eOk, eNotLoaded, eFeatureMismatch or eBufferTooSmall.

tree_writer.hpp

#include <ethereal/cpp/ml/trees/tree_writer.hpp>

Writer of the '.etltree' format.

Takes a description of the trees (as the converter reads it from LightGBM or XGBoost) and writes the '.etltree' file.

It allocates freely. It runs in the converter and in the tests, never in the prediction. The description nodes are linked by index, in any order. The writer puts them in the global level order the format requires, and measures the depth.

struct

SNodeDesc

Ethereal::Ml::Trees#
C++
struct   SNodeDesc   final
{
    /// @brief  The node is a leaf.
    bool                    bLeaf = false;

    /// @brief  Internal node: the feature it compares.
    ETL_UINT32                uFeature = 0u;

    /// @brief  Internal node: the threshold, already in the 'x <= threshold' form.
    float                    fThreshold = 0.0f;

    /// @brief  Internal node: the NODE_* flags.
    ETL_UINT32                uFlags = 0u;

    /// @brief  Internal node: left child (index in the same tree).
    ETL_INT32                iLeft = -1;

    /// @brief  Internal node: right child (index in the same tree).
    ETL_INT32                iRight = -1;

    /// @brief  Categorical node: the words of the set of categories that go left
    ///             (bit i of word i/32).
    std::vector< ETL_UINT32 >    Categories;

    /// @brief  Leaf: the value.
    ETL_DOUBLE                dLeafValue = 0.0;

    /// @brief  Leaf: its number in the source library.
    ETL_UINT32                uLeafId = 0u;

    /// @brief  How many training samples went through here (the LightGBM count,
    ///             the XGBoost sum of hessians). Negative when unknown.
    ETL_DOUBLE                dCover = -1.0;
};

One node of the description.

struct

STreeDesc

Ethereal::Ml::Trees#
C++
struct   STreeDesc   final
{
    /// @brief  The nodes, in any order.
    std::vector< SNodeDesc >    Nodes;

    /// @brief  Index of the root.
    ETL_UINT32                    uRoot = 0u;

    /// @brief  Output (class) the tree adds to.
    ETL_UINT32                    uOutput = 0u;
};

One tree: the nodes and the root.

struct

SModelDesc

Ethereal::Ml::Trees#
C++
struct   SModelDesc   final
{
    /// @brief  What the model predicts.
    EObjective                    eObjective = EObjective::eBinary;

    /// @brief  Transform applied to the margins.
    ETransform                    eTransform = ETransform::eSigmoid;

    /// @brief  Precision of the leaf sum.
    EAccumulation                eAccumulation = EAccumulation::eDouble;

    /// @brief  Number of outputs.
    ETL_UINT32                    uOutputCount = 1u;

    /// @brief  Starting margin shared by all outputs.
    ETL_DOUBLE                    dBaseScore = 0.0;

    /// @brief  Starting margin of each output, when it differs between outputs
    ///             (empty: the same 'dBaseScore' for all).
    std::vector< ETL_DOUBLE >    BaseScores;

    /// @brief  Sigmoid scale.
    ETL_DOUBLE                    dSigmoidScale = 1.0;

    /// @brief  Hash of the feature specification (zero when none).
    ETL_UINT64                    uSpecHash = 0u;

    /// @brief  Feature names, in column order.
    std::vector< std::string >    FeatureNames;

    /// @brief  Feature types: 0 numeric, 1 categorical.
    std::vector< ETL_UINT8 >    FeatureTypes;

    /// @brief  The trees.
    std::vector< STreeDesc >    Trees;
};

The whole model.

function

WriteTreeModel

Ethereal::Ml::Trees#
EStatus WriteTreeModel( const SModelDesc & Model, bool bCovers, std::vector< ETL_UINT8 > * pOut );

Writes the model.

Model
The model description.
bCovers
Writes the node covers section (the contributions need it). Requires the cover on every node.
pOut
Receives the file bytes.
eOk, or EStatus::eInvalidArgument for an inconsistent description (children outside the tree, cycles, features out of range, depth above TREE_MAX_DEPTH). EStatus::eNotLicensed when the library is not licensed.