ppforest2 v0.1.0
Projection Pursuit Decision Trees and Random Forests
Loading...
Searching...
No Matches
ppforest2::serialization Namespace Reference

JSON serialization and deserialization for ppforest2 models. More...

Classes

struct  Export
 A model bundled with its export metadata and optional metrics. More...
 
struct  JsonModelVisitor
 Visitor that serializes a model (Tree or Forest) to JSON. More...
 
struct  JsonNodeVisitor
 Visitor that serializes a tree node to JSON. More...
 

Typedefs

using GroupNames = std::vector<std::string>
 Group name vector for labeled serialization.
 
using json = nlohmann::json
 

Functions

std::vector< std::string > to_labels (types::ResponseVector const &predictions, std::vector< std::string > const &group_names)
 Map integer response codes to group name strings.
 
Serialization
json to_json (Model const &model)
 
json to_json (TreeNode const &node)
 
json to_json (Tree const &tree)
 
json to_json (BootstrapTree const &tree)
 
json to_json (Forest const &forest)
 
json to_json (stats::ConfusionMatrix const &cm)
 
json to_json (VariableImportance const &vi)
 
json to_json (types::FeatureMatrix const &matrix)
 
Labeled serialization (uses group names instead of integer codes)
json to_json (Model const &model, GroupNames const &group_names)
 
json to_json (TreeNode const &node, GroupNames const &group_names)
 
json to_json (Tree const &tree, GroupNames const &group_names)
 
json to_json (BootstrapTree const &tree, GroupNames const &group_names)
 
json to_json (Forest const &forest, GroupNames const &group_names)
 
json to_json (stats::ConfusionMatrix const &cm, GroupNames const &group_names)
 
Deserialization
template<typename T>
from_json (json const &j)
 Deserialize from a model block (integer labels only).
 
template<>
Tree from_json< Tree > (json const &j)
 
template<>
Forest from_json< Forest > (json const &j)
 
template<>
stats::ConfusionMatrix from_json< stats::ConfusionMatrix > (json const &j)
 
template<>
VariableImportance from_json< VariableImportance > (json const &j)
 
Stream operators
std::ostream & operator<< (std::ostream &os, TreeNode const &node)
 
std::ostream & operator<< (std::ostream &os, TreeCondition const &condition)
 
std::ostream & operator<< (std::ostream &os, TreeResponse const &response)
 
std::ostream & operator<< (std::ostream &os, Tree const &tree)
 
std::ostream & operator<< (std::ostream &os, Forest const &forest)
 
template<typename V>
std::ostream & operator<< (std::ostream &ostream, std::vector< V > const &vec)
 
template<typename V, typename C1, typename C2>
std::ostream & operator<< (std::ostream &ostream, std::set< V, C1, C2 > const &set)
 
template<typename K, typename V>
std::ostream & operator<< (std::ostream &ostream, std::map< K, V > const &map)
 
template<typename V>
std::ostream & operator<< (std::ostream &ostream, std::map< int, V > const &map)
 

Detailed Description

JSON serialization and deserialization for ppforest2 models.

Uses nlohmann/json. Provides to_json() for serializing trees, forests, confusion matrices, and variable importance to JSON. Deserialization uses j.get<T>() via nlohmann ADL:

// Serialize and write to file:
auto j = serialization::to_json(forest);
io::json::write_file(j, "model.json");
// Read a full export (model + config + meta):
auto j2 = io::json::read_file("model.json");
auto e = j2.get<Export<Forest>>(); // e.model, e.groups, e.spec
// Read bare model block (integer labels):
Tree tree = model_json.get<Tree>();
json to_json(Model const &model)
A single projection pursuit decision tree.
Definition Tree.hpp:26
A model bundled with its export metadata and optional metrics.
Definition Json.hpp:54

Typedef Documentation

◆ GroupNames

using ppforest2::serialization::GroupNames = std::vector<std::string>

Group name vector for labeled serialization.

◆ json

using ppforest2::serialization::json = nlohmann::json

Function Documentation

◆ from_json()

template<typename T>
T ppforest2::serialization::from_json ( json const & j)

Deserialize from a model block (integer labels only).

For labeled JSON (string values/groups), use j.get<Export<T>>() instead. Call via serialization::from_json<T>(j) or j.get<T>().

◆ from_json< Forest >()

◆ from_json< stats::ConfusionMatrix >()

◆ from_json< Tree >()

template<>
Tree ppforest2::serialization::from_json< Tree > ( json const & j)

◆ from_json< VariableImportance >()

◆ operator<<() [1/9]

std::ostream & ppforest2::serialization::operator<< ( std::ostream & os,
Forest const & forest )

◆ operator<<() [2/9]

std::ostream & ppforest2::serialization::operator<< ( std::ostream & os,
Tree const & tree )

◆ operator<<() [3/9]

std::ostream & ppforest2::serialization::operator<< ( std::ostream & os,
TreeCondition const & condition )

◆ operator<<() [4/9]

std::ostream & ppforest2::serialization::operator<< ( std::ostream & os,
TreeNode const & node )

◆ operator<<() [5/9]

std::ostream & ppforest2::serialization::operator<< ( std::ostream & os,
TreeResponse const & response )

◆ operator<<() [6/9]

template<typename V>
std::ostream & ppforest2::serialization::operator<< ( std::ostream & ostream,
std::map< int, V > const & map )

◆ operator<<() [7/9]

template<typename K, typename V>
std::ostream & ppforest2::serialization::operator<< ( std::ostream & ostream,
std::map< K, V > const & map )

◆ operator<<() [8/9]

template<typename V, typename C1, typename C2>
std::ostream & ppforest2::serialization::operator<< ( std::ostream & ostream,
std::set< V, C1, C2 > const & set )

◆ operator<<() [9/9]

template<typename V>
std::ostream & ppforest2::serialization::operator<< ( std::ostream & ostream,
std::vector< V > const & vec )

◆ to_json() [1/14]

json ppforest2::serialization::to_json ( BootstrapTree const & tree)

◆ to_json() [2/14]

json ppforest2::serialization::to_json ( BootstrapTree const & tree,
GroupNames const & group_names )

◆ to_json() [3/14]

json ppforest2::serialization::to_json ( Forest const & forest)

◆ to_json() [4/14]

json ppforest2::serialization::to_json ( Forest const & forest,
GroupNames const & group_names )

◆ to_json() [5/14]

json ppforest2::serialization::to_json ( Model const & model)

◆ to_json() [6/14]

json ppforest2::serialization::to_json ( Model const & model,
GroupNames const & group_names )

◆ to_json() [7/14]

json ppforest2::serialization::to_json ( stats::ConfusionMatrix const & cm)

◆ to_json() [8/14]

json ppforest2::serialization::to_json ( stats::ConfusionMatrix const & cm,
GroupNames const & group_names )

◆ to_json() [9/14]

json ppforest2::serialization::to_json ( Tree const & tree)

◆ to_json() [10/14]

json ppforest2::serialization::to_json ( Tree const & tree,
GroupNames const & group_names )

◆ to_json() [11/14]

json ppforest2::serialization::to_json ( TreeNode const & node)

◆ to_json() [12/14]

json ppforest2::serialization::to_json ( TreeNode const & node,
GroupNames const & group_names )

◆ to_json() [13/14]

json ppforest2::serialization::to_json ( types::FeatureMatrix const & matrix)

◆ to_json() [14/14]

json ppforest2::serialization::to_json ( VariableImportance const & vi)

◆ to_labels()

std::vector< std::string > ppforest2::serialization::to_labels ( types::ResponseVector const & predictions,
std::vector< std::string > const & group_names )

Map integer response codes to group name strings.