Loading .gitignore +0 −1 Original line number Diff line number Diff line Loading @@ -21,5 +21,4 @@ cv_* /include/ /cmake-build-*/ docker/kitware-archive.sh src/external/pybind11 build_third_party.bash 100755 → 100644 +0 −0 File mode changed from 100755 to 100644. View file docker/kitware-archive.sh 0 → 100644 +103 −0 Original line number Diff line number Diff line #!/bin/sh set -eu help() { echo "Usage: $0 [--release <ubuntu-release>] [--rc]" > /dev/stderr } doing= rc= release= help= for opt in "$@" do case "${doing}" in release) release="${opt}" doing= ;; "") case "${opt}" in --rc) rc=1 ;; --release) doing=release ;; --help) help=1 ;; esac ;; esac done if [ -n "${doing}" ] then echo "--${doing} option given no argument." > /dev/stderr echo > /dev/stderr help exit 1 fi if [ -n "${help}" ] then help exit fi if [ -z "${release}" ] then unset UBUNTU_CODENAME . /etc/os-release if [ -z "${UBUNTU_CODENAME+x}" ] then echo "This is not an Ubuntu system. Aborting." > /dev/stderr exit 1 fi release="${UBUNTU_CODENAME}" fi case "${release}" in xenial) packages="apt-transport-https" keyring_packages="wget" ;; bionic|focal) packages= keyring_packages="gpg wget" ;; *) echo "Only Ubuntu Xenial (16.04), Bionic (18.04), and Focal (20.04) are supported. Aborting." > /dev/stderr exit 1 ;; esac get_keyring= if [ ! -f /usr/share/keyrings/kitware-archive-keyring.gpg ] then packages="${packages} ${keyring_packages}" get_keyring=1 fi # Start the real work set -x apt-get update # shellcheck disable=SC2086 apt-get install -y ${packages} test -n "${get_keyring}" && (wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - > /usr/share/keyrings/kitware-archive-keyring.gpg) echo "deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ ${release} main" > /etc/apt/sources.list.d/kitware.list if [ -n "${rc}" ] then echo "deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ ${release}-rc main" >> /etc/apt/sources.list.d/kitware.list fi apt-get update test -n "${get_keyring}" && rm /usr/share/keyrings/kitware-archive-keyring.gpg apt-get install -y kitware-archive-keyring src/descriptor_identifier/model/Model.cpp +32 −27 Original line number Diff line number Diff line Loading @@ -20,8 +20,8 @@ */ #include "descriptor_identifier/model/Model.hpp" #include <filesystem> #include <utility> Model::Model(const std::string& prop_label, const Unit& prop_unit, Loading @@ -31,7 +31,8 @@ Model::Model(const std::string& prop_label, const std::vector<std::string>& sample_ids_train, const std::vector<std::string>& sample_ids_test, const std::vector<std::string>& task_names, const std::map<int, int>& index_map) const std::map<int, int>& index_map, const std::string loss_type_input) : _index_map(index_map), _sample_ids_train(sample_ids_train), _sample_ids_test(sample_ids_test), Loading @@ -44,7 +45,9 @@ Model::Model(const std::string& prop_label, _prop_label(prop_label), _prop_unit(prop_unit), _task_eval(task_names[0]), _fix_intercept(loss->fix_intercept()) _fix_intercept(loss->fix_intercept()), _loss_type(get_loss_type_from_string(loss_type_input)) { for (size_t tn = 0; tn < task_names.size(); ++tn) { Loading Loading @@ -73,7 +76,8 @@ Model::Model(std::string prop_label, std::vector<std::string> sample_ids_train, std::vector<std::string> sample_ids_test, std::vector<std::string> task_names, bool fix_intercept) bool fix_intercept, std::string loss_type_input) : _sample_ids_train(std::move(sample_ids_train)), _sample_ids_test(std::move(sample_ids_test)), _n_samp_train(feats[0]->n_samp()), Loading @@ -84,7 +88,8 @@ Model::Model(std::string prop_label, _prop_label(std::move(prop_label)), _prop_unit(prop_unit), _task_eval(task_names[0]), _fix_intercept(fix_intercept) _fix_intercept(fix_intercept), _loss_type(get_loss_type_from_string(loss_type_input)) { for(int ii = 0; ii < _n_samp_train; ++ii) { Loading Loading @@ -761,17 +766,10 @@ void Model::populate_model(const std::string& train_filename, const std::string& int n_dim = 0; std::getline(train_file_stream, line); //if the loss_type is unknown just grab it from the error line, 3rd line down if (_loss_type == ""){ _loss_type = grab_loss_type_from_line(error_line); } do { split_line = str_utils::split_string_trim(line); int n_tokens = static_cast<int>(split_line.size()); n_dim = n_tokens - 3 + _fix_intercept; //n_dim = split_line.size() - 3 + _fix_intercept; n_dim = split_line.size() - 3 + _fix_intercept; _coefs.push_back(std::vector<double>(n_dim + (!_fix_intercept), 0.0)); std::transform( split_line.begin() + 1, split_line.end() - 1, _coefs.back().data(), [](const std::string& s) { Loading Loading @@ -813,18 +811,22 @@ void Model::populate_model(const std::string& train_filename, const std::string& split_line = str_utils::split_string_trim(line); _task_names[split_line[0].substr(2)] = n_task; ++n_task; // for (std::string str : split_line){ // std::cout << "split line piece " << str << std::endl; // } // std::string fixed_line; // for (char i : split_line[1]) // { // if (std::isdigit(i)) // { // fixed_line += i; // } // } // _n_samp_train += std::stoi(fixed_line); // task_sizes_train.push_back(std::stoi(fixed_line)); _n_samp_train += std::stoi(split_line[1]); task_sizes_train.push_back(std::stoi(split_line[1])); std::string fixed_line; for (char i : split_line[1]) { if (std::isdigit(i)) { fixed_line += i; } } std::cout << "fixed line " << fixed_line << "\n"; _n_samp_train += std::stoi(fixed_line); task_sizes_train.push_back(std::stoi(fixed_line)); if (with_test) { split_line = str_utils::split_string_trim(test_line); Loading Loading @@ -1141,9 +1143,9 @@ std::string Model::write_for_test_file() const{ std::filesystem::path base_dir = source_path.parent_path(); //we can reroute this to another place in repo if desired //but it should be killed by boost anyways after the tests are run std::string outpath = (base_dir / (this->_loss_type + "_model_output.txt")); std::string outpath = (base_dir / (get_loss_type_from_enum(this->_loss_type) + "_model_output.txt")); this->to_file(outpath, true); return (base_dir / (this->_loss_type + "_model_output.txt")).string(); return (base_dir / (get_loss_type_from_enum(this->_loss_type) + "_model_output.txt")).string(); }; void Model::reorder_values(std::map<int, int> index_map) Loading Loading @@ -1227,3 +1229,6 @@ std::string grab_loss_type_from_file(const std::string& path) { } src/descriptor_identifier/model/Model.hpp +14 −10 Original line number Diff line number Diff line Loading @@ -26,9 +26,9 @@ #include <fstream> #include <sstream> #include <iomanip> #include <filesystem> #include "loss_function/utils.hpp" #include "utils/enum.hpp" #ifdef PY_BINDINGS namespace py = pybind11; #endif Loading Loading @@ -59,7 +59,7 @@ protected: Unit _prop_unit; //!< The Unit for the property std::string _task_eval; //!< Which set of coefficients to use for evaluating the model for a new data set std::string _loss_type; //!< Stores the loss type of the model LOSS_TYPE _loss_type; //!< Stores the loss type of the model bool _fix_intercept; //!< If true fix intercept to 0 // clang-format on Loading Loading @@ -91,7 +91,8 @@ public: const std::vector<std::string>& sample_ids_train, const std::vector<std::string>& sample_ids_test, const std::vector<std::string>& task_names, const std::map<int, int>& index_map); const std::map<int, int>& index_map, const std::string loss_type_input); // DocString: model_init_pickle /** Loading Loading @@ -121,7 +122,8 @@ public: std::vector<std::string> sample_ids_train, std::vector<std::string> sample_ids_test, std::vector<std::string> task_names, bool fix_intercept); bool fix_intercept, const std::string loss_type_input); /** * @brief Copy Constructor Loading Loading @@ -543,7 +545,7 @@ public: inline bool fix_intercept() const { return _fix_intercept; } inline std::string get_loss_type() const { return _loss_type; return get_loss_type_from_enum(_loss_type); }; // DocString: model_coefs Loading Loading @@ -602,10 +604,6 @@ public: std::string row_names="Materials"); inline void set_loss_type(std::string new_loss_type){ _loss_type = new_loss_type; } /** * @brief The property vector for all of the training samples */ Loading Loading @@ -886,6 +884,12 @@ public: } #endif }; /** * @brief Grabs the loss type from a file * @param line The error line within the file Loading Loading
.gitignore +0 −1 Original line number Diff line number Diff line Loading @@ -21,5 +21,4 @@ cv_* /include/ /cmake-build-*/ docker/kitware-archive.sh src/external/pybind11
docker/kitware-archive.sh 0 → 100644 +103 −0 Original line number Diff line number Diff line #!/bin/sh set -eu help() { echo "Usage: $0 [--release <ubuntu-release>] [--rc]" > /dev/stderr } doing= rc= release= help= for opt in "$@" do case "${doing}" in release) release="${opt}" doing= ;; "") case "${opt}" in --rc) rc=1 ;; --release) doing=release ;; --help) help=1 ;; esac ;; esac done if [ -n "${doing}" ] then echo "--${doing} option given no argument." > /dev/stderr echo > /dev/stderr help exit 1 fi if [ -n "${help}" ] then help exit fi if [ -z "${release}" ] then unset UBUNTU_CODENAME . /etc/os-release if [ -z "${UBUNTU_CODENAME+x}" ] then echo "This is not an Ubuntu system. Aborting." > /dev/stderr exit 1 fi release="${UBUNTU_CODENAME}" fi case "${release}" in xenial) packages="apt-transport-https" keyring_packages="wget" ;; bionic|focal) packages= keyring_packages="gpg wget" ;; *) echo "Only Ubuntu Xenial (16.04), Bionic (18.04), and Focal (20.04) are supported. Aborting." > /dev/stderr exit 1 ;; esac get_keyring= if [ ! -f /usr/share/keyrings/kitware-archive-keyring.gpg ] then packages="${packages} ${keyring_packages}" get_keyring=1 fi # Start the real work set -x apt-get update # shellcheck disable=SC2086 apt-get install -y ${packages} test -n "${get_keyring}" && (wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - > /usr/share/keyrings/kitware-archive-keyring.gpg) echo "deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ ${release} main" > /etc/apt/sources.list.d/kitware.list if [ -n "${rc}" ] then echo "deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ ${release}-rc main" >> /etc/apt/sources.list.d/kitware.list fi apt-get update test -n "${get_keyring}" && rm /usr/share/keyrings/kitware-archive-keyring.gpg apt-get install -y kitware-archive-keyring
src/descriptor_identifier/model/Model.cpp +32 −27 Original line number Diff line number Diff line Loading @@ -20,8 +20,8 @@ */ #include "descriptor_identifier/model/Model.hpp" #include <filesystem> #include <utility> Model::Model(const std::string& prop_label, const Unit& prop_unit, Loading @@ -31,7 +31,8 @@ Model::Model(const std::string& prop_label, const std::vector<std::string>& sample_ids_train, const std::vector<std::string>& sample_ids_test, const std::vector<std::string>& task_names, const std::map<int, int>& index_map) const std::map<int, int>& index_map, const std::string loss_type_input) : _index_map(index_map), _sample_ids_train(sample_ids_train), _sample_ids_test(sample_ids_test), Loading @@ -44,7 +45,9 @@ Model::Model(const std::string& prop_label, _prop_label(prop_label), _prop_unit(prop_unit), _task_eval(task_names[0]), _fix_intercept(loss->fix_intercept()) _fix_intercept(loss->fix_intercept()), _loss_type(get_loss_type_from_string(loss_type_input)) { for (size_t tn = 0; tn < task_names.size(); ++tn) { Loading Loading @@ -73,7 +76,8 @@ Model::Model(std::string prop_label, std::vector<std::string> sample_ids_train, std::vector<std::string> sample_ids_test, std::vector<std::string> task_names, bool fix_intercept) bool fix_intercept, std::string loss_type_input) : _sample_ids_train(std::move(sample_ids_train)), _sample_ids_test(std::move(sample_ids_test)), _n_samp_train(feats[0]->n_samp()), Loading @@ -84,7 +88,8 @@ Model::Model(std::string prop_label, _prop_label(std::move(prop_label)), _prop_unit(prop_unit), _task_eval(task_names[0]), _fix_intercept(fix_intercept) _fix_intercept(fix_intercept), _loss_type(get_loss_type_from_string(loss_type_input)) { for(int ii = 0; ii < _n_samp_train; ++ii) { Loading Loading @@ -761,17 +766,10 @@ void Model::populate_model(const std::string& train_filename, const std::string& int n_dim = 0; std::getline(train_file_stream, line); //if the loss_type is unknown just grab it from the error line, 3rd line down if (_loss_type == ""){ _loss_type = grab_loss_type_from_line(error_line); } do { split_line = str_utils::split_string_trim(line); int n_tokens = static_cast<int>(split_line.size()); n_dim = n_tokens - 3 + _fix_intercept; //n_dim = split_line.size() - 3 + _fix_intercept; n_dim = split_line.size() - 3 + _fix_intercept; _coefs.push_back(std::vector<double>(n_dim + (!_fix_intercept), 0.0)); std::transform( split_line.begin() + 1, split_line.end() - 1, _coefs.back().data(), [](const std::string& s) { Loading Loading @@ -813,18 +811,22 @@ void Model::populate_model(const std::string& train_filename, const std::string& split_line = str_utils::split_string_trim(line); _task_names[split_line[0].substr(2)] = n_task; ++n_task; // for (std::string str : split_line){ // std::cout << "split line piece " << str << std::endl; // } // std::string fixed_line; // for (char i : split_line[1]) // { // if (std::isdigit(i)) // { // fixed_line += i; // } // } // _n_samp_train += std::stoi(fixed_line); // task_sizes_train.push_back(std::stoi(fixed_line)); _n_samp_train += std::stoi(split_line[1]); task_sizes_train.push_back(std::stoi(split_line[1])); std::string fixed_line; for (char i : split_line[1]) { if (std::isdigit(i)) { fixed_line += i; } } std::cout << "fixed line " << fixed_line << "\n"; _n_samp_train += std::stoi(fixed_line); task_sizes_train.push_back(std::stoi(fixed_line)); if (with_test) { split_line = str_utils::split_string_trim(test_line); Loading Loading @@ -1141,9 +1143,9 @@ std::string Model::write_for_test_file() const{ std::filesystem::path base_dir = source_path.parent_path(); //we can reroute this to another place in repo if desired //but it should be killed by boost anyways after the tests are run std::string outpath = (base_dir / (this->_loss_type + "_model_output.txt")); std::string outpath = (base_dir / (get_loss_type_from_enum(this->_loss_type) + "_model_output.txt")); this->to_file(outpath, true); return (base_dir / (this->_loss_type + "_model_output.txt")).string(); return (base_dir / (get_loss_type_from_enum(this->_loss_type) + "_model_output.txt")).string(); }; void Model::reorder_values(std::map<int, int> index_map) Loading Loading @@ -1227,3 +1229,6 @@ std::string grab_loss_type_from_file(const std::string& path) { }
src/descriptor_identifier/model/Model.hpp +14 −10 Original line number Diff line number Diff line Loading @@ -26,9 +26,9 @@ #include <fstream> #include <sstream> #include <iomanip> #include <filesystem> #include "loss_function/utils.hpp" #include "utils/enum.hpp" #ifdef PY_BINDINGS namespace py = pybind11; #endif Loading Loading @@ -59,7 +59,7 @@ protected: Unit _prop_unit; //!< The Unit for the property std::string _task_eval; //!< Which set of coefficients to use for evaluating the model for a new data set std::string _loss_type; //!< Stores the loss type of the model LOSS_TYPE _loss_type; //!< Stores the loss type of the model bool _fix_intercept; //!< If true fix intercept to 0 // clang-format on Loading Loading @@ -91,7 +91,8 @@ public: const std::vector<std::string>& sample_ids_train, const std::vector<std::string>& sample_ids_test, const std::vector<std::string>& task_names, const std::map<int, int>& index_map); const std::map<int, int>& index_map, const std::string loss_type_input); // DocString: model_init_pickle /** Loading Loading @@ -121,7 +122,8 @@ public: std::vector<std::string> sample_ids_train, std::vector<std::string> sample_ids_test, std::vector<std::string> task_names, bool fix_intercept); bool fix_intercept, const std::string loss_type_input); /** * @brief Copy Constructor Loading Loading @@ -543,7 +545,7 @@ public: inline bool fix_intercept() const { return _fix_intercept; } inline std::string get_loss_type() const { return _loss_type; return get_loss_type_from_enum(_loss_type); }; // DocString: model_coefs Loading Loading @@ -602,10 +604,6 @@ public: std::string row_names="Materials"); inline void set_loss_type(std::string new_loss_type){ _loss_type = new_loss_type; } /** * @brief The property vector for all of the training samples */ Loading Loading @@ -886,6 +884,12 @@ public: } #endif }; /** * @brief Grabs the loss type from a file * @param line The error line within the file Loading