This is an example of how to use the netdem library.
using namespace std;
void TestRegressorEllipsoid(int id_comp = 0) {
string root_dir = "local/examples/netdem/ann_models/ellipsoid_ellipsoid/";
arma::mat dataset;
bool loadedDataset =
mlpack::data::Load(root_dir + "dataset_resolution.txt", dataset, true);
if (!loadedDataset) {
cout << "loading data erros ..." << endl;
return;
}
for (int i = 0; i < dataset.n_cols; i++) {
auto tmp_sgn = Math::Sign(dataset(3, i));
dataset(3, i) = tmp_sgn * dataset(3, i);
dataset(4, i) = tmp_sgn * dataset(4, i);
dataset(5, i) = tmp_sgn * dataset(5, i);
dataset(6, i) = tmp_sgn * dataset(6, i);
dataset(7, i) = dataset(7, i) * 40.0;
}
cout << "finished loading data ..." << endl;
arma::mat test_data = dataset;
int num_x{7}, num_y{7};
arma::mat test_x = test_data.rows(0, num_x - 1);
arma::mat test_y = test_data.rows(num_x, num_x + num_y - 1);
cout << "finished preparing training and testing data ..." << endl;
model.
Load(root_dir +
"ann_regressor.xml",
"resolution");
cout << "finished loading ann model ..." << endl;
auto pred_y = model.
Predict(test_x);
double test_accuracy =
MLPackUtils::GetMAE(pred_y.rows(id_comp, id_comp), test_y.rows(id_comp, id_comp));
cout << "test mae: " << test_accuracy << endl;
arma::mat joined_yy = std::move(arma::join_cols(pred_y, test_y));
mlpack::data::Save(root_dir + "pred_vs_true_resolution.txt", joined_yy, false,
true, mlpack::data::FileType::CSVASCII);
}
A class that represents a feedforward neural network for regression.
Definition regression_net.hpp:21
void Load(std::string const &filename, std::string const &label)
Loads the neural network model from disk.
Definition regression_net.cpp:95
arma::mat Predict(const arma::mat &data_x)
Predicts with the neural network model using input data.
Definition regression_net.cpp:62
Definition bond_entry.hpp:7