Commit 0a967d71 authored by Thomas Purcell's avatar Thomas Purcell
Browse files

Upadated parameterization

Parameters now go down the tree not just the initial feature
parent 3ae950c0
......@@ -286,134 +286,29 @@ set(MPI_LIBRARIES, ${MPI_CXX_LIBRARIES})
list(GET MPI_CXX_LIBRARIES 0 MPI_LIBRARY)
get_filename_component(MPI_DIR ${MPI_LIBRARY} DIRECTORY)
# Find Ceres
# Find NL Opt
if(USE_PARAMS)
find_package(Eigen)
if(NOT EIGEN_FOUND)
set(EIGEN_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/external/eigen/build/")
set(EIGEN_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/external/eigen/bin/")
set(EIGEN_INCLUDE_DIRS "${EIGEN_INSTALL_DIR}/include/eigen3")
ExternalProject_Add(
external_eigen
PREFIX "external/eigen"
GIT_REPOSITORY "https://gitlab.com/libeigen/eigen.git"
GIT_TAG "3.3.7"
CMAKE_ARGS "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER};-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER};-DCMAKE_INSTALL_PREFIX=${EIGEN_INSTALL_DIR};-DINCLUDE_INSTALL_DIR=${EIGEN_INCLUDE_DIRS};"
BINARY_DIR "${EIGEN_BUILD_DIR}"
INSTALL_DIR "${EIGEN_INSTALL_DIR}"
)
endif()
include_directories(${EIGEN_INCLUDE_DIRS})
find_package(Gflags)
if(NOT GFLAGS_FOUND)
set(GFLAGS_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/external/gflags/bin/")
set(GFLAGS_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/external/gflags/bin/")
set(GFLAGS_INCLUDE_DIRS "${GFLAGS_INSTALL_DIR}/include")
set(GFLAGS_LIBRARY_DIRS "${GFLAGS_INSTALL_DIR}/lib")
ExternalProject_Add(
external_gflags
PREFIX "external/gflags"
GIT_REPOSITORY "https://github.com/gflags/gflags.git"
GIT_TAG "v2.2.2"
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${GFLAGS_INSTALL_DIR};-DBUILD_SHARED_LIBS=ON;-DGFLAGS_NAMESPACE=google;-DINSTALL_HEADERS=ON"
BINARY_DIR "${GFLAGS_BUILD_DIR}"
INSTALL_DIR "${GFLAGS_INSTALL_DIR}"
INSTALL_COMMAND ""
)
add_library( Gflags SHARED IMPORTED )
set_property( TARGET Gflags PROPERTY IMPORTED_LOCATION ${GLOG_LIBRARY_DIRS}/libgflags.so )
set_property( TARGET Gflags PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${GLOG_INCLUDE_DIRS} )
add_dependencies(Gflags external_gflags)
set(GFLAG_LIBRARIES "${GFLAGS_LIBRARY_DIRS}/libgflags.so")
else()
list(GET GFLAG_LIBRARIES 0 GFLAGS_LIBRARY)
get_filename_component(GFLAGS_LIBRARY_DIRS ${GFLAGS_LIBRARY} DIRECTORY)
endif()
include_directories("${GFLAGS_INCLUDE_DIRS}")
# find_package(Glog)
# if(NOT GLOG_FOUND)
set(GLOG_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/external/glog/build/")
set(GLOG_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/external/glog/bin/")
set(GLOG_BIN_DIRS "${GLOG_INSTALL_DIR}/bin")
set(GLOG_INCLUDE_DIRS "${GLOG_INSTALL_DIR}/include")
set(GLOG_LIBRARY_DIRS "${GLOG_INSTALL_DIR}/lib")
set(GLOG_CMAKE_ARGS "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}")
list(APPEND GLOG_CMAKE_ARGS "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}")
list(APPEND GLOG_CMAKE_ARGS "-DWITH_GFLAGS=ON")
list(APPEND GLOG_CMAKE_ARGS "-DBUILD_SHARED_LIBS=ON")
list(APPEND GLOG_CMAKE_ARGS "-DCMAKE_INSTALL_BINDIR=${GLOG_BIN_DIRS}")
list(APPEND GLOG_CMAKE_ARGS "-DCMAKE_INSTALL_INCLUDEDIR=${GLOG_INCLUDE_DIRS}")
list(APPEND GLOG_CMAKE_ARGS "-DCMAKE_INSTALL_LIBDIR=${GLOG_LIBRARY_DIRS}")
list(APPEND GLOG_CMAKE_ARGS "-DWITH_UNWIND=OFF")
set(NLOPT_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/external/nlopt/build/")
set(NLOPT_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/external/nlopt/bin/")
set(NLOPT_INCLUDE_DIRS "${NLOPT_INSTALL_DIR}/include/")
set(NLOPT_LIBRARY_DIRS "${NLOPT_INSTALL_DIR}/lib/")
ExternalProject_Add(
external_glog
PREFIX "external/glog"
GIT_REPOSITORY "https://github.com/google/glog.git"
GIT_TAG "v0.4.0"
CMAKE_ARGS "${GLOG_CMAKE_ARGS}"
BINARY_DIR "${GLOG_BUILD_DIR}"
INSTALL_DIR "${GLOG_INSTALL_DIR}"
external_nlopt
PREFIX "external/nlopt"
GIT_REPOSITORY "https://github.com/stevengj/nlopt.git"
GIT_TAG "v2.6.2"
CMAKE_ARGS "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER};-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER};-DCMAKE_INSTALL_PREFIX=${NLOPT_INSTALL_DIR};"
BINARY_DIR "${NLOPT_BUILD_DIR}"
INSTALL_DIR "${NLOPT_INSTALL_DIR}"
)
add_dependencies(external_glog Gflags)
add_library( glog SHARED IMPORTED )
set_property( TARGET glog PROPERTY IMPORTED_LOCATION ${GLOG_LIBRARY_DIRS}/libglog.so )
set_property( TARGET glog PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${GLOG_INCLUDE_DIRS} )
add_dependencies(glog external_glog)
set(GLOG_LIBRARIES "${GLOG_LIBRARY_DIRS}/libglog.so")
# endif()
include_directories(${GLOG_INCLUDE_DIRS})
set(CERES_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/external/ceres/build/")
set(CERES_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/external/ceres/bin/")
set(CERES_INCLUDE_DIRS "${CERES_INSTALL_DIR}include")
set(CERES_LIBRARY_DIRS "${CERES_INSTALL_DIR}lib")
set(CERES_CMAKE_ARGS "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}")
list(APPEND CERES_CMAKE_ARGS "-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}")
list(APPEND CERES_CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${CERES_INSTALL_DIR}")
list(APPEND CERES_CMAKE_ARGS "-DGFLAGS=ON")
list(APPEND CERES_CMAKE_ARGS "-DMINIGLOG=OFF")
list(APPEND CERES_CMAKE_ARGS "-DBUILD_SHARED_LIBS=ON")
list(APPEND CERES_CMAKE_ARGS "-DSUITESPARSE=OFF")
list(APPEND CERES_CMAKE_ARGS "-DCXSPARSE=OFF")
list(APPEND CERES_CMAKE_ARGS "-DEIGENSPARSE=OFF")
list(APPEND CERES_CMAKE_ARGS "-DEIGEN_INCLUDE_DIR_HINTS=${EIGEN_INCLUDE_DIRS}")
list(APPEND CERES_CMAKE_ARGS "-DGLOG_INCLUDE_DIR_HINTS=${GLOG_INCLUDE_DIRS}")
list(APPEND CERES_CMAKE_ARGS "-DGLOG_LIBRARY_DIR_HINTS=${GLOG_LIBRARY_DIRS}")
list(APPEND CERES_CMAKE_ARGS "-DGFLAGS_INCLUDE_DIR_HINTS=${GFLAGS_INCLUDE_DIRS}")
list(APPEND CERES_CMAKE_ARGS "-DGFLAGS_LIBRARY_DIR_HINTS=${GFLAGS_LIBRARY_DIRS}")
list(APPEND CERES_CMAKE_ARGS "-DLIB_SUFFIX=''")
list(APPEND CERES_CMAKE_ARGS "-DBUILD_TESTING=OFF")
list(APPEND CERES_CMAKE_ARGS "-DBUILD_EXAMPLES=OFF")
ExternalProject_Add(
external_ceres
PREFIX "external/ceres"
GIT_REPOSITORY "https://ceres-solver.googlesource.com/ceres-solver.git"
GIT_TAG "1.14.0"
CMAKE_ARGS "${CERES_CMAKE_ARGS}"
BINARY_DIR "${CERES_BUILD_DIR}"
)
# if(NOT GFLAGS_FOUND)
add_dependencies(external_ceres Gflags)
# endif()
if(NOT GLOG_FOUND)
add_dependencies(external_ceres glog)
endif()
if(NOT EIGEN_FOUND)
add_dependencies(external_ceres external_eigen)
endif()
message(STATUS "CERES_LIBRARY_DIRS: ${CERES_LIBRARY_DIRS}")
add_library( ceres SHARED IMPORTED )
set_property( TARGET ceres PROPERTY IMPORTED_LOCATION "${CERES_LIBRARY_DIRS}/libceres.so" )
set_property( TARGET ceres PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${CERES_INCLUDE_DIRS}" )
add_dependencies(ceres external_ceres)
set(CERES_LIBRARIES "${CERES_LIBRARY_DIRS}/libceres.so;${GLOG_LIBRARIES};${GFLAG_LIBRARIES}")
include_directories(${CERES_INCLUDE_DIRS})
include_directories(${NLOPT_INCLUDE_DIRS})
add_library( nlopt SHARED IMPORTED )
set_property(TARGET nlopt PROPERTY IMPORTED_LOCATION ${NLOPT_LIBRARY_DIRS}/libnlopt.so )
set_property(TARGET nlopt PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${NLOPT_INCLUDE_DIRS} )
ExternalProject_Add_StepDependencies(external_nlopt nlopt)
set(NLOPT_LIBRARIES "${NLOPT_LIBRARY_DIRS}/libnlopt.so")
endif()
# Coin-Clp for linear programing
......
......@@ -3,9 +3,9 @@ include_directories(${CMAKE_CURRENT_LIST_DIR})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
set(CMAKE_INSTALL_RPATH ${Boost_LIBRARY_DIRS};${LAPACK_DIR};${MPI_DIR})
set(CMAKE_INSTALL_RPATH ${Boost_LIBRARY_DIRS};${LAPACK_DIR};${MPI_DIR};${COIN_CLP_LIBRARY_DIRS})
if(USE_PARAMS)
list(APPEND CMAKE_INSTALL_RPATH ${CERES_LIBRARY_DIRS};${GLOG_LIBRARY_DIRS};${GFLAGS_LIBRARY_DIRS};${COIN_CLP_LIBRARY_DIRS})
list(APPEND CMAKE_INSTALL_RPATH ${NLOPT_LIBRARY_DIRS})
endif()
message(STATUS("CMAKE_INSTALL_RPATH = ${CMAKE_INSTALL_RPATH}"))
......@@ -33,19 +33,14 @@ set_target_properties(sisso++
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
# add_dependencies(sisso++ ceres)
message(STATUS "CERES_LIBRARIES = ${CERES_LIBRARIES}")
message(STATUS "CERES_LIBRARY_DIRS = ${CERES_LIBRARY_DIRS}")
target_link_libraries(sisso++ ${LAPACK_LIBRARIES} ${MPI_LIBRARIES} ${Boost_LIBRARIES} ${CERES_LIBRARIES})
target_link_libraries(sisso++ ${LAPACK_LIBRARIES} ${MPI_LIBRARIES} -Wl,--rpath=${Boost_LIB_DIR} -Wl,--rpath=${LAPACK_DIR} ${Boost_LIBRARIES} ${COIN_CLP_LIBRARIES})
target_link_libraries(sisso++ ${LAPACK_LIBRARIES} ${MPI_LIBRARIES} -Wl,--rpath=${Boost_LIB_DIR} -Wl,--rpath=${LAPACK_DIR} ${Boost_LIBRARIES} ${COIN_CLP_LIBRARIES} ${NLOPT_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};${GLOG_LIBRARY_DIRS};${GFLAGS_LIBRARY_DIRS};${COIN_CLP_LIBRARY_DIRS}")
set(CMAKE_INSTALL_RPATH "${Boost_LIBRARY_DIRS};${PYTHON_PREFIX}/lib/;${MPI_DIR};${COIN_CLP_LIBRARY_DIRS}")
if(USE_PARAMS)
list(APPEND CMAKE_INSTALL_RPATH ${CERES_LIBRARY_DIRS};${GLOG_LIBRARY_DIRS})
list(APPEND CMAKE_INSTALL_RPATH ${NLOPT_LIBRARY_DIRS})
endif()
message(STATUS "CMAKE_INSTALL_RPATH = ${CMAKE_INSTALL_RPATH}")
......@@ -78,7 +73,7 @@ if(USE_PYTHON)
SUFFIX ".so"
)
target_link_libraries(_sisso ${MPI_LIBRARIES} -Wl,--rpath=${CERES_LIBRARY_DIRS} -Wl,--rpath=${PYTHON_PREFIX}/lib/ ${LAPACK_LIBRARIES} ${PYTHON_LIBRARIES} -Wl,--rpath=${Boost_LIB_DIR} ${Boost_LIBRARIES} ${Boost_PYTHON_LIBRARIES} ${CERES_LIBRARIES} ${COIN_CLP_LIBRARIES})
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} ${NLOPT_LIBRARIES} ${COIN_CLP_LIBRARIES})
install(TARGETS _sisso DESTINATION "${PYTHON_INSTDIR}/cpp_sisso")
install(
DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/python/ DESTINATION ${PYTHON_INSTDIR}/cpp_sisso
......
......@@ -134,6 +134,7 @@ void SISSORegressor::l0_norm(std::vector<double>& prop, int n_dim)
for(int rr = 0; rr < n_get_models; ++rr)
{
node_value_arrs::clear_temp_test_reg();
node_value_arrs::clear_temp_reg();
for(int ii = 0; ii < n_dim; ++ii)
{
int index = all_inds_min[inds[rr] * n_dim + ii];
......@@ -165,6 +166,9 @@ void SISSORegressor::fit()
std::vector<ModelRegressor> models;
for(int rr = 0; rr < std::max(_n_residual, _n_models_store); ++rr)
{
node_value_arrs::clear_temp_test_reg();
node_value_arrs::clear_temp_reg();
node_value_arrs::clear_temp_test_reg();
model_node_ptr model_feat = std::make_shared<ModelNode>(_feat_space->phi_selected()[rr]->arr_ind(), _feat_space->phi_selected()[rr]->rung(), _feat_space->phi_selected()[rr]->expr(), _feat_space->phi_selected()[rr]->postfix_expr(), _feat_space->phi_selected()[rr]->value(), _feat_space->phi_selected()[rr]->test_value(), _feat_space->phi_selected()[rr]->domain(), _feat_space->phi_selected()[rr]->unit());
......
......@@ -284,11 +284,11 @@ Domain Domain::sub(Domain domain_2, double alpha, double a)
return Domain(bnd, end_pts, new_excluded_pts);
}
Domain Domain::mult(Domain domain_2)
Domain Domain::mult(Domain domain_2, double alpha, double a)
{
std::array<double, 4> test_bnd;
std::transform(_end_points.begin(), _end_points.end(), domain_2.end_points().begin(), test_bnd.begin(), std::multiplies<double>());
std::transform(_end_points.begin(), _end_points.end(), domain_2.end_points().rbegin(), test_bnd.rbegin(), std::multiplies<double>());
std::transform(_end_points.begin(), _end_points.end(), domain_2.end_points().begin(), test_bnd.begin(), [&alpha, &a](double d1, double d2){return d1 * (alpha * d2 + a);});
std::transform(_end_points.begin(), _end_points.end(), domain_2.end_points().rbegin(), test_bnd.rbegin(), [&alpha, &a](double d1, double d2){return d1 * (alpha * d2 + a);});
std::transform(test_bnd.begin(), test_bnd.end(), test_bnd.begin(), [](double d1){return std::isnan(d1) ? 0.0 : d1;});
int min_ind = std::min_element(test_bnd.begin(), test_bnd.end()) - test_bnd.begin();
......
......@@ -252,7 +252,7 @@ public:
* @param a shift parameter
* @return The resulting domain
*/
Domain add(Domain domain_2, double alpha, double a);
Domain add(Domain domain_2, double alpha=1.0, double a=0.0);
// DocString: domain_sub
/**
......@@ -263,7 +263,7 @@ public:
* @param a shift parameter
* @return The resulting domain
*/
Domain sub(Domain domain_2, double alpha, double a);
Domain sub(Domain domain_2, double alpha=1.0, double a=0.0);
// DocString: domain_mult
/**
......@@ -274,7 +274,7 @@ public:
* @param a shift parameter
* @return The resulting domain
*/
Domain mult(Domain domain_2);
Domain mult(Domain domain_2, double alpha=1.0, double a=0.0);
// DocString: domain_div
/**
......@@ -285,7 +285,7 @@ public:
* @param a shift parameter
* @return The resulting domain
*/
Domain div(Domain domain_2, double alpha, double a);
Domain div(Domain domain_2, double alpha=1.0, double a=0.0);
// DocString: domain_abs_parameters
/**
......@@ -296,18 +296,7 @@ public:
*
* @return The abs(alpha * domain + a) domain
*/
Domain abs(double alpha, double a);
// DocString: domain_abs
/**
* @brief Exponential of the domain
*
* @param alpha prefactor for the domain
* @param a The shift of the domain
*
* @return The abs(alpha * domain + a) domain
*/
inline Domain abs(){return abs(1.0, 0.0);}
Domain abs(double alpha=1.0, double a=0.0);
// DocString: domain_exp
/**
......@@ -318,7 +307,7 @@ public:
*
* @return The exp(alpha * domain + a) domain
*/
Domain exp(double alpha, double a);
Domain exp(double alpha=1.0, double a=0.0);
// DocString: domain_log
/**
......@@ -329,7 +318,7 @@ public:
*
* @return The log(alpha * domain + a) domain
*/
Domain log(double alpha, double a);
Domain log(double alpha=1.0, double a=0.0);
// DocString: domain_pow
/**
......@@ -341,7 +330,7 @@ public:
*
* @return The log(alpha * domain + a) domain
*/
Domain pow(double power, double alpha, double a);
Domain pow(double power, double alpha=1.0, double a=0.0);
// DocString: domain_inv
/**
......@@ -352,7 +341,7 @@ public:
*
* @return The log(alpha * domain + a) domain
*/
Domain inv(double alpha, double a);
Domain inv(double alpha=1.0, double a=0.0);
/**
* @brief return true if domain_2 == this
......
......@@ -19,11 +19,29 @@ BOOST_CLASS_EXPORT_GUID(InvNode, "InvNode")
BOOST_CLASS_EXPORT_GUID(SinNode, "SinNode")
BOOST_CLASS_EXPORT_GUID(CosNode, "CosNode")
BOOST_CLASS_EXPORT_GUID(AddParamNode, "AddParamNode")
BOOST_CLASS_EXPORT_GUID(SubParamNode, "SubParamNode")
BOOST_CLASS_EXPORT_GUID(AbsDiffParamNode, "AbsDiffParamNode")
BOOST_CLASS_EXPORT_GUID(MultParamNode, "MultParamNode")
BOOST_CLASS_EXPORT_GUID(DivParamNode, "DivParamNode")
BOOST_CLASS_EXPORT_GUID(SqParamNode, "SqParamNode")
BOOST_CLASS_EXPORT_GUID(SqrtParamNode, "SqrtParamNode")
BOOST_CLASS_EXPORT_GUID(CbParamNode, "CbParamNode")
BOOST_CLASS_EXPORT_GUID(CbrtParamNode, "CbrtParamNode")
BOOST_CLASS_EXPORT_GUID(SixPowParamNode, "SixPowParamNode")
BOOST_CLASS_EXPORT_GUID(ExpParamNode, "ExpParamNode")
BOOST_CLASS_EXPORT_GUID(NegExpParamNode, "NegExpParamNode")
BOOST_CLASS_EXPORT_GUID(LogParamNode, "LogParamNode")
BOOST_CLASS_EXPORT_GUID(AbsParamNode, "AbsParamNode")
BOOST_CLASS_EXPORT_GUID(InvParamNode, "InvParamNode")
BOOST_CLASS_EXPORT_GUID(SinParamNode, "SinParamNode")
BOOST_CLASS_EXPORT_GUID(CosParamNode, "CosParamNode")
FeatureSpace::FeatureSpace(
std::shared_ptr<MPI_Interface> mpi_comm,
std::vector<node_ptr> phi_0,
std::vector<std::string> allowed_ops,
std::map<std::string, std::vector<std::string>> allowed_param_ops,
std::vector<std::string> allowed_param_ops,
std::vector<double> prop,
std::vector<int> task_sizes,
std::string project_type,
......@@ -56,14 +74,16 @@ FeatureSpace::FeatureSpace(
_n_rung_store(max_store_rung),
_n_rung_generate(n_rung_generate)
{
initialize_fs(prop, project_type);
initialize_fs(project_type);
}
void FeatureSpace::initialize_fs(std::vector<double> prop, std::string project_type)
void FeatureSpace::initialize_fs(std::string project_type)
{
#ifndef PARAMETERIZE
if(_allowed_param_ops.size() != 0)
throw std::logic_error("Parameterization is not possible recompile with -DPARAMETERIZE");
#else
nlopt_wrapper::set_objective(project_type, _prop.data(), _task_sizes);
#endif
if(_n_rung_store == -1)
......@@ -105,12 +125,12 @@ void FeatureSpace::initialize_fs(std::vector<double> prop, std::string project_t
#ifdef PARAMETERIZE
for(auto& op : _allowed_param_ops)
{
if((op.first.compare("add") == 0) || (op.first.compare("sub") == 0) || (op.first.compare("mult") == 0) || (op.first.compare("abs_diff") == 0))
_com_bin_param_operators.push_back(std::make_pair(allowed_op_maps::binary_param_operator_map[op.first], op.second));
else if((op.first.compare("div") == 0))
_bin_param_operators.push_back(std::make_pair(allowed_op_maps::binary_param_operator_map[op.first], op.second));
if((op.compare("add") == 0) || (op.compare("sub") == 0) || (op.compare("mult") == 0) || (op.compare("abs_diff") == 0))
_com_bin_param_operators.push_back(allowed_op_maps::binary_param_operator_map[op]);
else if((op.compare("div") == 0))
_bin_param_operators.push_back(allowed_op_maps::binary_param_operator_map[op]);
else
_un_param_operators.push_back(std::make_pair(allowed_op_maps::unary_param_operator_map[op.first], op.second));
_un_param_operators.push_back(allowed_op_maps::unary_param_operator_map[op]);
}
#endif
......@@ -183,7 +203,7 @@ void FeatureSpace::generate_new_feats(std::vector<node_ptr>::iterator& feat, std
{
try
{
feat_set.push_back(op.first(*feat, feat_ind, l_bound, u_bound, op.second, _prop));
feat_set.push_back(op(*feat, feat_ind, l_bound, u_bound, _prop));
++feat_ind;
}
catch(const InvalidFeatureException& e)
......@@ -197,7 +217,7 @@ void FeatureSpace::generate_new_feats(std::vector<node_ptr>::iterator& feat, std
{
try
{
feat_set.push_back(op.first(*feat, *feat_2, feat_ind, l_bound, u_bound, op.second, _prop));
feat_set.push_back(op(*feat, *feat_2, feat_ind, l_bound, u_bound, _prop));
++feat_ind;
}
catch(const InvalidFeatureException& e)
......@@ -212,7 +232,7 @@ void FeatureSpace::generate_new_feats(std::vector<node_ptr>::iterator& feat, std
{
try
{
feat_set.push_back(op.first(*feat, *feat_2, feat_ind, l_bound, u_bound, op.second, _prop));
feat_set.push_back(op(*feat, *feat_2, feat_ind, l_bound, u_bound, _prop));
++feat_ind;
}
catch(const InvalidFeatureException& e)
......@@ -221,7 +241,7 @@ void FeatureSpace::generate_new_feats(std::vector<node_ptr>::iterator& feat, std
}
try
{
feat_set.push_back(op.first(*feat_2, *feat, feat_ind, l_bound, u_bound, op.second, _prop));
feat_set.push_back(op(*feat_2, *feat, feat_ind, l_bound, u_bound, _prop));
++feat_ind;
}
catch(const InvalidFeatureException& e)
......
......@@ -42,12 +42,12 @@ class FeatureSpace
std::vector<node_ptr> _phi_0; //!< initial feature space
#ifdef PARAMETERIZE
std::vector<std::pair<un_param_op_node_gen, std::vector<std::string>>> _un_param_operators; //!< list of all parameterized unary operators with free parameters
std::vector<std::pair<bin_param_op_node_gen, std::vector<std::string>>> _com_bin_param_operators; //!< list of all parameterized commutable binary operators with free parameters
std::vector<std::pair<bin_param_op_node_gen, std::vector<std::string>>> _bin_param_operators; //!< list of all parameterized binary operators with free parameters
std::vector<un_param_op_node_gen> _un_param_operators; //!< list of all parameterized unary operators with free parameters
std::vector<bin_param_op_node_gen> _com_bin_param_operators; //!< list of all parameterized commutable binary operators with free parameters
std::vector<bin_param_op_node_gen> _bin_param_operators; //!< list of all parameterized binary operators with free parameters
#endif
std::map<std::string, std::vector<std::string>> _allowed_param_ops; //!< Map of parameterization operator set (set of operators and non-linear parameters used for a non-linear least squares fit to property)
std::vector<std::string> _allowed_param_ops; //!< Map of parameterization operator set (set of operators and non-linear parameters used for a non-linear least squares fit to property)
std::vector<std::string> _allowed_ops; //!< list of all allowed operators strings
std::vector<un_op_node_gen> _un_operators; //!< list of all unary operators
std::vector<bin_op_node_gen> _com_bin_operators; //!< list of all commutable binary operators
......@@ -100,7 +100,7 @@ public:
std::shared_ptr<MPI_Interface> mpi_comm,
std::vector<node_ptr> phi_0,
std::vector<std::string> allowed_ops,
std::map<std::string, std::vector<std::string>> allowed_param_ops,
std::vector<std::string> allowed_param_ops,
std::vector<double> prop,
std::vector<int> task_sizes,
std::string project_type="regression",
......@@ -118,7 +118,7 @@ public:
*
* @param prop The property trying to be learned
*/
void initialize_fs(std::vector<double> prop, std::string project_type);
void initialize_fs(std::string project_type);
/**
* @brief Generate the full feature set from the allowed operators and initial feature set
......@@ -292,7 +292,7 @@ public:
FeatureSpace(
py::list phi_0,
py::list allowed_ops,
py::dict allowed_param_ops,
py::list allowed_param_ops,
py::list prop,
py::list task_sizes,
std::string project_type="pearson",
......@@ -326,7 +326,7 @@ public:
FeatureSpace(
py::list phi_0,
py::list allowed_ops,
py::dict allowed_param_ops,
py::list allowed_param_ops,
np::ndarray prop,
py::list task_sizes,
std::string project_type="pearson",
......
......@@ -12,7 +12,10 @@ FeatureNode::FeatureNode(int feat_ind, std::string expr, std::vector<double> val
_expr(expr)
{
if((*std::max_element(value.begin(), value.end()) > _domain) || (*std::min_element(value.begin(), value.end()) < _domain))
{
std::cout << (*std::max_element(value.begin(), value.end())) << '\t' << (*std::min_element(value.begin(), value.end())) << std::endl;
throw std::logic_error("The feature " + expr + " has values outside of the domain of " + _domain.toString());
}
if(set_val)
{
......
......@@ -210,7 +210,6 @@ public:
*/
inline double* test_value_ptr(int offset = 0){return node_value_arrs::get_test_value_ptr(_arr_ind, _feat_ind, offset);}
// DocString: feat_node_rung
/**
* @brief return the rung of the feature
......@@ -296,12 +295,68 @@ public:
/**
* @brief The parameters used for introducing more non linearity in the operators
*/
inline std::array<double, 2> parameters(){return {1.0, 0.0};}
inline std::vector<double> parameters(){return {};};
/**
* @brief Set the non-linear parameters
*/
inline void set_parameters(std::vector<double> params){};
/**
* @brief returns the number of parameters for this feature
* @return the number of parameters (_params.size())
*/
inline int n_params(int n_cur=0){return n_cur;};
/**
* @brief Set the values of the training data for the feature inside of the value storage arrays
*
* @param offset(int) Key to determine which part of the temporary storage array to look into
* @param params pointer to the parameter values
*/
inline void set_value(const double* params, int offset = -1){set_value(offset);};
/**
* @brief The pointer to where the feature's training data is stored
*
* @param offset(int) Key to determine which part of the temporary storage array to look into
* @param params pointer to the parameter values
* @returns the pointer to the feature's data
*/
inline double* value_ptr(const double* params, int offset = -1){return value_ptr(offset);};
/**
* @brief Set the values of the test data for the feature inside of the value storage arrays
*
* @param offset(int) Key to determine which part of the temporary storage array to look into
* @param params pointer to the parameter values
*/
inline void set_test_value(const double* params, int offset = -1){set_test_value(offset);};
/**
* @brief The pointer to where the feature's test data is stored
*
* @param offset(int) Key to determine which part of the temporary storage array to look into
* @param params pointer to the parameter values
* @returns the pointer to the feature's data
*/
inline double* test_value_ptr(const double* params, int offset = -1){return test_value_ptr(offset);};
/**
* @brief The domain for the feature (min/max values)
*
* @param params parameter values for non-linear operations
* @return the domain
*/
Domain domain(double* params){return _domain;};
/**
* @brief The expression of the feature
*
* @param params parameter values for non-linear operations
* @return feature expression
*/
inline void set_parameters(std::array<double, 2>){};
std::string expr(double* params){return _expr;};
#endif
};
......
......@@ -327,12 +327,69 @@ public:
/**
* @brief The parameters used for introducing more non linearity in the operators
*/
virtual std::array<double, 2> parameters() = 0;
virtual std::vector<double> parameters() = 0;
/**
* @brief Set the non-linear parameters
*/
virtual void set_parameters(std::array<double, 2>) = 0;
virtual void set_parameters(std::vector<double>) = 0;
/**
* @brief returns the number of parameters for this feature
* @return the number of parameters (_params.size())
*/
virtual int n_params(int n_cur = 0) = 0;
/**