This is an example of how to use the netdem library.
using namespace std;
void TestNetSPF() {
arma::mat dataset;
bool loadedDataset = mlpack::data::Load("dataset_SPF.txt", dataset, true);
if (!loadedDataset) {
cout << "loading data erros ..." << endl;
return;
}
cout << "finished loading data ..." << endl;
arma::mat test_data = dataset;
int num_x{3}, num_y{3};
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(
"ann_SPF.xml",
"SPF");
cout << "finished loading ann model ..." << endl;
auto pred_y = model.
Predict(test_x);
for (int i = 0; i < num_y; i++) {
double test_accuracy = MLPackUtils::GetMAE(pred_y.row(i), test_y.row(i));
cout << "test mae: "
<< "comp " << i << ": " << test_accuracy << endl;
}
arma::mat joined_yy = std::move(arma::join_cols(pred_y, test_y));
mlpack::data::Save("pred_vs_true_SPF.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