NetDEM v1.0
Loading...
Searching...
No Matches
23_test_classifier_ellipsoid_plane.cpp

This is an example of how to use the netdem library.

#include "general_net.hpp"
#include "mlpack_utils.hpp"
using namespace netdem;
using namespace std;
void TestClassifierEllipsoidPlane() {
string root_dir = "local/examples/netdem/ann_models/ellipsoid_plane/";
arma::mat dataset;
bool loadedDataset =
mlpack::data::Load(root_dir + "dataset_detection.txt", dataset, true);
if (!loadedDataset) {
cout << "loading data erros ..." << endl;
return;
}
cout << "finished loading data ..." << endl;
arma::mat test_data = dataset;
int num_x{4}, 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 training and testing data ..." << endl;
GeneralNet model;
model.Load(root_dir + "ann_classifier.xml", "detection");
cout << "finished loading ann model ..." << endl;
auto pred_y = model.Classify(test_x);
double test_accuracy =
arma::accu(pred_y == test_y) * 1.0 / test_y.n_elem * 100.0;
cout << "test accuracy: " << test_accuracy << " %" << endl;
arma::mat joined_yy = std::move(arma::join_cols(pred_y, test_y));
mlpack::data::Save(root_dir + "/pred_vs_true_detection.txt", joined_yy, false,
true, mlpack::data::FileType::CSVASCII);
}
A class representing a general neural network.
Definition general_net.hpp:19
void Load(std::string const &filename, std::string const &label)
Loads a previously saved neural network model from a file.
Definition general_net.cpp:74
arma::mat Classify(const arma::mat &data_x)
Classifies input data based on the current neural network model.
Definition general_net.cpp:65
Definition bond_entry.hpp:7