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

Update handeling of Param to lev

set it to a depth variable, that can be set instead
parent bb97b603
......@@ -305,8 +305,6 @@ list(GET MPI_CXX_LIBRARIES 0 MPI_LIBRARY)
get_filename_component(MPI_DIR ${MPI_LIBRARY} DIRECTORY)
# Build libnlopt
message(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}")
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/")
......@@ -377,9 +375,26 @@ if(NOT GTEST_FOUND)
)
set(GTEST_BOTH_LIBRARIES "${GTEST_LIBRARY_DIRS}/libgtest.so;${GTEST_LIBRARY_DIRS}/libgtest_main.so;${GTEST_LIBRARY_DIRS}/libgmock.so;${GTEST_LIBRARY_DIRS}/libgmock_main.so")
endif()
include_directories(${GTEST_INCLUDE_DIRS})
set(FMT_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/external/fmt/build/")
set(FMT_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/external/fmt/bin/")
set(FMT_INCLUDE_DIRS "${FMT_INSTALL_DIR}/include/")
set(FMT_LIBRARY_DIRS "${FMT_INSTALL_DIR}/lib/")
ExternalProject_Add(
external_fmt
PREFIX "external/fmt"
GIT_REPOSITORY "https://github.com/fmtlib/fmt.git"
GIT_TAG "7.1.2"
CMAKE_ARGS "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER};-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER};-DINSTALL_LIB_DIR=${FMT_LIBRARY_DIRS};-DCMAKE_INSTALL_PREFIX=${FMT_INSTALL_DIR};-DFMT_DOC=OFF;-DFMT_TEST=OFF;-DFMT_OS=OFF;-DBUILD_SHARED_LIBS=ON"
BINARY_DIR "${FMT_BUILD_DIR}"
INSTALL_DIR "${FMT_INSTALL_DIR}"
)
include_directories(${FMT_INCLUDE_DIRS})
set(FMT_LIBRARIES "${FMT_LIBRARY_DIRS}/libfmt.so")
message(STATUS "FMT_LIBRARIES: ${FMT_LIBRARIES}")
include_directories(${CMAKE_CURRENT_LIST_DIR}/src)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/src)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tests/googletest/)
......
......@@ -2,7 +2,7 @@ include_directories(${CMAKE_CURRENT_LIST_DIR}/feature_creation/domain/)
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};${COIN_CLP_LIBRARY_DIRS};${NLOPT_LIBRARY_DIRS};${COIN_UTILS_LIBRARY_DIRS};${CMAKE_CURRENT_LIST_DIR}/../lib/)
set(CMAKE_INSTALL_RPATH ${Boost_LIBRARY_DIRS};${LAPACK_DIR};${MPI_DIR};${COIN_CLP_LIBRARY_DIRS};${NLOPT_LIBRARY_DIRS};${COIN_UTILS_LIBRARY_DIRS};${CMAKE_CURRENT_LIST_DIR}/../lib/;${FMT_LIBRARY_DIRS})
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
# set(INSTALL_RPATH ${Boost_LIB_DIR})
......@@ -30,7 +30,7 @@ set_target_properties(libsisso
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})
target_link_libraries(libsisso ${LAPACK_LIBRARIES} ${MPI_LIBRARIES} -Wl,--rpath=${Boost_LIB_DIR} -Wl,--rpath=${LAPACK_DIR} ${Boost_LIBRARIES} ${COIN_CLP_LIBRARIES} ${OPENMP_LIBRARIES} ${FMT_LIBRARIES})
message(STATUS "Testing without coverage.")
install(TARGETS libsisso DESTINATION ${CMAKE_CURRENT_LIST_DIR}/../lib/)
......@@ -44,12 +44,12 @@ set_target_properties(sisso++
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
target_link_libraries(sisso++ libsisso ${LAPACK_LIBRARIES} ${MPI_LIBRARIES} -Wl,--rpath=${Boost_LIB_DIR} -Wl,--rpath=${LAPACK_DIR} ${Boost_LIBRARIES} ${COIN_CLP_LIBRARIES} ${NLOPT_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} ${NLOPT_LIBRARIES} ${OPENMP_LIBRARIES} ${FMT_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 ${PYTHON_PREFIX}/lib/;${Boost_LIBRARY_DIRS};${LAPACK_DIR};${MPI_DIR};${COIN_CLP_LIBRARY_DIRS};${NLOPT_LIBRARY_DIRS};${COIN_UTILS_LIBRARY_DIRS};${CMAKE_CURRENT_LIST_DIR}/../lib/;${PYTHON_INSTDIR}/cpp_sisso/)
set(CMAKE_INSTALL_RPATH ${PYTHON_PREFIX}/lib/;${Boost_LIBRARY_DIRS};${LAPACK_DIR};${MPI_DIR};${COIN_CLP_LIBRARY_DIRS};${NLOPT_LIBRARY_DIRS};${COIN_UTILS_LIBRARY_DIRS};${CMAKE_CURRENT_LIST_DIR}/../lib/;${PYTHON_INSTDIR}/cpp_sisso/;${FMT_LIBRARY_DIRS})
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)
......
......@@ -38,23 +38,23 @@ BOOST_CLASS_EXPORT_GUID(InvParamNode, "InvParamNode")
BOOST_CLASS_EXPORT_GUID(SinParamNode, "SinParamNode")
BOOST_CLASS_EXPORT_GUID(CosParamNode, "CosParamNode")
BOOST_CLASS_EXPORT_GUID(AddParamTopLevNode, "AddParamTopLevNode")
BOOST_CLASS_EXPORT_GUID(SubParamTopLevNode, "SubParamTopLevNode")
BOOST_CLASS_EXPORT_GUID(AbsDiffParamTopLevNode, "AbsDiffParamTopLevNode")
BOOST_CLASS_EXPORT_GUID(MultParamTopLevNode, "MultParamTopLevNode")
BOOST_CLASS_EXPORT_GUID(DivParamTopLevNode, "DivParamTopLevNode")
BOOST_CLASS_EXPORT_GUID(SqParamTopLevNode, "SqParamTopLevNode")
BOOST_CLASS_EXPORT_GUID(SqrtParamTopLevNode, "SqrtParamTopLevNode")
BOOST_CLASS_EXPORT_GUID(CbParamTopLevNode, "CbParamTopLevNode")
BOOST_CLASS_EXPORT_GUID(CbrtParamTopLevNode, "CbrtParamTopLevNode")
BOOST_CLASS_EXPORT_GUID(SixPowParamTopLevNode, "SixPowParamTopLevNode")
BOOST_CLASS_EXPORT_GUID(ExpParamTopLevNode, "ExpParamTopLevNode")
BOOST_CLASS_EXPORT_GUID(NegExpParamTopLevNode, "NegExpParamTopLevNode")
BOOST_CLASS_EXPORT_GUID(LogParamTopLevNode, "LogParamTopLevNode")
BOOST_CLASS_EXPORT_GUID(AbsParamTopLevNode, "AbsParamTopLevNode")
BOOST_CLASS_EXPORT_GUID(InvParamTopLevNode, "InvParamTopLevNode")
BOOST_CLASS_EXPORT_GUID(SinParamTopLevNode, "SinParamTopLevNode")
BOOST_CLASS_EXPORT_GUID(CosParamTopLevNode, "CosParamTopLevNode")
// BOOST_CLASS_EXPORT_GUID(AddParamTopLevNode, "AddParamTopLevNode")
// BOOST_CLASS_EXPORT_GUID(SubParamTopLevNode, "SubParamTopLevNode")
// BOOST_CLASS_EXPORT_GUID(AbsDiffParamTopLevNode, "AbsDiffParamTopLevNode")
// BOOST_CLASS_EXPORT_GUID(MultParamTopLevNode, "MultParamTopLevNode")
// BOOST_CLASS_EXPORT_GUID(DivParamTopLevNode, "DivParamTopLevNode")
// BOOST_CLASS_EXPORT_GUID(SqParamTopLevNode, "SqParamTopLevNode")
// BOOST_CLASS_EXPORT_GUID(SqrtParamTopLevNode, "SqrtParamTopLevNode")
// BOOST_CLASS_EXPORT_GUID(CbParamTopLevNode, "CbParamTopLevNode")
// BOOST_CLASS_EXPORT_GUID(CbrtParamTopLevNode, "CbrtParamTopLevNode")
// BOOST_CLASS_EXPORT_GUID(SixPowParamTopLevNode, "SixPowParamTopLevNode")
// BOOST_CLASS_EXPORT_GUID(ExpParamTopLevNode, "ExpParamTopLevNode")
// BOOST_CLASS_EXPORT_GUID(NegExpParamTopLevNode, "NegExpParamTopLevNode")
// BOOST_CLASS_EXPORT_GUID(LogParamTopLevNode, "LogParamTopLevNode")
// BOOST_CLASS_EXPORT_GUID(AbsParamTopLevNode, "AbsParamTopLevNode")
// BOOST_CLASS_EXPORT_GUID(InvParamTopLevNode, "InvParamTopLevNode")
// BOOST_CLASS_EXPORT_GUID(SinParamTopLevNode, "SinParamTopLevNode")
// BOOST_CLASS_EXPORT_GUID(CosParamTopLevNode, "CosParamTopLevNode")
FeatureSpace::FeatureSpace(
std::shared_ptr<MPI_Interface> mpi_comm,
......@@ -71,7 +71,7 @@ FeatureSpace::FeatureSpace(
double cross_corr_max,
double min_abs_feat_val,
double max_abs_feat_val,
bool param_internal
int max_param_depth
):
_phi(phi_0),
_phi_0(phi_0),
......@@ -93,7 +93,7 @@ FeatureSpace::FeatureSpace(
_n_feat(phi_0.size()),
_n_rung_store(max_store_rung),
_n_rung_generate(n_rung_generate),
_param_internal(param_internal)
_max_param_depth(max_param_depth)
{
initialize_fs(project_type);
}
......@@ -104,7 +104,7 @@ void FeatureSpace::initialize_fs(std::string project_type)
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, _max_phi, _param_internal);
nlopt_wrapper::set_objective(project_type, _prop.data(), _task_sizes, _max_phi, _max_param_depth);
#endif
if(_n_rung_store == -1)
......
......@@ -83,7 +83,8 @@ class FeatureSpace
const int _n_samp; //!< Number of samples (training data)
const int _n_rung_generate; //!< Total number of rungs to generate on the fly
bool _param_internal; //!< True if parameterize all scale and shift parameters in a feature
int _max_param_depth; //!< Max depth to parameterize a feature (default=_max_rung)
public:
/**
......@@ -120,7 +121,7 @@ public:
double cross_corr_max=1.0,
double min_abs_feat_val=1e-50,
double max_abs_feat_val=1e50,
bool param_internal=true
int max_param_depth = 100
);
/**
......@@ -303,7 +304,7 @@ public:
double cross_corr_max=1.0,
double min_abs_feat_val=1e-50,
double max_abs_feat_val=1e50,
bool param_internal=true
int max_param_depth = 100
);
/**
......@@ -338,7 +339,7 @@ public:
double cross_corr_max=1.0,
double min_abs_feat_val=1e-50,
double max_abs_feat_val=1e50,
bool param_internal=true
int max_param_depth = 100
);
/**
......
......@@ -306,7 +306,7 @@ public:
* @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;};
inline int n_params(int n_cur=0, int depth = 1){return n_cur;};
/**
* @brief Set the values of the training data for the feature inside of the value storage arrays
......@@ -314,7 +314,7 @@ public:
* @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);};
inline void set_value(const double* params, int offset = -1, int depth = 1){set_value(offset);};
/**
* @brief The pointer to where the feature's training data is stored
......@@ -323,7 +323,7 @@ public:
* @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);};
inline double* value_ptr(const double* params, int offset = -1, int depth = 1){return value_ptr(offset);};
/**
* @brief Set the values of the test data for the feature inside of the value storage arrays
......@@ -331,7 +331,7 @@ public:
* @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);};
inline void set_test_value(const double* params, int offset = -1, int depth = 1){set_test_value(offset);};
/**
* @brief The pointer to where the feature's test data is stored
......@@ -340,7 +340,7 @@ public:
* @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);};
inline double* test_value_ptr(const double* params, int offset = -1, int depth = 1){return test_value_ptr(offset);};
/**
* @brief The domain for the feature (min/max values)
......@@ -348,7 +348,7 @@ public:
* @param params parameter values for non-linear operations
* @return the domain
*/
Domain domain(double* params){return _domain;};
Domain domain(double* params, int depth = 1){return _domain;};
/**
* @brief The expression of the feature
......@@ -356,7 +356,7 @@ public:
* @param params parameter values for non-linear operations
* @return feature expression
*/
std::string expr(double* params){return _expr;};
std::string expr(double* params, int depth = 1){return _expr;};
/**
* @brief Set the bounds for the nl parameterization
......@@ -364,7 +364,7 @@ public:
* @param lb pointer to the lower bounds data
* @param ub pointer to the upper bounds data
*/
inline void set_bounds(double* lb, double* ub, int from_parent=2){};
inline void set_bounds(double* lb, double* ub, int from_parent=2, int depth = 1){};
/**
* @brief Calculates the derivative of an operation with respect to the parameters for a given sample
......
......@@ -346,7 +346,7 @@ public:
* @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;
virtual int n_params(int n_cur = 0, int depth = 1) = 0;
/**
* @brief Set the values of the training data for the feature inside of the value storage arrays
......@@ -354,7 +354,7 @@ public:
* @param offset(int) Key to determine which part of the temporary storage array to look into
* @param params pointer to the parameter values
*/
virtual void set_value(const double* params, int offset = -1) = 0;
virtual void set_value(const double* params, int offset = -1, int depth = 1) = 0;
/**
* @brief The pointer to where the feature's training data is stored
......@@ -363,7 +363,7 @@ public:
* @param params pointer to the parameter values
* @returns the pointer to the feature's data
*/
virtual double* value_ptr(const double* params, int offset = -1) = 0;
virtual double* value_ptr(const double* params, int offset = -1, int depth = 1) = 0;
/**
* @brief Set the values of the test data for the feature inside of the value storage arrays
......@@ -371,7 +371,7 @@ public:
* @param offset(int) Key to determine which part of the temporary storage array to look into
* @param params pointer to the parameter values
*/
virtual void set_test_value(const double* params, int offset = -1) = 0;
virtual void set_test_value(const double* params, int offset = -1, int depth = 1) = 0;
/**
* @brief The pointer to where the feature's test data is stored
......@@ -380,7 +380,7 @@ public:
* @param params pointer to the parameter values
* @returns the pointer to the feature's data
*/
virtual double* test_value_ptr(const double* params, int offset = -1) = 0;
virtual double* test_value_ptr(const double* params, int offset = -1, int depth = 1) = 0;
/**
* @brief The domain for the feature (min/max values)
......@@ -388,7 +388,7 @@ public:
* @param params parameter values for non-linear operations
* @return the domain
*/
virtual Domain domain(double* params) = 0;
virtual Domain domain(double* params, int depth = 1) = 0;
/**
* @brief The expression of the feature
......@@ -396,7 +396,7 @@ public:
* @param params parameter values for non-linear operations
* @return feature expression
*/
virtual std::string expr(double* params) = 0;
virtual std::string expr(double* params, int depth = 1) = 0;
/**
* @brief Set the bounds for the nl parameterization
......@@ -404,7 +404,7 @@ public:
* @param lb pointer to the lower bounds data
* @param ub pointer to the upper bounds data
*/
virtual void set_bounds(double* lb, double* ub, int from_parent=2) = 0;
virtual void set_bounds(double* lb, double* ub, int from_parent=2, int depth = 1) = 0;
/**
* @brief Calculates the derivative of an operation with respect to the parameters for a given sample
......
......@@ -22,7 +22,9 @@
#include<iomanip>
// #ifdef PARAMETERIZE
#ifdef PARAMETERIZE
#include<nl_opt/NLOptWrapper.hpp>
// #include "ceres/ceres.h"
// #include "glog/logging.h"
......@@ -32,7 +34,7 @@
// using ceres::Problem;
// using ceres::Solver;
// using ceres::Solve;
// #endif
#endif
#ifdef PY_BINDINGS
#include <python/conversion_utils.hpp>
......@@ -346,7 +348,10 @@ public:
* @brief returns the number of theoretical parameters for this feature
* @return the number of theoretical parameters
*/
virtual inline int n_params(int n_cur = 0){return std::accumulate(_feats.begin(), _feats.end(), 2, [](double tot, node_ptr feat){return tot + feat->n_params();});}
virtual inline int n_params(int n_cur = 0, int depth = 1)
{
return (depth > nlopt_wrapper::_max_param_depth) ? 0 : std::accumulate(_feats.begin(), _feats.end(), 2, [&](double tot, node_ptr feat){return tot + feat->n_params(0, depth + 1);});
}
/**
* @brief Set the values of the training data for the feature inside of the value storage arrays
......@@ -354,7 +359,7 @@ public:
* @param offset(int) Key to determine which part of the temporary storage array to look into
* @param params pointer to the parameter values
*/
virtual void set_value(const double* params, int offset = -1) = 0;
virtual void set_value(const double* params, int offset = -1, int depth = 1) = 0;
/**
* @brief The pointer to where the feature's training data is stored
......@@ -363,13 +368,13 @@ public:
* @param params pointer to the parameter values
* @returns the pointer to the feature's data
*/
double* value_ptr(const double* params, int offset = -1)
double* value_ptr(const double* params, int offset = -1, int depth = 1)
{
if(_selected)
return node_value_arrs::get_d_matrix_ptr(_d_mat_ind);
offset = (offset == -1) ? rung() : offset;
set_value(params, offset);
set_value(params, offset, depth);
return node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, offset, false);
}
......@@ -379,7 +384,7 @@ public:
* @param offset(int) Key to determine which part of the temporary storage array to look into
* @param params pointer to the parameter values
*/
virtual void set_test_value(const double* params, int offset = -1) = 0;
virtual void set_test_value(const double* params, int offset = -1, int depth = 1) = 0;
/**
* @brief The pointer to where the feature's test data is stored
......@@ -388,10 +393,10 @@ public:
* @param params pointer to the parameter values
* @returns the pointer to the feature's data
*/
double* test_value_ptr(const double* params, int offset = -1)
double* test_value_ptr(const double* params, int offset = -1, int depth = 1)
{
offset = (offset == -1) ? rung() : offset;
set_test_value(params, offset);
set_test_value(params, offset, depth);
return node_value_arrs::get_test_value_ptr(_arr_ind, _feat_ind, offset, false);
}
......@@ -425,7 +430,7 @@ public:
* @param lb pointer to the lower bounds data
* @param ub pointer to the upper bounds data
*/
virtual void set_bounds(double* lb, double* ub, int from_parent=2) = 0;
virtual void set_bounds(double* lb, double* ub, int from_parent=2, int depth = 1) = 0;
/**
* @brief Calculates the derivative of an operation with respect to the parameters for a given sample
......
......@@ -10,6 +10,7 @@
#define ABS_VAL_NODE
#include <feature_creation/node/operator_nodes/OperatorNode.hpp>
#include <fmt/core.h>
// DocString: cls_abs_node
/**
......@@ -69,7 +70,14 @@ public:
/**
* @brief Get the expression for the overall feature (From root node down)
*/
virtual inline std::string expr(){return "|" + _feats[0]->expr() + "|";}
inline std::string expr()
{
return fmt::format(
"|{}|",
_feats[0]->expr()
);
}
// virtual inline std::string expr(){return "|" + _feats[0]->expr() + "|";}
// DocString: abs_node_set_value
/**
......@@ -156,7 +164,7 @@ public:
* @param offset(int) Key to determine which part of the temporary storage array to look into
* @param params pointer to the parameter values
*/
void set_value(const double* params, int offset = -1);
void set_value(const double* params, int offset=-1, int depth=1);
/**
* @brief Set the values of the test data for the feature inside of the value storage arrays
......@@ -164,7 +172,7 @@ public:
* @param offset(int) Key to determine which part of the temporary storage array to look into
* @param params pointer to the parameter values
*/
void set_test_value(const double* params, int offset = -1);
void set_test_value(const double* params, int offset=-1, int depth=1);
/**
* @brief The domain for the feature (min/max values)
......@@ -172,7 +180,13 @@ public:
* @param params parameter values for non-linear operations
* @return the domain
*/
inline Domain domain(double* params){return _feats[0]->domain(params + 2).abs(params[0], params[1]);}
inline Domain domain(double* params, int depth=1)
{
if(depth < nlopt_wrapper::_max_param_depth)
return _feats[0]->domain(params + 2, depth + 1).abs(params[0], params[1]);
else
return _feats[0]->domain().abs(params[0], params[1]);
}
/**
* @brief The expression of the feature
......@@ -180,7 +194,25 @@ public:
* @param params parameter values for non-linear operations
* @return feature expression
*/
inline std::string expr(double* params){return "|" + std::to_string(params[0]) + "*" + _feats[0]->expr(params + 2) + " + " + std::to_string(params[1]) + "|";}
inline std::string expr(double* params, int depth=1)
{
// if(depth < nlopt_wrapper::_max_param_depth)
// return "|" + std::to_string(params[0]) + "*" + _feats[0]->expr(params + 2) + " + " + fmt::format(params[1]) + "|";
// else
// return "|" + std::to_string(params[0]) + "*" + _feats[0]->expr() + " + " + fmt::format(params[1]) + "|";
// if(depth < nlopt_wrapper::_max_param_depth)
// return fmt::format("|{:.10e} * {} {:+15.10e}|", params[0], _feats[0]->expr(params + 2), params[1]);
// else
// return fmt::format("|{:.10e} * {} {:+15.10e}|", params[0], _feats[0]->expr(), params[1]);
return fmt::format(
"|{:.10e} * {} {:+15.10e}|",
params[0],
(depth < nlopt_wrapper::_max_param_depth ? _feats[0]->expr(params + 2, depth + 1) : _feats[0]->expr()),
params[1]
);
}
/**
* @brief Set the bounds for the nl parameterization
......@@ -188,7 +220,7 @@ public:
* @param lb pointer to the lower bounds data
* @param ub pointer to the upper bounds data
*/
virtual void set_bounds(double* lb, double* ub, int from_parent=2);
virtual void set_bounds(double* lb, double* ub, int from_parent=2, int depth = 1);
/**
* @brief Calculates the derivative of an operation with respect to the parameters for a given sample
......
#include <feature_creation/node/operator_nodes/allowed_operator_nodes/abs/parameterize_top_lev_absolute_value.hpp>
void generateAbsParamTopLevNode(std::vector<node_ptr>& feat_list, node_ptr feat, int& feat_ind, double l_bound, double u_bound, std::vector<double>& prop)
{
++feat_ind;
node_ptr new_feat = std::make_shared<AbsParamTopLevNode>(feat, feat_ind, prop);
new_feat->set_value();
if(new_feat->is_nan() || new_feat->is_const() || (util_funcs::max_abs_val<double>(new_feat->value_ptr(), new_feat->n_samp()) > u_bound) || (util_funcs::max_abs_val<double>(new_feat->value_ptr(), new_feat->n_samp()) < l_bound))
return;
feat_list.push_back(new_feat);
}
AbsParamTopLevNode::AbsParamTopLevNode()
{}
AbsParamTopLevNode::AbsParamTopLevNode(node_ptr feat, int feat_ind, double l_bound, double u_bound, std::vector<double>& prop) :
AbsParamNode(feat, feat_ind, l_bound, u_bound)
{
_params.resize(n_params(), 0.0);
get_parameters(prop);
if(is_nan() || is_const() || (util_funcs::max_abs_val<double>(value_ptr(), _n_samp) > u_bound) || (util_funcs::max_abs_val<double>(value_ptr(), _n_samp) < l_bound))
throw InvalidFeatureException();
}
AbsParamTopLevNode::AbsParamTopLevNode(node_ptr feat, int feat_ind, std::vector<double>& prop) :
AbsParamNode(feat, feat_ind)
{
_params.resize(n_params(), 0.0);
get_parameters(prop);
}
AbsParamTopLevNode::AbsParamTopLevNode(node_ptr feat, int feat_ind, double l_bound, double u_bound) :
AbsParamNode(feat, feat_ind, l_bound, u_bound)
{
_params.resize(n_params(), 0.0);
}
void AbsParamTopLevNode::set_value(int offset)
{
offset = (offset == -1) ? rung() : offset;
if(_selected)
allowed_op_funcs::abs(_n_samp, _feats[0]->value_ptr(offset + 2), _params[0], _params[1], node_value_arrs::get_d_matrix_ptr(_d_mat_ind));
allowed_op_funcs::abs(_n_samp, _feats[0]->value_ptr(offset + 2), _params[0], _params[1], node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, offset, false));
}
void AbsParamTopLevNode::set_test_value(int offset)
{
offset = (offset == -1) ? rung() : offset;
allowed_op_funcs::abs(_n_test_samp, _feats[0]->test_value_ptr(offset + 2), _params[0], _params[1], node_value_arrs::get_test_value_ptr(_arr_ind, _feat_ind, offset, false));
}
void AbsParamTopLevNode::set_bounds(double* lb, double* ub, int from_parent)
{
lb[0] = _sign_alpha;
ub[0] = _sign_alpha;
}
/** @file feature_creation/node/operator_nodes/allowed_operator_nodes/abs/parameterize_top_levabsolute_value.hpp
* @brief Class describing the parameterized absolute value operator
*
* This class represents the parameterized unary operator -> |alpha * A + a|
*
* @author Thomas A. R. Purcell (tpurcell)
* @bug No known bugs.
*/
#ifndef PARAM_TOP_LEV_ABS_VAL_NODE
#define PARAM_TOP_LEV_ABS_VAL_NODE
#include <feature_creation/node/operator_nodes/allowed_operator_nodes/abs/parameterized_absolute_value.hpp>
#include <nl_opt/NLOptWrapper.hpp>
// DocString: cls_abs_node
/**
* @brief Node for the absolute value operator
*
*/
class AbsParamTopLevNode: public AbsParamNode
{
using AbsParamNode::set_value;
using AbsParamNode::set_test_value;
using AbsParamNode::value_ptr;
using AbsParamNode::test_value_ptr;
using AbsParamNode::domain;
using AbsParamNode::expr;
friend class boost::serialization::access;