Commit dd390d8b authored by Thomas Purcell's avatar Thomas Purcell
Browse files

Updated files relative to sissopp changes

see https://gitlab.com/sissopp_developers/sissopp
commits: up to 763e40e4deaf7a45dba3f0d8052cca053c1fa957
parent e03c25a5
......@@ -8,15 +8,15 @@ stages:
build-intel:
stage: build
script:
- python -m venv sissopp_env
- source sissopp_env/bin/activate
- python -m venv cpp_sisso_env
- source cpp_sisso_env/bin/activate
- mkdir build_intel/
- cd build_intel/
- export I_MPI_ROOT=/home/runner/intel/oneapi/mpi/2021.1-beta10/
- export INTEL_COMP_ROOT=/home/runner/intel/oneapi/compiler/2021.1-beta10/linux/
- export MKLROOT=/home/runner/intel/oneapi/mkl/2021.1-beta10/
- export LD_LIBRARY_PATH=$I_MPI_ROOT/lib/:$I_MPI_ROOT/lib/release:$MKLROOT/lib/intel64:$INTEL_COMP_ROOT/lib/:$INTEL_COMP_ROOT/compiler/lib/intel64/:$LD_LIBRARY_PATH:$HOME/intel/oneapi/intelpython/latest/lib/:$HOME/intel/oneapi/intelpython/latest/lib/python3.7
- export PYTHONPATH=$HOME/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/:sissopp_env/lib/python3.7/site-packages/
- export PYTHONPATH=$HOME/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/:cpp_sisso_env/lib/python3.7/site-packages/
- export PATH=$INTEL_COMP_ROOT/bin/:$INTEL_COMP_ROOT/bin/intel64:$I_MPI_ROOT/bin:$PATH
- cmake -C ../cmake/toolchains/intel_py.cmake ../
- make
......@@ -28,7 +28,7 @@ build-intel:
- bin/sisso++
- lib/boost/*
- lib/coin-or/*
- sissopp_env/*
- cpp_sisso_env/*
expire_in: 1 days
test-intel-py:
......@@ -36,12 +36,12 @@ test-intel-py:
dependencies:
- build-intel
script:
- source sissopp_env/bin/activate
- source cpp_sisso_env/bin/activate
- export I_MPI_ROOT=/home/runner/intel/oneapi/mpi/2021.1-beta10/
- export INTEL_COMP_ROOT=/home/runner/intel/oneapi/compiler/2021.1-beta10/linux/
- export MKLROOT=/home/runner/intel/oneapi/mkl/2021.1-beta10/
- export LD_LIBRARY_PATH=$I_MPI_ROOT/lib/:$I_MPI_ROOT/lib/release:$MKLROOT/lib/intel64:$INTEL_COMP_ROOT/lib/:$INTEL_COMP_ROOT/compiler/lib/intel64/:$LD_LIBRARY_PATH:$HOME/intel/oneapi/intelpython/latest/lib/:$HOME/intel/oneapi/intelpython/latest/lib/python3.7
- export PYTHONPATH=$HOME/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/:sissopp_env/lib/python3.7/site-packages/
- export PYTHONPATH=$HOME/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/:cpp_sisso_env/lib/python3.7/site-packages/
- export PATH=$INTEL_COMP_ROOT/bin/:$INTEL_COMP_ROOT/bin/intel64:$I_MPI_ROOT/bin:$PATH
- pytest tests
......@@ -50,12 +50,12 @@ test-intel-bin:
dependencies:
- build-intel
script:
- source sissopp_env/bin/activate
- source cpp_sisso_env/bin/activate
- export I_MPI_ROOT=/home/runner/intel/oneapi/mpi/2021.1-beta10/
- export INTEL_COMP_ROOT=/home/runner/intel/oneapi/compiler/2021.1-beta10/linux/
- export MKLROOT=/home/runner/intel/oneapi/mkl/2021.1-beta10/
- export LD_LIBRARY_PATH=$I_MPI_ROOT/lib/:$I_MPI_ROOT/lib/release:$MKLROOT/lib/intel64:$INTEL_COMP_ROOT/lib/:$INTEL_COMP_ROOT/compiler/lib/intel64/:$LD_LIBRARY_PATH:$HOME/intel/oneapi/intelpython/latest/lib/:$HOME/intel/oneapi/intelpython/latest/lib/python3.7
- export PYTHONPATH=$HOME/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/:sissopp_env/lib/python3.7/site-packages/
- export PYTHONPATH=$HOME/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/:cpp_sisso_env/lib/python3.7/site-packages/
- export PATH=$INTEL_COMP_ROOT/bin/:$INTEL_COMP_ROOT/bin/intel64:$I_MPI_ROOT/bin:$PATH
- cd tests/exec_test/
- mpiexec -n 2 ../../bin/sisso++
......@@ -65,10 +65,10 @@ build-gnu:
stage: build
script:
- conda info --envs
- python -m venv sissopp_env
- source sissopp_env/bin/activate
- python -m venv cpp_sisso_env
- source cpp_sisso_env/bin/activate
- export LD_LIBRARY_PATH=$HOME/intel/oneapi/intelpython/latest/lib/:$HOME/intel/oneapi/intelpython/latest/lib/python3.7:$LD_LIBRARY_PATH
- export PYTHONPATH=$HOME/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/:sissopp_env/lib/python3.7/site-packages/
- export PYTHONPATH=$HOME/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/:cpp_sisso_env/lib/python3.7/site-packages/
- mkdir build_gcc/
- cd build_gcc/
- cmake -C ../cmake/toolchains/gnu_py.cmake ../
......@@ -81,16 +81,16 @@ build-gnu:
- bin/sisso++
- lib/boost/*
- lib/coin-or/*
- sissopp_env/*
- cpp_sisso_env/*
test-gnu-py:
stage: unit_test
dependencies:
- build-gnu
script:
- source sissopp_env/bin/activate
- source cpp_sisso_env/bin/activate
- export LD_LIBRARY_PATH=$HOME/intel/oneapi/intelpython/latest/lib/:$HOME/intel/oneapi/intelpython/latest/lib/python3.7:$LD_LIBRARY_PATH
- export PYTHONPATH=$HOME/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/:sissopp_env/lib/python3.7/site-packages/
- export PYTHONPATH=$HOME/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/:cpp_sisso_env/lib/python3.7/site-packages/
- pytest tests
test-gnu-bin:
......@@ -98,9 +98,9 @@ test-gnu-bin:
dependencies:
- build-gnu
script:
- source sissopp_env/bin/activate
- source cpp_sisso_env/bin/activate
- export LD_LIBRARY_PATH=$HOME/intel/oneapi/intelpython/latest/lib/:$HOME/intel/oneapi/intelpython/latest/lib/python3.7:$LD_LIBRARY_PATH
- export PYTHONPATH=$HOME/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/:sissopp_env/lib/python3.7/site-packages/
- export PYTHONPATH=$HOME/intel/oneapi/intelpython/latest/lib/python3.7/site-packages/:cpp_sisso_env/lib/python3.7/site-packages/
- cd tests/exec_test/
- mpiexec -n 2 ../../bin/sisso++
- python check_model.py
......@@ -327,9 +327,6 @@ ExternalProject_Add(
external_Clp
PREFIX "external/coin-Clp"
URL ${COIN_CLP_URL}
# SVN_REPOSITORY "https://projects.coin-or.org/svn/Clp/stable/1.17"
# BUILD_IN_SOURCE 1
# CONFIGURE_COMMAND "${CMAKE_CURRENT_BINARY_DIR}/external/coin-Clp/src/external_Clp/configure"
CONFIGURE_COMMAND "${COIN_CLP_CONFIGURE_COMMAND}"
BUILD_COMMAND make -j ${BOOST_BUILD_N_PROCS}
INSTALL_COMMAND make install
......
......@@ -15,14 +15,27 @@ include_directories(${CMAKE_CURRENT_LIST_DIR}/utils/)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
set(CMAKE_INSTALL_RPATH ${Boost_LIBRARY_DIRS};${LAPACK_DIR};${MPI_DIR};${COIN_CLP_LIBRARY_DIRS};${COIN_UTILS_LIBRARY_DIRS};${CMAKE_CURRENT_LIST_DIR}/../lib/;${CMAKE_CURRENT_LIST_DIR}/../lib/coin-or)
# set(INSTALL_RPATH ${Boost_LIB_DIR})
file(GLOB_RECURSE SISSOPP_SOURCES *.cpp)
file(GLOB_RECURSE NOT_SISSOPP_SOURCES python/*.cpp)
list(REMOVE_ITEM SISSOPP_SOURCES ${NOT_SISSOPP_SOURCES})
list(REMOVE_ITEM SISSOPP_SOURCES ${CMAKE_CURRENT_LIST_DIR}/main.cpp)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/sisso++_config.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/sisso++_config.hpp)
add_executable(sisso++ ${SISSOPP_SOURCES})
add_library(libsisso SHARED ${SISSOPP_SOURCES})
set_target_properties(libsisso
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
PREFIX ""
SUFFIX ".so"
)
target_link_libraries(libsisso ${LAPACK_LIBRARIES} ${MPI_LIBRARIES} -Wl,--rpath=${Boost_LIB_DIR} -Wl,--rpath=${LAPACK_DIR} ${Boost_LIBRARIES} ${COIN_CLP_LIBRARIES} ${OPENMP_LIBRARIES})
install(TARGETS libsisso DESTINATION ${CMAKE_CURRENT_LIST_DIR}/../lib/)
set(CMAKE_INSTALL_RPATH ${Boost_LIBRARY_DIRS};${LAPACK_DIR};${MPI_DIR};${COIN_CLP_LIBRARY_DIRS};${COIN_UTILS_LIBRARY_DIRS};${CMAKE_CURRENT_LIST_DIR}/../lib/;${CMAKE_CURRENT_LIST_DIR}/../lib/coin-or)
add_executable(sisso++ ${CMAKE_CURRENT_LIST_DIR}/main.cpp)
set_target_properties(sisso++
PROPERTIES
......@@ -31,23 +44,21 @@ set_target_properties(sisso++
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
target_link_libraries(sisso++ ${LAPACK_LIBRARIES} ${MPI_LIBRARIES} -Wl,--rpath=${Boost_LIB_DIR} -Wl,--rpath=${LAPACK_DIR} ${Boost_LIBRARIES} ${COIN_CLP_LIBRARIES} ${OPENMP_LIBRARIES})
target_link_libraries(sisso++ libsisso ${LAPACK_LIBRARIES} ${MPI_LIBRARIES} -Wl,--rpath=${Boost_LIB_DIR} -Wl,--rpath=${LAPACK_DIR} ${Boost_LIBRARIES} ${COIN_CLP_LIBRARIES} ${OPENMP_LIBRARIES})
install(TARGETS sisso++ DESTINATION ${CMAKE_CURRENT_LIST_DIR}/../bin/)
if(USE_PYTHON)
include(${CMAKE_CURRENT_LIST_DIR}/../cmake/TransferDocStrings.cmake)
set(CMAKE_INSTALL_RPATH "${Boost_LIBRARY_DIRS};${PYTHON_PREFIX}/lib/;${MPI_DIR};${COIN_CLP_LIBRARY_DIRS};${COIN_UTILS_LIBRARY_DIRS};${CMAKE_CURRENT_LIST_DIR}/../lib/;;${CMAKE_CURRENT_LIST_DIR}/../lib/coin-or")
set(CMAKE_INSTALL_RPATH ${PYTHON_PREFIX}/lib/;${Boost_LIBRARY_DIRS};${LAPACK_DIR};${MPI_DIR};${COIN_CLP_LIBRARY_DIRS};${COIN_UTILS_LIBRARY_DIRS};${CMAKE_CURRENT_LIST_DIR}/../lib/;${PYTHON_INSTDIR}/cpp_sisso/)
transfer_doc_string(${CMAKE_CURRENT_LIST_DIR}/python/bindings_docstring_keyed.cpp ${CMAKE_CURRENT_LIST_DIR}/python/bindings.cpp)
transfer_doc_string(${CMAKE_CURRENT_LIST_DIR}/python/bindings_docstring_keyed.hpp ${CMAKE_CURRENT_LIST_DIR}/python/bindings.hpp)
file(GLOB_RECURSE SISSOLIB_SOURCES *.cpp)
list(REMOVE_ITEM SISSOLIB_SOURCES ${CMAKE_CURRENT_LIST_DIR}/main.cpp)
file(GLOB_RECURSE SISSOLIB_SOURCES ${CMAKE_CURRENT_LIST_DIR}/python/*cpp)
list(REMOVE_ITEM SISSOLIB_SOURCES ${CMAKE_CURRENT_LIST_DIR}/python/bindings_docstring_keyed.cpp)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPY_BINDINGS")
add_library(_sisso SHARED ${SISSOLIB_SOURCES})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/python/__init__.py ${CMAKE_CURRENT_LIST_DIR}/python/__init__.py COPYONLY)
set_target_properties(_sisso
......@@ -59,8 +70,10 @@ if(USE_PYTHON)
PREFIX ""
SUFFIX ".so"
)
target_link_libraries(_sisso ${MPI_LIBRARIES} -Wl,--rpath=${PYTHON_PREFIX}/lib/ ${LAPACK_LIBRARIES} ${PYTHON_LIBRARIES} -Wl,--rpath=${Boost_LIB_DIR} ${Boost_LIBRARIES} ${Boost_PYTHON_LIBRARIES} ${COIN_CLP_LIBRARIES} ${OPENMP_LIBRARIES})
target_link_libraries(_sisso libsisso ${MPI_LIBRARIES} -Wl,--rpath=${PYTHON_PREFIX}/lib/ ${LAPACK_LIBRARIES} ${PYTHON_LIBRARIES} -Wl,--rpath=${Boost_LIB_DIR} ${Boost_LIBRARIES} ${Boost_PYTHON_LIBRARIES} ${COIN_CLP_LIBRARIES} ${OPENMP_LIBRARIES})
install(TARGETS _sisso DESTINATION "${PYTHON_INSTDIR}/cpp_sisso")
install(TARGETS libsisso DESTINATION "${PYTHON_INSTDIR}/cpp_sisso/")
install(
DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/python/ DESTINATION ${PYTHON_INSTDIR}/cpp_sisso
FILES_MATCHING PATTERN "*.py"
......
#include <descriptor_identifier/Model/Model.hpp>
Model::Model(Unit prop_unit, std::vector<double> prop_train, std::vector<double> prop_test, std::vector<model_node_ptr> feats, std::vector<int> task_sizes_train, std::vector<int> task_sizes_test, bool fix_intercept) :
Model::Model(std::string prop_label, Unit prop_unit, std::vector<double> prop_train, std::vector<double> prop_test, std::vector<model_node_ptr> feats, std::vector<int> task_sizes_train, std::vector<int> task_sizes_test, bool fix_intercept) :
_n_samp_train(feats[0]->n_samp()),
_n_samp_test(feats[0]->n_test_samp()),
_n_dim(feats.size()),
......@@ -11,6 +11,7 @@ Model::Model(Unit prop_unit, std::vector<double> prop_train, std::vector<double>
_D_test(_n_samp_test * (feats.size() + (1 - fix_intercept))),
_task_sizes_train(task_sizes_train),
_task_sizes_test(task_sizes_test),
_prop_label(prop_label),
_prop_unit(prop_unit),
_fix_intercept(fix_intercept)
{}
......
......@@ -51,6 +51,7 @@ protected:
std::vector<int> _task_sizes_train; //!< Number of training samples in each task
std::vector<int> _task_sizes_test; //!< Number of testing samples in each task
std::string _prop_label; //!< label for the model
Unit _prop_unit; //!< The Unit for the property
bool _fix_intercept; //!< If true fix intercept to 0
......@@ -64,6 +65,7 @@ public:
/**
* @brief Constructor for the model
*
* @param prop_label The unit of the property
* @param prop_unit The unit of the property
* @param prop_train The property vector for the training samples
* @param prop_test The property vector for the test samples
......@@ -71,7 +73,7 @@ public:
* @param task_sizes_train Number of samples per task in the training data
* @param task_sizes_test Number of samples per task in the test data
*/
Model(Unit prop_unit, std::vector<double> prop_train, std::vector<double> prop_test, std::vector<model_node_ptr> feats, std::vector<int> task_sizes_train, std::vector<int> task_sizes_test, bool fix_intercept);
Model(std::string prop_label, Unit prop_unit, std::vector<double> prop_train, std::vector<double> prop_test, std::vector<model_node_ptr> feats, std::vector<int> task_sizes_train, std::vector<int> task_sizes_test, bool fix_intercept);
/**
* @brief Copy Constructor
......@@ -126,6 +128,13 @@ public:
*/
inline Unit prop_unit(){return _prop_unit;}
// DocString: model_prop_label
/**
* @brief The label for the property
* @return The label for the property
*/
inline std::string prop_label(){return _prop_label;}
/**
* @brief Convert the Model into an output file
*
......
#include <descriptor_identifier/Model/ModelClassifier.hpp>
ModelClassifier::ModelClassifier(Unit prop_unit, std::vector<double> prop_train, std::vector<double> prop_test, std::vector<model_node_ptr> feats, std::vector<int> task_sizes_train, std::vector<int> task_sizes_test, bool fix_intercept) :
Model(prop_unit, prop_train, prop_test, feats, task_sizes_train, task_sizes_test, fix_intercept),
ModelClassifier::ModelClassifier(std::string prop_label, Unit prop_unit, std::vector<double> prop_train, std::vector<double> prop_test, std::vector<model_node_ptr> feats, std::vector<int> task_sizes_train, std::vector<int> task_sizes_test, bool fix_intercept) :
Model(prop_label, prop_unit, prop_train, prop_test, feats, task_sizes_train, task_sizes_test, fix_intercept),
_prop_train_est(_prop_train),
_prop_test_est(_prop_test),
_train_error(_n_samp_train),
......@@ -67,17 +67,18 @@ ModelClassifier::ModelClassifier(std::string train_file)
_task_sizes_test = std::vector<int>(_task_sizes_train.size(), 0);
for(int ff = 0; ff < feature_expr_train.size(); ++ff)
{
split_str = str_utils::split_string_trim(feature_expr_train[ff]);
split_str = str_utils::split_string_trim(feature_expr_train[ff], ";");
int rung = std::stoi(split_str[0]);
std::string unit_str = split_str[1];
std::string postfix_expr = split_str[2];
std::string expr = split_str[3];
std::string latex_expr = split_str[4];
std::vector<double> feat_val(_n_samp_train);
std::vector<double> feat_test_val = {};
std::copy_n(&_D_train[ff * _n_samp_train], _n_samp_train, feat_val.data());
model_node_ptr feat = std::make_shared<ModelNode>(ff, rung, expr, postfix_expr, feat_val, feat_test_val, Unit(unit_str));
model_node_ptr feat = std::make_shared<ModelNode>(ff, rung, expr, latex_expr, postfix_expr, feat_val, feat_test_val, Unit(unit_str));
_feats.push_back(feat);
}
......@@ -100,12 +101,13 @@ ModelClassifier::ModelClassifier(std::string train_file, std::string test_file)
if(feature_expr_train[ff] != feature_expr_test[ff])
throw std::logic_error("Features for train and test file do not agree");
split_str = str_utils::split_string_trim(feature_expr_train[ff]);
split_str = str_utils::split_string_trim(feature_expr_train[ff], ";");
int rung = std::stoi(split_str[0]);
std::string unit_str = split_str[1];
std::string postfix_expr = split_str[2];
std::string expr = split_str[3];
std::string latex_expr = split_str[4];
std::vector<double> feat_val(_n_samp_train);
std::vector<double> feat_test_val(_n_samp_test);
......@@ -113,7 +115,7 @@ ModelClassifier::ModelClassifier(std::string train_file, std::string test_file)
std::copy_n(&_D_train[ff * _n_samp_train], _n_samp_train, feat_val.data());
std::copy_n(&_D_test[ff * _n_samp_test], _n_samp_test, feat_test_val.data());
_feats.push_back(std::make_shared<ModelNode>(ff, rung, expr, postfix_expr, feat_val, feat_test_val, Unit(unit_str)));
_feats.push_back(std::make_shared<ModelNode>(ff, rung, expr, latex_expr, postfix_expr, feat_val, feat_test_val, Unit(unit_str)));
}
int file_train_n_convex_overlap = _train_n_convex_overlap;
......@@ -147,11 +149,13 @@ std::vector<std::string> ModelClassifier::populate_model(std::string filename, b
if(unit_line.substr(0, 42).compare("# # Samples in Convex Hull Overlap Region:") != 0)
{
split_line = str_utils::split_string_trim(unit_line);
_prop_label = split_line[1];
_prop_unit = Unit(split_line.back());
std::getline(file_stream, error_line);
}
else
{
_prop_label = "Property";
_prop_unit = Unit();
error_line = unit_line;
}
......@@ -413,6 +417,16 @@ std::string ModelClassifier::toString() const
return unit_rep.str();
}
std::string ModelClassifier::toLatexString() const
{
std::stringstream unit_rep;
unit_rep << "[" << _feats[0]->latex_expr();
for(int ff = 1; ff < _feats.size(); ++ff)
unit_rep << ", " << _feats[ff]->latex_expr();
unit_rep << "]";
return unit_rep.str();
}
std::ostream& operator<< (std::ostream& outStream, const ModelClassifier& model)
{
outStream << model.toString();
......@@ -428,7 +442,7 @@ void ModelClassifier::to_file(std::string filename, bool train, std::vector<int>
out_file_stream.open(filename);
out_file_stream << "# " << toString() << std::endl;
out_file_stream << "# Property of the Unit: " << _prop_unit.toString() << std::endl;
out_file_stream << "# Property Label: $" << str_utils::latexify(_prop_label) << "$; Unit of the Property: " << _prop_unit.toString() << std::endl;
if(train)
out_file_stream << "# # Samples in Convex Hull Overlap Region: " << _train_n_convex_overlap << "; # SVM Misclassified: " << std::setprecision(15) << n_svm_misclassified_train() << std::endl;
else
......@@ -455,7 +469,7 @@ void ModelClassifier::to_file(std::string filename, bool train, std::vector<int>
out_file_stream << "# Feature Rung, Units, and Expressions" << std::endl;
for(int ff = 0; ff < _feats.size(); ++ff)
out_file_stream << std::setw(6) << std::left << "# " + std::to_string(ff) + ", " << std::to_string(_feats[ff]->rung()) + ", " << std::setw(50) << _feats[ff]->unit().toString() + ", " << _feats[ff]->postfix_expr() + "," << _feats[ff]->expr() << std::endl;
out_file_stream << std::setw(6) << std::left << "# " + std::to_string(ff) + "; " << std::to_string(_feats[ff]->rung()) + "; " << std::setw(50) << _feats[ff]->unit().toString() + "; " << _feats[ff]->postfix_expr() + "; " << _feats[ff]->expr() + "; " << _feats[ff]->latex_expr() << std::endl;
out_file_stream << "# Number of Samples Per Task" << std::endl;
if(train)
......
......@@ -68,7 +68,7 @@ public:
* @param task_sizes_train Number of samples per task in the training data
* @param task_sizes_test Number of samples per task in the test data
*/
ModelClassifier(Unit prop_unit, std::vector<double> prop_train, std::vector<double> prop_test, std::vector<model_node_ptr> feats, std::vector<int> task_sizes_train, std::vector<int> task_sizes_test, bool fix_intercept);
ModelClassifier(std::string prop_label, Unit prop_unit, std::vector<double> prop_train, std::vector<double> prop_test, std::vector<model_node_ptr> feats, std::vector<int> task_sizes_train, std::vector<int> task_sizes_test, bool fix_intercept);
// DocString: model_class_init_str
/**
......@@ -136,6 +136,14 @@ public:
*/
std::string toString() const;
// DocString: model_class_latex_str
/**
* @brief Convert the model to a latexified string
* @return The string representation of the model
*/
std::string toLatexString() const;
/**
* @brief Copy the error into a new array
*
......
#include <descriptor_identifier/Model/ModelLogRegressor.hpp>
ModelLogRegressor::ModelLogRegressor(Unit prop_unit, std::vector<double> prop_train, std::vector<double> prop_test, std::vector<model_node_ptr> feats, std::vector<int> task_sizes_train, std::vector<int> task_sizes_test, bool fix_intercept) :
ModelRegressor(prop_unit, prop_train, prop_test, feats, task_sizes_train, task_sizes_test, fix_intercept),
ModelLogRegressor::ModelLogRegressor(std::string prop_label, Unit prop_unit, std::vector<double> prop_train, std::vector<double> prop_test, std::vector<model_node_ptr> feats, std::vector<int> task_sizes_train, std::vector<int> task_sizes_test, bool fix_intercept) :
ModelRegressor(prop_label, prop_unit, prop_train, prop_test, feats, task_sizes_train, task_sizes_test, fix_intercept),
_log_prop_train(_n_samp_train, 0.0),
_log_prop_test(_n_samp_test, 0.0),
_log_prop_train_est(_n_samp_train, 0.0),
......@@ -109,6 +109,16 @@ std::string ModelLogRegressor::toString() const
return unit_rep.str();
}
std::string ModelLogRegressor::toLatexString() const
{
std::stringstream unit_rep;
unit_rep << "$c_0";
for(int ff = 0; ff < _feats.size(); ++ff)
unit_rep << "\\left(" << _feats[ff]->get_latex_expr("") << "\\right)^{a_" << ff << "}";
unit_rep << "$";
return unit_rep.str();
}
std::ostream& operator<< (std::ostream& outStream, const ModelLogRegressor& model)
{
outStream << model.toString();
......
......@@ -46,7 +46,7 @@ public:
* @param task_sizes_train Number of samples per task in the training data
* @param task_sizes_test Number of samples per task in the test data
*/
ModelLogRegressor(Unit prop_unit, std::vector<double> prop_train, std::vector<double> prop_test, std::vector<model_node_ptr> feats, std::vector<int> task_sizes_train, std::vector<int> task_sizes_test, bool fix_intercept);
ModelLogRegressor(std::string prop_label, Unit prop_unit, std::vector<double> prop_train, std::vector<double> prop_test, std::vector<model_node_ptr> feats, std::vector<int> task_sizes_train, std::vector<int> task_sizes_test, bool fix_intercept);
// DocString: model_log_reg_init_str
/**
......@@ -103,6 +103,14 @@ public:
*/
std::string toString() const;
// DocString: model_log_reg_latex_str
/**
* @brief Convert the model to a latexified string
* @return The string representation of the model
*/
std::string toLatexString() const;
/**
* @brief Copy the error into a new array
*
......
#include <descriptor_identifier/Model/ModelRegressor.hpp>
ModelRegressor::ModelRegressor(Unit prop_unit, std::vector<double> prop_train, std::vector<double> prop_test, std::vector<model_node_ptr> feats, std::vector<int> task_sizes_train, std::vector<int> task_sizes_test, bool fix_intercept) :
Model(prop_unit, prop_train, prop_test, feats, task_sizes_train, task_sizes_test, fix_intercept),
ModelRegressor::ModelRegressor(std::string prop_label, Unit prop_unit, std::vector<double> prop_train, std::vector<double> prop_test, std::vector<model_node_ptr> feats, std::vector<int> task_sizes_train, std::vector<int> task_sizes_test, bool fix_intercept) :
Model(prop_label, prop_unit, prop_train, prop_test, feats, task_sizes_train, task_sizes_test, fix_intercept),
_prop_train_est(_n_samp_train, 0.0),
_prop_test_est(_n_samp_test, 0.0),
_train_error(_n_samp_train),
......@@ -66,17 +66,19 @@ ModelRegressor::ModelRegressor(std::string train_file)
for(int ff = 0; ff < feature_expr_train.size(); ++ff)
{
split_str = str_utils::split_string_trim(feature_expr_train[ff]);
split_str = str_utils::split_string_trim(feature_expr_train[ff], ";");
int rung = std::stoi(split_str[0]);
std::string unit_str = split_str[1];
std::string postfix_expr = split_str[2];
std::string expr = split_str[3];
std::string latex_expr = split_str[4];
std::vector<double> feat_val(_n_samp_train);
std::vector<double> feat_test_val = {};
std::copy_n(&_D_train[ff * _n_samp_train], _n_samp_train, feat_val.data());
model_node_ptr feat = std::make_shared<ModelNode>(ff, rung, expr, postfix_expr, feat_val, feat_test_val, Unit(unit_str));
model_node_ptr feat = std::make_shared<ModelNode>(ff, rung, expr, latex_expr, postfix_expr, feat_val, feat_test_val, Unit(unit_str));
_feats.push_back(feat);
}
......@@ -93,12 +95,13 @@ ModelRegressor::ModelRegressor(std::string train_file, std::string test_file)
if(feature_expr_train[ff] != feature_expr_test[ff])
throw std::logic_error("Features for train and test file do not agree");
split_str = str_utils::split_string_trim(feature_expr_train[ff]);
split_str = str_utils::split_string_trim(feature_expr_train[ff], ";");
int rung = std::stoi(split_str[0]);
std::string unit_str = split_str[1];
std::string postfix_expr = split_str[2];
std::string expr = split_str[3];
std::string latex_expr = split_str[4];
std::vector<double> feat_val(_n_samp_train);
std::vector<double> feat_test_val(_n_samp_test);
......@@ -106,7 +109,7 @@ ModelRegressor::ModelRegressor(std::string train_file, std::string test_file)
std::copy_n(&_D_train[ff * _n_samp_train], _n_samp_train, feat_val.data());
std::copy_n(&_D_test[ff * _n_samp_test], _n_samp_test, feat_test_val.data());
_feats.push_back(std::make_shared<ModelNode>(ff, rung, expr, postfix_expr, feat_val, feat_test_val, Unit(unit_str)));
_feats.push_back(std::make_shared<ModelNode>(ff, rung, expr, latex_expr, postfix_expr, feat_val, feat_test_val, Unit(unit_str)));
}
}
......@@ -130,11 +133,13 @@ std::vector<std::string> ModelRegressor::populate_model(std::string filename, bo
if(unit_line.substr(0, 8).compare("# RMSE: ") != 0)
{
split_line = str_utils::split_string_trim(unit_line);
_prop_label = split_line[1];
_prop_unit = Unit(split_line.back());
std::getline(file_stream, error_line);
}
else
{
_prop_label = "Property";
_prop_unit = Unit();
error_line = unit_line;
}
......@@ -170,7 +175,7 @@ std::vector<std::string> ModelRegressor::populate_model(std::string filename, bo
else
_fix_intercept = false;
_n_dim = n_dim + 1 - _fix_intercept;
_n_dim = n_dim;
std::getline(file_stream, line);
for(int ff = 0; ff < n_dim; ++ff)
......@@ -263,6 +268,16 @@ std::string ModelRegressor::toString() const
return unit_rep.str();
}
std::string ModelRegressor::toLatexString() const
{
std::stringstream unit_rep;
unit_rep << "$c_0";
for(int ff = 0; ff < _feats.size(); ++ff)
unit_rep << " + a_" << std::to_string(ff) << _feats[ff]->get_latex_expr("");
unit_rep << "$";
return unit_rep.str();
}
std::ostream& operator<< (std::ostream& outStream, const ModelRegressor& model)
{
outStream << model.toString();
......@@ -278,7 +293,7 @@ void ModelRegressor::to_file(std::string filename, bool train, std::vector<int>
out_file_stream.open(filename);
out_file_stream << "# " << toString() << std::endl;
out_file_stream << "# Property of the Unit: " << _prop_unit.toString() << std::endl;
out_file_stream << "# Property Label: $" << str_utils::latexify(_prop_label) << "$; Unit of the Property: " << _prop_unit.toString() << std::endl;
if(train)
out_file_stream << "# RMSE: " << std::setprecision(15) << rmse() << "; Max AE: " << max_ae() << std::endl;
else
......@@ -305,7 +320,7 @@ void ModelRegressor::to_file(std::string filename, bool train, std::vector<int>
out_file_stream << "# Feature Rung, Units, and Expressions" << std::endl;
for(int ff = 0; ff < _feats.size(); ++ff)
out_file_stream << std::setw(6) << std::left << "# " + std::to_string(ff) + ", " << std::to_string(_feats[ff]->rung()) + ", " << std::setw(50) << _feats[ff]->unit().toString() + ", " << _feats[ff]->postfix_expr() + "," << _feats[ff]->expr() << std::endl;
out_file_stream << std::setw(6) << std::left << "# " + std::to_string(ff) + "; " << std::to_string(_feats[ff]->rung()) + "; " << std::setw(50) << _feats[ff]->unit().toString() + "; " << _feats[ff]->postfix_expr() + "; " << _feats[ff]->expr() + "; " << _feats[ff]->latex_expr() << std::endl;
out_file_stream << "# Number of Samples Per Task" << std::endl;
if(train)
......
......@@ -54,7 +54,7 @@ public:
* @param task_sizes_train Number of samples per task in the training data
* @param task_sizes_test Number of samples per task in the test data
*/
ModelRegressor(Unit prop_unit, std::vector<double> prop_train, std::vector<double> prop_test, std::vector<model_node_ptr> feats, std::vector<int> task_sizes_train, std::vector<int> task_sizes_test, bool fix_intercept);
ModelRegressor(std::string prop_label, Unit prop_unit, std::vector<double> prop_train, std::vector<double> prop_test, std::vector<model_node_ptr> feats, std::vector<int> task_sizes_train, std::vector<int> task_sizes_test, bool fix_intercept);
// DocString: model_reg_init_str
/**
......@@ -122,6 +122,14 @@ public:
*/
virtual std::string toString() const;
// DocString: model_reg_latex_str
/**
* @brief Convert the model to a latexified string
* @return The string representation of the model
*/
std::string toLatexString() const;
/**
* @brief Copy the error into a new array
*
......@@ -141,6 +149,18 @@ public:
*/
inline double test_rmse(){return util_funcs::norm(_test_error.data(), _n_samp_test) / std::sqrt(static_cast<double>(_n_samp_test));}
// DocString: model_reg_r2
/**
* @brief The training R^2 of the model
*/
inline double r2(){return util_funcs::r2(_prop_train.data(), _prop_train_est.data(), _n_samp_train);}
// DocString: model_reg_test_r2
/**
* @brief The test R^2 of the model
*/
inline double test_r2(){return util_funcs::r2(_prop_test.data(), _prop_test_est.data(), _n_samp_test);}
// DocString: model_reg_max_ae
/**
* @brief The max Absolute error of the training data
......
......@@ -2,6 +2,7 @@
SISSOClassifier::SISSOClassifier(
std::shared_ptr<FeatureSpace> feat_space,
std::string prop_label,
Unit prop_unit,
std::vector<double> prop,
std::vector<double> prop_test,
......@@ -12,7 +13,7 @@ SISSOClassifier::SISSOClassifier(
int n_residual,
int n_models_store
):
SISSO_DI(feat_space, prop_unit, prop, prop_test, task_sizes_train, task_sizes_test, leave_out_inds, n_dim, n_residual, n_models_store, false),
SISSO_DI(feat_space, prop_label, prop_unit, prop, prop_test, task_sizes_train, task_sizes_test, leave_out_inds, n_dim, n_residual, n_models_store, false),
_c(1000.0),