ppforest2 v0.1.3
Projection Pursuit Decision Trees and Random Forests
Loading...
Searching...
No Matches
IO.hpp
Go to the documentation of this file.
1
5#pragma once
6
8
9#include "utils/Invariant.hpp"
10
11#include <nlohmann/json.hpp>
12#include <string>
13
14namespace ppforest2::io {
15 using ErrorHandler = void (*)(bool, std::string const&);
16
21 void check_file_exists(std::string const& path);
22
27 void check_file_not_exists(std::string const& path);
28
33 void check_dir_not_exists(std::string const& path);
34}
35
42 std::string ensure_extension(std::string const& path);
43
52 nlohmann::json read_file(std::string const& path, ErrorHandler on_error = invariant);
53
62 void write_file(nlohmann::json const& data, std::string const& path, ErrorHandler on_error = invariant);
63}
64
72 void write_file(std::string const& content, std::string const& path, ErrorHandler on_error = invariant);
73}
74
90 stats::DataPacket read(std::string const& filename);
91
105 stats::DataPacket read(std::string const& filename, types::Mode mode);
106
121
141 stats::DataPacket read_sorted(std::string const& filename);
142
156 stats::DataPacket read_sorted(std::string const& filename, types::Mode mode);
157
163 void write(stats::DataPacket const& data, std::string const& filename);
164
173 struct FeatureSet {
176 std::vector<std::vector<std::string>> raw_rows;
177 };
178
191 FeatureSet read_features_from_string(std::string const& content);
192}
void invariant(bool condition, char const *message)
Runtime assertion that throws on failure.
Definition IO.hpp:75
FeatureSet read_features_from_string(std::string const &content)
Parse a feature-only CSV from an in-memory string.
void write(stats::DataPacket const &data, std::string const &filename)
Write a DataPacket to a CSV file (features followed by label, no header).
types::OutcomeVector remap_labels(stats::DataPacket const &data, types::Names const &target_groups)
Re-encode data.y label codes into a target label space.
stats::DataPacket read_sorted(std::string const &filename)
Read a CSV file and sort rows ascending by the response column.
stats::DataPacket read(std::string const &filename)
Read a CSV file into a DataPacket.
Definition IO.hpp:36
nlohmann::json read_file(std::string const &path, ErrorHandler on_error=invariant)
Read a JSON file and parse its contents.
std::string ensure_extension(std::string const &path)
Ensure a file path ends with the ".json" extension.
void write_file(nlohmann::json const &data, std::string const &path, ErrorHandler on_error=invariant)
Write a JSON object to a file (pretty-printed with indent 2).
Definition IO.hpp:65
void write_file(std::string const &content, std::string const &path, ErrorHandler on_error=invariant)
Write a string to a file.
Definition Color.hpp:31
void check_file_exists(std::string const &path)
Exit with an error if a file does not exist at the given path.
void check_dir_not_exists(std::string const &path)
Exit with an error if a directory already exists at the given path.
void(*)(bool, std::string const &) ErrorHandler
Definition IO.hpp:15
void check_file_not_exists(std::string const &path)
Exit with an error if a file already exists at the given path.
std::vector< std::string > Names
Vector of name strings — used uniformly for class labels (group_names[i] is the label for GroupId == ...
Definition Types.hpp:59
Eigen::Matrix< Feature, Eigen::Dynamic, Eigen::Dynamic > FeatureMatrix
Dynamic-size matrix of feature values.
Definition Types.hpp:43
Eigen::Matrix< Outcome, Eigen::Dynamic, 1 > OutcomeVector
Dynamic-size column vector of predictions.
Definition Types.hpp:52
Mode
Training mode.
Definition Types.hpp:68
Result of parsing a feature-only CSV (no response column).
Definition IO.hpp:173
std::vector< std::vector< std::string > > raw_rows
Definition IO.hpp:176
types::FeatureMatrix x
Definition IO.hpp:174
types::Names feature_names
Definition IO.hpp:175
Bundled dataset: features, response, and group labels.
Definition DataPacket.hpp:19