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: ...@@ -8,15 +8,15 @@ stages:
build-intel: build-intel:
stage: build stage: build
script: script:
- python -m venv sissopp_env - python -m venv cpp_sisso_env
- source sissopp_env/bin/activate - source cpp_sisso_env/bin/activate
- mkdir build_intel/ - mkdir build_intel/
- cd build_intel/ - cd build_intel/
- export I_MPI_ROOT=/home/runner/intel/oneapi/mpi/2021.1-beta10/ - 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 INTEL_COMP_ROOT=/home/runner/intel/oneapi/compiler/2021.1-beta10/linux/
- export MKLROOT=/home/runner/intel/oneapi/mkl/2021.1-beta10/ - 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 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 - export PATH=$INTEL_COMP_ROOT/bin/:$INTEL_COMP_ROOT/bin/intel64:$I_MPI_ROOT/bin:$PATH
- cmake -C ../cmake/toolchains/intel_py.cmake ../ - cmake -C ../cmake/toolchains/intel_py.cmake ../
- make - make
...@@ -28,7 +28,7 @@ build-intel: ...@@ -28,7 +28,7 @@ build-intel:
- bin/sisso++ - bin/sisso++
- lib/boost/* - lib/boost/*
- lib/coin-or/* - lib/coin-or/*
- sissopp_env/* - cpp_sisso_env/*
expire_in: 1 days expire_in: 1 days
test-intel-py: test-intel-py:
...@@ -36,12 +36,12 @@ test-intel-py: ...@@ -36,12 +36,12 @@ test-intel-py:
dependencies: dependencies:
- build-intel - build-intel
script: 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 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 INTEL_COMP_ROOT=/home/runner/intel/oneapi/compiler/2021.1-beta10/linux/
- export MKLROOT=/home/runner/intel/oneapi/mkl/2021.1-beta10/ - 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 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 - export PATH=$INTEL_COMP_ROOT/bin/:$INTEL_COMP_ROOT/bin/intel64:$I_MPI_ROOT/bin:$PATH
- pytest tests - pytest tests
...@@ -50,12 +50,12 @@ test-intel-bin: ...@@ -50,12 +50,12 @@ test-intel-bin:
dependencies: dependencies:
- build-intel - build-intel
script: 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 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 INTEL_COMP_ROOT=/home/runner/intel/oneapi/compiler/2021.1-beta10/linux/
- export MKLROOT=/home/runner/intel/oneapi/mkl/2021.1-beta10/ - 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 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 - export PATH=$INTEL_COMP_ROOT/bin/:$INTEL_COMP_ROOT/bin/intel64:$I_MPI_ROOT/bin:$PATH
- cd tests/exec_test/ - cd tests/exec_test/
- mpiexec -n 2 ../../bin/sisso++ - mpiexec -n 2 ../../bin/sisso++
...@@ -65,10 +65,10 @@ build-gnu: ...@@ -65,10 +65,10 @@ build-gnu:
stage: build stage: build
script: script:
- conda info --envs - conda info --envs
- python -m venv sissopp_env - python -m venv cpp_sisso_env
- 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 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/ - mkdir build_gcc/
- cd build_gcc/ - cd build_gcc/
- cmake -C ../cmake/toolchains/gnu_py.cmake ../ - cmake -C ../cmake/toolchains/gnu_py.cmake ../
...@@ -81,16 +81,16 @@ build-gnu: ...@@ -81,16 +81,16 @@ build-gnu:
- bin/sisso++ - bin/sisso++
- lib/boost/* - lib/boost/*
- lib/coin-or/* - lib/coin-or/*
- sissopp_env/* - cpp_sisso_env/*
test-gnu-py: test-gnu-py:
stage: unit_test stage: unit_test
dependencies: dependencies:
- build-gnu - build-gnu
script: 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 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 - pytest tests
test-gnu-bin: test-gnu-bin:
...@@ -98,9 +98,9 @@ test-gnu-bin: ...@@ -98,9 +98,9 @@ test-gnu-bin:
dependencies: dependencies:
- build-gnu - build-gnu
script: 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 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/ - cd tests/exec_test/
- mpiexec -n 2 ../../bin/sisso++ - mpiexec -n 2 ../../bin/sisso++
- python check_model.py - python check_model.py
...@@ -230,8 +230,8 @@ else(EXTERNAL_BOOST) ...@@ -230,8 +230,8 @@ else(EXTERNAL_BOOST)
BUILD_IN_SOURCE 1 BUILD_IN_SOURCE 1
CONFIGURE_COMMAND ${Boost_CONFIGURE_COMMAND} CONFIGURE_COMMAND ${Boost_CONFIGURE_COMMAND}
BUILD_COMMAND BUILD_COMMAND
./b2 -j ${BOOST_BUILD_N_PROCS} ./b2 -j ${BOOST_BUILD_N_PROCS}
INSTALL_COMMAND ./b2 -j ${BOOST_BUILD_N_PROCS} install INSTALL_COMMAND ./b2 -j ${BOOST_BUILD_N_PROCS} install
INSTALL_DIR ${Boost_INSTALL_DIR} INSTALL_DIR ${Boost_INSTALL_DIR}
) )
...@@ -327,9 +327,6 @@ ExternalProject_Add( ...@@ -327,9 +327,6 @@ ExternalProject_Add(
external_Clp external_Clp
PREFIX "external/coin-Clp" PREFIX "external/coin-Clp"
URL ${COIN_CLP_URL} 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}" CONFIGURE_COMMAND "${COIN_CLP_CONFIGURE_COMMAND}"
BUILD_COMMAND make -j ${BOOST_BUILD_N_PROCS} BUILD_COMMAND make -j ${BOOST_BUILD_N_PROCS}
INSTALL_COMMAND make install INSTALL_COMMAND make install
......
...@@ -15,14 +15,27 @@ include_directories(${CMAKE_CURRENT_LIST_DIR}/utils/) ...@@ -15,14 +15,27 @@ include_directories(${CMAKE_CURRENT_LIST_DIR}/utils/)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations") 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(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 SISSOPP_SOURCES *.cpp)
file(GLOB_RECURSE NOT_SISSOPP_SOURCES python/*.cpp) file(GLOB_RECURSE NOT_SISSOPP_SOURCES python/*.cpp)
list(REMOVE_ITEM SISSOPP_SOURCES ${NOT_SISSOPP_SOURCES}) 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) 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++ set_target_properties(sisso++
PROPERTIES PROPERTIES
...@@ -31,23 +44,21 @@ set_target_properties(sisso++ ...@@ -31,23 +44,21 @@ set_target_properties(sisso++
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" 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/) install(TARGETS sisso++ DESTINATION ${CMAKE_CURRENT_LIST_DIR}/../bin/)
if(USE_PYTHON) if(USE_PYTHON)
include(${CMAKE_CURRENT_LIST_DIR}/../cmake/TransferDocStrings.cmake) 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.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) 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) file(GLOB_RECURSE SISSOLIB_SOURCES ${CMAKE_CURRENT_LIST_DIR}/python/*cpp)
list(REMOVE_ITEM SISSOLIB_SOURCES ${CMAKE_CURRENT_LIST_DIR}/main.cpp)
list(REMOVE_ITEM SISSOLIB_SOURCES ${CMAKE_CURRENT_LIST_DIR}/python/bindings_docstring_keyed.cpp) list(REMOVE_ITEM SISSOLIB_SOURCES ${CMAKE_CURRENT_LIST_DIR}/python/bindings_docstring_keyed.cpp)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPY_BINDINGS") # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPY_BINDINGS")
add_library(_sisso SHARED ${SISSOLIB_SOURCES}) add_library(_sisso SHARED ${SISSOLIB_SOURCES})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/python/__init__.py ${CMAKE_CURRENT_LIST_DIR}/python/__init__.py COPYONLY) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/python/__init__.py ${CMAKE_CURRENT_LIST_DIR}/python/__init__.py COPYONLY)
set_target_properties(_sisso set_target_properties(_sisso
...@@ -59,8 +70,10 @@ if(USE_PYTHON) ...@@ -59,8 +70,10 @@ if(USE_PYTHON)
PREFIX "" PREFIX ""
SUFFIX ".so" 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 _sisso DESTINATION "${PYTHON_INSTDIR}/cpp_sisso")
install(TARGETS libsisso DESTINATION "${PYTHON_INSTDIR}/cpp_sisso/")
install( install(
DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/python/ DESTINATION ${PYTHON_INSTDIR}/cpp_sisso DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/python/ DESTINATION ${PYTHON_INSTDIR}/cpp_sisso
FILES_MATCHING PATTERN "*.py" FILES_MATCHING PATTERN "*.py"
......
#include <descriptor_identifier/Model/Model.hpp> #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_train(feats[0]->n_samp()),
_n_samp_test(feats[0]->n_test_samp()), _n_samp_test(feats[0]->n_test_samp()),
_n_dim(feats.size()), _n_dim(feats.size()),
...@@ -11,6 +11,7 @@ Model::Model(Unit prop_unit, std::vector<double> prop_train, std::vector<double> ...@@ -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))), _D_test(_n_samp_test * (feats.size() + (1 - fix_intercept))),
_task_sizes_train(task_sizes_train), _task_sizes_train(task_sizes_train),
_task_sizes_test(task_sizes_test), _task_sizes_test(task_sizes_test),
_prop_label(prop_label),
_prop_unit(prop_unit), _prop_unit(prop_unit),
_fix_intercept(fix_intercept) _fix_intercept(fix_intercept)
{} {}
......
...@@ -51,6 +51,7 @@ protected: ...@@ -51,6 +51,7 @@ protected:
std::vector<int> _task_sizes_train; //!< Number of training samples in each task 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::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 Unit _prop_unit; //!< The Unit for the property
bool _fix_intercept; //!< If true fix intercept to 0 bool _fix_intercept; //!< If true fix intercept to 0
...@@ -64,6 +65,7 @@ public: ...@@ -64,6 +65,7 @@ public:
/** /**
* @brief Constructor for the model * @brief Constructor for the model
* *
* @param prop_label The unit of the property
* @param prop_unit 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_train The property vector for the training samples
* @param prop_test The property vector for the test samples * @param prop_test The property vector for the test samples
...@@ -71,7 +73,7 @@ public: ...@@ -71,7 +73,7 @@ public:
* @param task_sizes_train Number of samples per task in the training data * @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 * @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 * @brief Copy Constructor
...@@ -126,6 +128,13 @@ public: ...@@ -126,6 +128,13 @@ public:
*/ */
inline Unit prop_unit(){return _prop_unit;} 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 * @brief Convert the Model into an output file
* *
...@@ -196,4 +205,4 @@ public: ...@@ -196,4 +205,4 @@ public:
#endif #endif
}; };
#endif #endif
\ No newline at end of file
#include <descriptor_identifier/Model/ModelClassifier.hpp> #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) : 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_unit, prop_train, prop_test, feats, task_sizes_train, task_sizes_test, 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_train_est(_prop_train),
_prop_test_est(_prop_test), _prop_test_est(_prop_test),
_train_error(_n_samp_train), _train_error(_n_samp_train),
...@@ -67,17 +67,18 @@ ModelClassifier::ModelClassifier(std::string train_file) ...@@ -67,17 +67,18 @@ ModelClassifier::ModelClassifier(std::string train_file)
_task_sizes_test = std::vector<int>(_task_sizes_train.size(), 0); _task_sizes_test = std::vector<int>(_task_sizes_train.size(), 0);
for(int ff = 0; ff < feature_expr_train.size(); ++ff) 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]); int rung = std::stoi(split_str[0]);
std::string unit_str = split_str[1]; std::string unit_str = split_str[1];
std::string postfix_expr = split_str[2]; std::string postfix_expr = split_str[2];
std::string expr = split_str[3]; 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_val(_n_samp_train);
std::vector<double> feat_test_val = {}; std::vector<double> feat_test_val = {};
std::copy_n(&_D_train[ff * _n_samp_train], _n_samp_train, feat_val.data()); 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); _feats.push_back(feat);
} }
...@@ -100,12 +101,13 @@ ModelClassifier::ModelClassifier(std::string train_file, std::string test_file) ...@@ -100,12 +101,13 @@ ModelClassifier::ModelClassifier(std::string train_file, std::string test_file)
if(feature_expr_train[ff] != feature_expr_test[ff]) if(feature_expr_train[ff] != feature_expr_test[ff])
throw std::logic_error("Features for train and test file do not agree"); 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]); int rung = std::stoi(split_str[0]);
std::string unit_str = split_str[1]; std::string unit_str = split_str[1];
std::string postfix_expr = split_str[2]; std::string postfix_expr = split_str[2];
std::string expr = split_str[3]; 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_val(_n_samp_train);
std::vector<double> feat_test_val(_n_samp_test); std::vector<double> feat_test_val(_n_samp_test);
...@@ -113,7 +115,7 @@ ModelClassifier::ModelClassifier(std::string train_file, std::string test_file) ...@@ -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_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()); 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; 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 ...@@ -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) if(unit_line.substr(0, 42).compare("# # Samples in Convex Hull Overlap Region:") != 0)
{ {
split_line = str_utils::split_string_trim(unit_line); split_line = str_utils::split_string_trim(unit_line);
_prop_label = split_line[1];
_prop_unit = Unit(split_line.back()); _prop_unit = Unit(split_line.back());
std::getline(file_stream, error_line); std::getline(file_stream, error_line);
} }
else else
{ {
_prop_label = "Property";
_prop_unit = Unit(); _prop_unit = Unit();
error_line = unit_line; error_line = unit_line;
} }
...@@ -413,6 +417,16 @@ std::string ModelClassifier::toString() const ...@@ -413,6 +417,16 @@ std::string ModelClassifier::toString() const
return unit_rep.str(); 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) std::ostream& operator<< (std::ostream& outStream, const ModelClassifier& model)
{ {
outStream << model.toString(); outStream << model.toString();
...@@ -428,7 +442,7 @@ void ModelClassifier::to_file(std::string filename, bool train, std::vector<int> ...@@ -428,7 +442,7 @@ void ModelClassifier::to_file(std::string filename, bool train, std::vector<int>
out_file_stream.open(filename); out_file_stream.open(filename);
out_file_stream << "# " << toString() << std::endl; 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) 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; 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 else
...@@ -455,7 +469,7 @@ void ModelClassifier::to_file(std::string filename, bool train, std::vector<int> ...@@ -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; out_file_stream << "# Feature Rung, Units, and Expressions" << std::endl;
for(int ff = 0; ff < _feats.size(); ++ff) 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; out_file_stream << "# Number of Samples Per Task" << std::endl;
if(train) if(train)
......
...@@ -68,7 +68,7 @@ public: ...@@ -68,7 +68,7 @@ public:
* @param task_sizes_train Number of samples per task in the training data * @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 * @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 // DocString: model_class_init_str
/** /**
...@@ -136,6 +136,14 @@ public: ...@@ -136,6 +136,14 @@ public:
*/ */
std::string toString() const; 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 * @brief Copy the error into a new array
* *
...@@ -256,4 +264,4 @@ public: ...@@ -256,4 +264,4 @@ public:
*/ */
std::ostream& operator<< (std::ostream& outStream, const ModelClassifier& model); std::ostream& operator<< (std::ostream& outStream, const ModelClassifier& model);
#endif #endif
\ No newline at end of file
#include <descriptor_identifier/Model/ModelLogRegressor.hpp> #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) : 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_unit, prop_train, prop_test, feats, task_sizes_train, task_sizes_test, 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_train(_n_samp_train, 0.0),
_log_prop_test(_n_samp_test, 0.0), _log_prop_test(_n_samp_test, 0.0),
_log_prop_train_est(_n_samp_train, 0.0), _log_prop_train_est(_n_samp_train, 0.0),
...@@ -109,8 +109,18 @@ std::string ModelLogRegressor::toString() const ...@@ -109,8 +109,18 @@ std::string ModelLogRegressor::toString() const
return unit_rep.str(); 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();