This is an example of how to use the netdem library.
using namespace std;
void TestCodedNetSDF() {
vector<string> template_names;
ifstream file("template_dict.txt");
if (file.is_open()) {
string line;
while (getline(file, line)) {
template_names.push_back(line);
}
file.close();
} else {
cout << "file template_dict.txt not exist" << endl;
return;
}
int num_templates = template_names.size();
vector<arma::mat> dataset(num_templates);
for (int i = 0; i < template_names.size(); i++) {
bool loadedDataset = mlpack::data::Load(
template_names[i] + "/dataset_SDF.txt", dataset[i], true);
if (!loadedDataset) {
cout << "loading data erros ..." << endl;
return;
}
cout << template_names[i] << ": " << dataset[i].n_cols << " samples"
<< endl;
}
cout << "finished loading data ..." << endl;
arma::mat latent_code;
mlpack::data::Load("latent_code.txt", latent_code, false, false);
int num_latent_code = latent_code.n_cols;
model.
Load(
"ann_SDF.xml",
"SDF");
cout << "finished loading ann model ..." << endl;
for (int ii = 0; ii < num_templates; ii++) {
arma::mat test_data = dataset[ii];
int num_x{3}, num_y{1};
arma::mat test_x = test_data.rows(0, num_x - 1);
arma::mat test_y = test_data.row(num_x);
cout << "finished preparing testing data ..." << endl;
arma::mat test_x_coded(num_latent_code + test_x.n_rows, test_x.n_cols);
for (int i = 0; i < num_latent_code; i++) {
for (int j = 0; j < test_x.n_cols; j++) {
test_x_coded(i, j) = latent_code(ii, i);
}
}
for (int i = num_latent_code; i < test_x_coded.n_rows; i++) {
for (int j = 0; j < test_x.n_cols; j++) {
test_x_coded(i, j) = test_x(i - num_latent_code, j);
}
}
cout << "finished combining latent code ..." << endl;
auto pred_y = model.
Predict(test_x_coded);
double test_accuracy = MLPackUtils::GetMAE(pred_y, test_y);
cout << "test mae: " << test_accuracy << endl;
arma::mat joined_yy = std::move(arma::join_cols(pred_y, test_y));
mlpack::data::Save(template_names[ii] + "/pred_vs_true_SDF.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