diff --git a/src/.removed_features/domain/Domain.hpp b/src/.removed_features/domain/Domain.hpp index d100acf2ae1d84fddee66ee8f7fb85e1568eaa44..7d2b657f5f10388e0e95fa1b34c2612db35cde00 100644 --- a/src/.removed_features/domain/Domain.hpp +++ b/src/.removed_features/domain/Domain.hpp @@ -1,5 +1,5 @@ /** @file feature_creation/domain/Domain.hpp - * @brief A representation of the domain for each feature + * @brief A representation of the domain for each feature * * A dictionary representation of the domain for a features (key = domain, value = power) * diff --git a/src/.removed_features/log_fit_c_regressor/ModelLogRegressorFitC.hpp b/src/.removed_features/log_fit_c_regressor/ModelLogRegressorFitC.hpp index f8023684d1f83ef0223d488653de43856f793265..8a88603d299bfeabb7f508c21775b11c587fb09f 100644 --- a/src/.removed_features/log_fit_c_regressor/ModelLogRegressorFitC.hpp +++ b/src/.removed_features/log_fit_c_regressor/ModelLogRegressorFitC.hpp @@ -1,5 +1,5 @@ /** @file descriptor_identifier/ModelLogRegressorFitC/ModelLogRegressorFitC.hpp - * @brief Object to store the models generated form SISSO + * @brief Object to store the models generated form SISSO * * Creates a ModelLogRegressorFitC generated from SISSO and the corresponding output file. * It also has functionality to read in an output file to regenerate the model. @@ -123,9 +123,9 @@ public: */ inline std::vector<std::array<double, 2>> c_coefs(){return _c_coefs;} /** - * @brief Copy the error into a new array + * @brief Copy the training error into a different vector * - * @param res pointer to the beginning of the vector to store the residual + * @param res Pointer to the head of the new vector to store the residual */ inline void copy_error(double* res){std::copy_n(_train_error.data(), _n_samp_train, res);} @@ -153,4 +153,4 @@ public: */ std::ostream& operator<< (std::ostream& outStream, const ModelLogRegressorFitC& model); -#endif \ No newline at end of file +#endif diff --git a/src/.removed_features/log_fit_c_regressor/SISSOLogRegressorFitC.hpp b/src/.removed_features/log_fit_c_regressor/SISSOLogRegressorFitC.hpp index 961eb2809ad6d5b111e00e41a191f6380a63f15b..01eb4c381e9434adc2719588629908144aa2eb81 100644 --- a/src/.removed_features/log_fit_c_regressor/SISSOLogRegressorFitC.hpp +++ b/src/.removed_features/log_fit_c_regressor/SISSOLogRegressorFitC.hpp @@ -1,5 +1,5 @@ /** @file descriptor_identifier/SISSOLogRegressorFitC.hpp - * @brief Perform SISSO on a previously generated Feature Space + * @brief Perform SISSO on a previously generated Feature Space * * Takes in a feature space and performs SISSO on it while storing the selected features in _models * @@ -41,7 +41,7 @@ public: * @param leave_out_inds List of indexes from the initial data file in the test set * @param n_dim Maximum dimensionality of the generated models * @param n_residual Number of residuals to pass to the next SIS operation - * @param n_models_store Number of features to store in files + * @param n_models_store The number of models to output to files * @param fix_intrecept If true fix intercept to 0 */ SISSOLogRegressorFitC(std::shared_ptr<FeatureSpace> feat_space, Unit prop_unit, std::vector<double> prop, std::vector<double> prop_test, std::vector<int> task_sizes_train, std::vector<int> task_sizes_test, std::vector<int> leave_out_inds, int n_dim, int n_residual, int n_models_store, bool fix_intercept=false); @@ -76,7 +76,7 @@ public: * @param prop The property to fit * @param n_dim the dimensionality of the model */ - void l0_norm(std::vector<double>& prop, int n_dim); + void l0_regularization(std::vector<double>& prop, int n_dim); /** * @brief Acessor function for models @@ -97,7 +97,7 @@ public: * @param leave_out_inds List of indexes from the initial data file in the test set * @param n_dim Maximum dimensionality of the generated models * @param n_residual Number of residuals to pass to the next SIS operation - * @param n_models_store Number of features to store in files + * @param n_models_store The number of models to output to files * @param fix_intrecept If true fix intercept to 0 */ SISSOLogRegressorFitC( @@ -127,7 +127,7 @@ public: * @param leave_out_inds List of indexes from the initial data file in the test set * @param n_dim Maximum dimensionality of the generated models * @param n_residual Number of residuals to pass to the next SIS operation - * @param n_models_store Number of features to store in files + * @param n_models_store The number of models to output to files * @param fix_intrecept If true fix intercept to 0 */ SISSOLogRegressorFitC( diff --git a/src/classification/ConvexHull1D.hpp b/src/classification/ConvexHull1D.hpp index 8125c442508137c41665249106e6a9d934108bbc..d94d542811afaabb26feda34e664ccb95ce34fa2 100644 --- a/src/classification/ConvexHull1D.hpp +++ b/src/classification/ConvexHull1D.hpp @@ -11,13 +11,12 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -/** @file classificationutils.hpp - * @brief A set of functions to create convex hulls, and compare overlap/distance +/** @file classification/ConvexHull1D.hpp + * @brief A set of functions to create convex hulls, and compare overlap/distance * * @author Thomas A. R. Purcell (tpurcell) * @bug No known bugs. */ - #ifndef CONVEX_UTILS #define CONVEX_UTILS @@ -29,13 +28,13 @@ class ConvexHull1D { protected : - std::vector<double> _sorted_value; //!< The value sorted based on the property + std::vector<double> _sorted_value; //!< The value of the input vector sorted based on the property vector std::vector<double> _cls_max; //!< The maximum value of the property in each class std::vector<double> _cls_min; //!< The minimum value of the property in each class - std::vector<int> _sorted_prop_inds; //!< The value sorted based on the property - std::vector<int> _cls_start; //!< The number of values in each class - std::vector<int> _cls_sz; //!< The number of values in each class + std::vector<int> _sorted_prop_inds; //!< The indexes of where each element of an input vector is in _sorted_value + std::vector<int> _cls_start; //!< The element where each new class starts + std::vector<int> _cls_sz; //!< The number of elements in each class std::vector<double> _task_scores; //!< The scores for each task @@ -46,20 +45,20 @@ public: /** * @brief Constructor * - * @param sizes The size of the tasks + * @param sizes The size of each task * @param prop The pointer to the property vector */ ConvexHull1D(const std::vector<int> sizes, const double* prop); /** - * @brief Initialize the projection objects + * @brief Default constructor */ ConvexHull1D(); /** * @brief Initialize the projection objects * - * @param sizes The size of the tasks + * @param sizes The size of each task * @param prop The pointer to the property vector */ void initialize_prop(const std::vector<int>& sizes, const double* prop); @@ -67,7 +66,7 @@ public: /** * @brief Calculate the projection scores of a set of features to a vector via Pearson correlation * - * @param value The pointer to the value of the data + * @param value The pointer to the input data * @param width The buffer used for calculating the overlap * * @returns The projection score for the particular feature diff --git a/src/classification/LPWrapper.hpp b/src/classification/LPWrapper.hpp index d517d130b0bd4a7bfae4deeee823f8a573623c5a..5002b33712378f62ad875583165d470e73aec32e 100644 --- a/src/classification/LPWrapper.hpp +++ b/src/classification/LPWrapper.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file classification/LPWrapper.hpp - * @brief A class used to wrap Coin-Clp into a single class + * @brief A class used to wrap Coin-Clp into a single class * * @author Thomas A. R. Purcell (tpurcell) * @bug No known bugs. @@ -30,9 +30,9 @@ class LPWrapper { protected: - ClpSimplex _simplex; //!< Model used to find if a point is inside the convex hull + ClpSimplex _simplex; //!< LP algorithm used to determine if a point is inside the convex hull - std::vector<double> _elements; //!< The elements of the A matrix (descriptor matrix) for the linear optimization problem + std::vector<double> _elements; //!< The elements of the A matrix (descriptor matrix) for the linear programing problem std::vector<double> _row_lower; //!< The lower bound for the row constraints (value of the data point to check) std::vector<double> _row_upper; //!< The upper bound for the row constraints (value of the data point to check) std::vector<double> _row_lower_test; //!< The lower bound for the row constraints for the test set (value of the data point to check) @@ -42,20 +42,20 @@ protected: std::vector<double> _column_upper; //!< The upper bound for the column constraints (all infinity) std::vector<int> _column_start; //!< Vector len(n_samples) of the starting column for the A matrix - std::vector<int> _row; //!< Vector saying what row each data point is in - std::vector<int> _row_test; //!< Vector saying what row each data point is in for the test set + std::vector<int> _row; //!< Vector storing what row each data point is in + std::vector<int> _row_test; //!< Vector storing what row each data point is in for the test set - std::vector<int> _n_row_per_class; //!< Number of rows per class - std::vector<int> _n_row_per_class_test; //!< Number of rows per class in the test set + std::vector<int> _n_row_per_class; //!< //!< A vector storing the number of rows in each class/task combination for the training set [task * N_TASK * N_CLASS + class] + std::vector<int> _n_row_per_class_test; //!< //!< A vector storing the number of rows in each class/task combination for the test set [task * N_TASK * N_CLASS + class] - double _tol; //!< tolerance value (\epsilon) for the final row constraint + double _tol; //!< tolerance value (\epsilon) for the final row constraint 1 +/- _tol for the upper and lower constraint int _n_dim; //!< The number of dimensions for the SVM problem - int _n_samp; //!< The number of samples per feature - int _n_samp_test; //!< The number of samples per feature in the test set + int _n_samp; //!< The number of samples in the training data per feature + int _n_samp_test; //!< The number of samples in the test data per feature int _n_class; //!< The number of classes in the data set int _n_row; //!< The number of rows in the A matrix - int _task_num; //!< The task number the LPWrapper is used for + int _task_num; //!< The current task number the LPWrapper is used for int _n_col; //!< The number of columns in the A matrix int _n_overlap; //!< The number of misclassified data points in the training set int _n_overlap_test; //!< The number of misclassified data points in the test set @@ -66,14 +66,14 @@ public: /** * @brief The constructor for the LPWrapper * - * @param samp_per_class number of samples per class - * @param task_num The task ID number to perform the calculation + * @param samp_per_class A vector storing the number of rows in each class/task combination for the training set [task * N_TASK * N_CLASS + class] + * @param task_num The task ID number used to perform the calculation * @param n_class Number of classes in the dataset * @param n_dim Number of dimensions of the problem * @param n_samp Number of samples in the dataset - * @param n_samp_test Number of samples in the dataset for the test set - * @param samp_per_class number of samples per class for the test set * @param tol The tolerance used to have a fuzzy border around the convex hull + * @param samp_per_class A vector storing number of test samples per class + * @param n_samp_test TheA vector storing tnumber of rows in each class/task combination for the test set [task * N_TASK * N_CLASS + class] */ LPWrapper( std::vector<int> samp_per_class, @@ -122,75 +122,69 @@ public: /** * @brief Copies the data from a set of feature indexes (sorted_dmatrix) into the x_space * - * @param cls class the number of the class to copy over - * @param inds list of indexes to pull data for + * @param cls Index defining what class to copy + * @param inds A vector storing the _d_mat_ind of the features to pull data from the Descriptor Matrix storage array */ void copy_data(const int cls, const std::vector<int> inds); /** * @brief Copies the data from a set data pointers * - * @param cls class the number of the class to copy over - * @param val_ptrs The pointers to the feature's data + * @param cls Index defining what class to copy + * @param val_ptrs A vector storing pointers to the features training data + * @param test_val_ptrs A vector storing pointers to the features test data */ void copy_data(const int cls, const std::vector<double*> val_ptrs, const std::vector<double*> test_val_ptrs); /** - * @brief Copy the data from a set of feature indexes (sorted_dmatrix) into the x_space and train the SVM model + * @brief Calculate the number of points in the overlap region of the convex hulls for the training set * - * @param inds list of indexes to pull data for + * @param inds A vector storing the _d_mat_ind of the features to pull data from the Descriptor Matrix storage array */ int get_n_overlap(const std::vector<int> inds); /** - * @brief Copy tthe data from a set data pointers and train the SVM model + * @brief Calculate the number of points in the overlap region of the convex hulls for the training and test sets and set the error vectors * - * @param val_ptrs The pointers to the feature's data - * @param test_val_ptrs The pointers to the feature's data (Test set) - * @param error Pointer to the error vector - * @param test_error Pointer to the test_error + * @param val_ptrs A vector storing pointers to the features training data + * @param test_val_ptrs A vector storing pointers to the features test data + * @param error Pointer to the head of the error vector + * @param test_error Pointer to the head of the test error vector */ void set_n_overlap(const std::vector<double*> val_ptrs, const std::vector<double*> test_val_ptrs, double* error, double* test_error); /** * @brief The number of classes in the training set - * @return The number of classes in the training set */ inline int n_class() const {return _n_class;} /** - * @brief The task id number - * @return The task id number + * @brief The index of the current task that is stored in the LPWrapper */ inline int task_num() const {return _task_num;} /** * @brief The number of dimensions of the Convex Hulls - * @return The number of dimensions of the Convex Hulls */ inline int n_dim() const {return _n_dim;} /** * @brief The number of samples in the training set - * @return The number of samples in the training set */ inline int n_samp() const {return _n_samp;} /** * @brief The number of samples in the test set - * @return The number of samples in the test set */ inline int n_samp_test() const {return _n_samp_test;} /** * @brief Number of misclassified samples in the data set - * @return Number of misclassified samples in the data set */ inline int n_overlap() const {return _n_overlap;} /** * @brief Number of misclassified samples in the test set - * @return Number of misclassified samples in the test set */ inline int n_overlap_test() const {return _n_overlap_test;} }; diff --git a/src/classification/SVMWrapper.cpp b/src/classification/SVMWrapper.cpp index 36736850277772192cc6b08627a658cd1bb6ade2..4fa2bf162830be4a22e07df08df693835229fc69 100644 --- a/src/classification/SVMWrapper.cpp +++ b/src/classification/SVMWrapper.cpp @@ -250,19 +250,19 @@ void SVMWrapper::train(const std::vector<double*> val_ptrs, const bool remap_coe train(remap_coefs); } -std::vector<double> SVMWrapper::predict(const int n_test_samp, const std::vector<double*> val_ptrs) +std::vector<double> SVMWrapper::predict(const int n_samp_test, const std::vector<double*> val_ptrs) { if(val_ptrs.size() > _n_dim) { throw std::logic_error("Size of the val_ptrs vector is larger than _n_dim"); } - std::vector<double> y_est_test(n_test_samp, 0.0); + std::vector<double> y_est_test(n_samp_test, 0.0); - std::vector<svm_node>x_space_test(n_test_samp * (val_ptrs.size() + 1)); - std::vector<svm_node*>x_test(n_test_samp); + std::vector<svm_node>x_space_test(n_samp_test * (val_ptrs.size() + 1)); + std::vector<svm_node*>x_test(n_samp_test); - for(int ss = 0; ss < n_test_samp; ++ss) + for(int ss = 0; ss < n_samp_test; ++ss) { for(int dd = 0; dd < val_ptrs.size(); ++dd) { diff --git a/src/classification/SVMWrapper.hpp b/src/classification/SVMWrapper.hpp index f584c91439cc49503259f4567dc4332861a8a546..c8a589551a0c9c7dcfa4ae2c487d7aea34f043ca 100644 --- a/src/classification/SVMWrapper.hpp +++ b/src/classification/SVMWrapper.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file classification/SVMWrapper.hpp - * @brief A class used to wrap libsvm in more C++ oriented data structure + * @brief A class used to wrap libsvm in more C++ oriented data structure * * @author Thomas A. R. Purcell (tpurcell) * @bug No known bugs. @@ -47,7 +47,7 @@ protected: const double _C; //!< The C parameter for the SVM calculation const int _n_dim; //!< The number of dimensions for the SVM problem - const int _n_samp; //!< The number of samples per feature + const int _n_samp; //!< The number of training samples per feature const int _n_class; //!< The number of classes in the data set int _n_misclassified; //!< The number of misclassified data points in the training set @@ -57,7 +57,7 @@ public: * * @param n_class Number of classes in the dataset * @param n_dim Number of dimensions of the problem - * @param n_samp Number of samples in the dataset + * @param n_samp Number of training samples in the dataset * @param prop pointer to the start of the property vector */ SVMWrapper(const int n_class, const int n_dim, const int n_samp, const double* prop); @@ -77,7 +77,7 @@ public: * @param C The C value for the SVM calculation * @param n_class Number of classes in the dataset * @param n_dim Number of dimensions of the problem - * @param n_samp Number of samples in the dataset + * @param n_samp Number of training samples in the dataset * @param prop pointer to the start of the property vector */ SVMWrapper(const double C, const int n_class, const int n_dim, const int n_samp, const double* prop); @@ -128,7 +128,7 @@ public: /** * @brief Copies the data from a set of feature indexes (sorted_dmatrix) into the x_space * - * @param inds list of indexes to pull data for + * @param inds A vector storing the _d_mat_ind of the features to pull data from the Descriptor Matrix storage array * @param task the task number for the calculation */ void copy_data(const std::vector<int> inds, const int task); @@ -150,16 +150,16 @@ public: /** * @brief Copy the data from a set of feature indexes (sorted_dmatrix) into the x_space and train the SVM model * - * @param inds list of indexes to pull data for + * @param inds A vector storing the _d_mat_ind of the features to pull data from the Descriptor Matrix storage array * @param task the task number for the calculation * @param remap_coefs If true remap the final coefficients back to the unscaled feature space */ void train(const std::vector<int> inds, const int task, const bool remap_coefs=true); /** - * @brief Copy tthe data from a set data pointers and train the SVM model + * @brief Copy the data from a set data pointers and train the SVM model * - * @param val_ptrs The pointers to the feature's data + * @param val_ptrs A vector storing pointers to the features training data * @param remap_coefs If true remap the final coefficients back to the unscaled feature space */ void train(const std::vector<double*> val_ptrs, const bool remap_coefs=true); @@ -167,58 +167,50 @@ public: /** * @brief Predict the class of a set of data from the SVM model * - * @param n_test_samp the number of test samples to predict the class off - * @param val_ptrs vector of the data pointers for the feature's test set + * @param n_samp_test the number of test samples to predict the class off + * @param val_ptrs A vector storing pointers to the features test data * * @return The predicted class of the test samples */ - std::vector<double> predict(const int n_test_samp, const std::vector<double*> val_ptrs); + std::vector<double> predict(const int n_samp_test, const std::vector<double*> val_ptrs); /** * @brief the coefficients of the decision planes for each of the one against one SVM models - * @return A list of all coefficients for the decision planes */ inline std::vector<std::vector<double>> coefs(){return _coefs;} /** - * @brief the list of the bias terms in all the Svm models - * @return The bias term for each SVM generated decision function + * @brief the list of the bias terms in all the SVM models */ inline std::vector<double> intercept() const {return _intercept;} /** * @brief The number of classes in the training set - * @return The number of classes in the training set */ inline int n_class() const {return _n_class;} /** * @brief The number of dimensions of the SVM model - * @return The number of dimensions of the SVM model */ inline int n_dim() const {return _n_dim;} /** * @brief The number of samples in the training set - * @return The number of samples in the training set */ inline int n_samp() const {return _n_samp;} /** * @brief The predicted class for each sample in the data set - * @return The predicted class for each sample in the data set */ inline std::vector<double> y_estimate() const {return _y_est;} /** * @brief The actual class for each sample in the data set - * @return The actual class for each sample in the data set */ inline std::vector<double> y_actual() const {return _y;} /** * @brief Number of misclassified samples in the data set - * @return Number of misclassified samples in the data set */ inline int n_misclassified() const {return _n_misclassified;} diff --git a/src/classification/prop_sorted_d_mat.hpp b/src/classification/prop_sorted_d_mat.hpp index 143abeb2937c0a69229f68318bf6d9e1286d7462..8434fb2f4014c461f767cc7aed6bea366b33c627 100644 --- a/src/classification/prop_sorted_d_mat.hpp +++ b/src/classification/prop_sorted_d_mat.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file classification/prop_sorted_d_mat.hpp - * @brief Central storage area for a sorted descriptor matrix based on the task/class of a sample + * @brief Central storage area for a sorted descriptor matrix based on the task/class of a sample * @author Thomas A. R. Purcell (tpurcell) * @bug No known bugs. @@ -27,10 +27,10 @@ namespace prop_sorted_d_mat { - extern std::vector<double> SORTED_D_MATRIX; //!< The descriptor matrix + extern std::vector<double> SORTED_D_MATRIX; //!< The descriptor matrix with the feature's input data sorted by the class index extern std::vector<int> CLASS_START; //!< The starting point for each class - extern std::vector<int> N_SAMPLES_PER_CLASS; //!< number of features in each class/task combination [task * N_TASK * N_CLASS + class] + extern std::vector<int> N_SAMPLES_PER_CLASS; //!< The number of samples in each class/task combination [task * N_TASK * N_CLASS + class] extern int N_TASK; //!< Number of tasks for the calculation extern int N_CLASS; //!< Number of classes per task for the calculation @@ -44,20 +44,19 @@ namespace prop_sorted_d_mat * @param n_feat The number of features * @param n_task The number of tasks * @param n_class The number of classes - * @param n_samples_per_class The number of samples in each class + * @param n_samples_per_class The number of samples in each class/task combination [task * N_TASK * N_CLASS + class] */ void initialize_sroted_d_matrix_arr(int n_feat, int n_task, int n_class, std::vector<int> n_samples_per_class); /** - * @brief Resize the descriptor matrix - * @details Using the total number of features + * @brief Resize the descriptor matrix to match the current number of features * * @param n_feats Number of features to select */ void resize_sroted_d_matrix_arr(int n_feats); /** - * @brief Get the size of a particular class + * @brief Get the number of samples in a particular task/class combination * * @param task The task number * @param cls the class number @@ -78,11 +77,13 @@ namespace prop_sorted_d_mat { return SORTED_D_MATRIX[feat_ind * N_SAMPLES + samp_ind]; } + /** * @brief Access the sorted descriptor matrix by feature ind * - * @param feat_ind feature index - * @return pointer to the start of the selected feature + * @param feat_ind The feature index + * + * @return Pointer to the start of the selected feature */ inline double* access_sorted_d_matrix(int feat_ind) { @@ -90,11 +91,11 @@ namespace prop_sorted_d_mat } /** - * @brief Access the sorted descriptor matrix by the class and task number + * @brief Get a pointer to the head of the sorted description matrix for a given task/class combination * * @param task The task number * @param cls The class number - * @return pointer to the start of a given class and task for feature 0 + * @return Pointer to the start of a given class and task for all features */ inline double* access_sorted_d_matrix(int task, int cls) { @@ -107,7 +108,7 @@ namespace prop_sorted_d_mat * @param feat_ind feature index * @param task The task number * @param cls The class number - * @return pointer to the start of the selected feature for a given class and task + * @return pointer to the start of the selected feature for a given feature, class, and task */ inline double* access_sorted_d_matrix(int feat_ind, int task, int cls) { diff --git a/src/descriptor_identifier/Model/Model.cpp b/src/descriptor_identifier/Model/Model.cpp index 946470fef15510922509246485e74ca6b9c52d93..e3ef4be28b2562c0b00b0136f07090e14526d842 100644 --- a/src/descriptor_identifier/Model/Model.cpp +++ b/src/descriptor_identifier/Model/Model.cpp @@ -21,7 +21,7 @@ Model::Model( const std::vector<int> leave_out_inds ) : _n_samp_train(feats[0]->n_samp()), - _n_samp_test(feats[0]->n_test_samp()), + _n_samp_test(feats[0]->n_samp_test()), _n_dim(feats.size()), _feats(feats), _leave_out_inds(leave_out_inds), diff --git a/src/descriptor_identifier/Model/Model.hpp b/src/descriptor_identifier/Model/Model.hpp index afdc32917f6bef63122da177069e70fd702ab1e3..2a4f1790227467e338a6dae859de85c661197497 100644 --- a/src/descriptor_identifier/Model/Model.hpp +++ b/src/descriptor_identifier/Model/Model.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file descriptor_identifier/Model/Model.hpp - * @brief Object to store the models generated form SISSO + * @brief Object to store the models generated form SISSO * * Creates a Model generated from SISSO and the corresponding output file. * It also has functionality to read in an output file to regenerate the model. @@ -45,14 +45,14 @@ class Model protected: int _n_samp_train; //!< The number of samples per feature int _n_samp_test; //!< The number of test samples per feature - int _n_dim; //!< Dimension of the model + int _n_dim; //!< The number of dimensions of the model std::vector<model_node_ptr> _feats; //!< List of features in the model std::vector<std::vector<double>> _coefs; //!< Coefficients for the features std::vector<int> _leave_out_inds; //!< The indexes used as the test set - std::shared_ptr<LossFunction> _loss; - std::string _prop_label; //!< label for the model + std::shared_ptr<LossFunction> _loss; //!< The LossFunction used to evaluate the model + std::string _prop_label; //!< The property label for the model Unit _prop_unit; //!< The Unit for the property int _task_eval; //!< Which set of coefficients to use for evaluating the model for a new data set @@ -111,15 +111,14 @@ public: Model& operator= (Model&& o) = default; /** - * @brief Copy the error into a new array + * @brief Copy the training error into a different vector * - * @param res pointer to the beginning of the vector to store the residual + * @param res Pointer to the head of the new vector to store the residual */ virtual void copy_error(double* res) const = 0; /** - * @brief Read an output file and extract all relevant information - * @details Takes in an output file and extracts all data needed to recreate the model + * @brief Read an output file and extract all relevant information from it * * @param train_filename Name of the training output file * @param test_filename Name of the test output file @@ -129,10 +128,10 @@ public: /** * @brief Create the LossFunction for the Model when constructed from a file * - * @param prop_train Vector storing all data to train the SISSO models with - * @param prop_test Vector storing all data to test the SISSO models with - * @param task_sizes_train Number of training samples per task - * @param task_sizes_test Number of testing samples per task + * @param prop_train The property vector for all of the training samples + * @param prop_test The property vector for all of the test samples + * @param task_sizes_train The number of training samples per task + * @param task_sizes_test The number of test samples per task */ virtual void make_loss( std::vector<double>& prop_train, @@ -142,7 +141,7 @@ public: ) = 0; /** - * @brief Based off of the model line in a model file determine if the intercept is fixed + * @brief Based off of the model line in a model file determine if the bias term is 0.0 * * @param model_line the model line from the file * @return True if the intercept should be fixed @@ -244,13 +243,13 @@ public: // DocString: model_n_samp_train /** - * @brief Total number of samples being trained on + * @brief The number of samples in the training data per feature */ inline int n_samp_train() const {return _n_samp_train;} // DocString: model_n_samp_test /** - * @brief Total number of samples being tested + * @brief The number of samples in the test data per feature */ inline int n_samp_test() const {return _n_samp_test;} @@ -295,7 +294,7 @@ public: // DocString: model_fix_intercept /** - * @brief Access whether the intercept is fixed at 0 or not + * @brief True if the bias term is 0.0 */ inline bool fix_intercept() const {return _fix_intercept;} @@ -311,10 +310,15 @@ public: */ virtual std::string toString() const = 0; + /** + * @brief Convert the model to a latexified string + */ + virtual std::string toLatexString() const = 0; + /** * @brief Get the matlab expression for this model - * @return The matlab exprssion for the model + * @return The matlab expression for the model */ virtual std::string matlab_expr() const = 0; @@ -327,52 +331,47 @@ public: void write_matlab_fxn(std::string fxn_filename); /** - * @brief The training data property to be learned - * @return _prop_train as a numpy ndarray + * @brief The property vector for all of the training samples */ virtual inline std::vector<double> prop_train() const {return _loss->prop_train();} /** - * @brief The test values for the property - * @return _prop_test as a numpy ndarray + * @brief The property vector for all of the test samples */ virtual inline std::vector<double> prop_test() const {return _loss->prop_test();} /** - * @brief The training data property to be learned - * @return _prop_train as a numpy ndarray + * @brief The estimated property vector for all of the training samples */ virtual inline std::vector<double> prop_train_est() const {return _loss->prop_train_est();} /** - * @brief The test values for the property - * @return _prop_test as a numpy ndarray + * @brief The estimated property vector for all of the test samples */ virtual inline std::vector<double> prop_test_est() const {return _loss->prop_test_est();} /** - * @brief Access the size of the training set for each task + * @brief The number of training samples per task */ inline std::vector<int> task_sizes_train() const {return _loss->task_sizes_train();} /** - * @brief Access the size of the training set for each task + * @brief The number of test samples per task */ inline std::vector<int> task_sizes_test() const {return _loss->task_sizes_test();} /** - * @brief The training error - * @return _train_error as a numpy ndarray + * @brief The error vector for the training data as a numpy array */ virtual inline std::vector<double> train_error() const {return _loss->error_train();} /** - * @brief The test error - * @return _test_error as a numpy ndarray + * @brief The error vector for the test data as a numpy array */ virtual inline std::vector<double> test_error() const {return _loss->error_test();} #ifdef PY_BINDINGS + // DocString: model_coefs /** * @brief The coefficient array for the model (n_task, n_dim + bias term) diff --git a/src/descriptor_identifier/Model/ModelClassifier.hpp b/src/descriptor_identifier/Model/ModelClassifier.hpp index 78aa6fe13b2939b215c18aa966ae983f75306883..6459c29a465636651665e2629f0619f6e7f7c8c9 100644 --- a/src/descriptor_identifier/Model/ModelClassifier.hpp +++ b/src/descriptor_identifier/Model/ModelClassifier.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file descriptor_identifier/ModelClassifier/ModelClassifier.hpp - * @brief Object to store the models generated form SISSO + * @brief Object to store the models generated form SISSO * * Creates a ModelClassifier generated from SISSO and the corresponding output file. * It also has functionality to read in an output file to regenerate the model. @@ -37,7 +37,7 @@ */ class ModelClassifier : public Model { - int _n_class; //!< The number of classes + int _n_class; //!< The number of classes in the model int _train_n_convex_overlap; //!< Number of data points in regions where the convex hulls overlap in the training set int _test_n_convex_overlap; //!< Number of data points in regions where the convex hulls overlap for the test data set @@ -45,6 +45,7 @@ class ModelClassifier : public Model int _train_n_svm_misclassified; //!< The number of points misclassified by SVM (training set) int _test_n_svm_misclassified; //!< The number of points misclassified by SVM (test set) public: + /** * @brief Construct a ModelClassifier using a loss function and a set of features * @@ -66,7 +67,7 @@ public: /** * @brief Construct a ModelClassifier from a training output file * - * @param train_file (str) Previously generated model file + * @param train_file (str) Previously generated model output file for the training data */ ModelClassifier(const std::string train_file); @@ -74,8 +75,8 @@ public: /** * @brief Construct a ModelClassifier from a training and testing output file * - * @param train_file (str) Previously generated training model output file - * @param test_file (str) Previously generated testing model output file + * @param train_file (str) Previously generated model output file for the training data + * @param test_file (str) Previously generated model output file for the test data */ ModelClassifier(const std::string train_file, const std::string test_file); @@ -110,10 +111,10 @@ public: /** * @brief Create the LossFunctionConvexHull for the Model when constructed from a file * - * @param prop_train Vector storing all data to train the SISSO models with - * @param prop_test Vector storing all data to test the SISSO models with - * @param task_sizes_train Number of training samples per task - * @param task_sizes_test Number of testing samples per task + * @param prop_train The property vector for all of the training samples + * @param prop_test The property vector for all of the test samples + * @param task_sizes_train The number of training samples per task + * @param task_sizes_test The number of test samples per task */ void make_loss( std::vector<double>& prop_train, @@ -123,7 +124,7 @@ public: ); /** - * @brief Based off of the model line in a model file determine if the intercept is fixed + * @brief Based off of the model line in a model file determine if the bias term is 0.0 * * @param model_line the model line from the file * @return True if the intercept should be fixed @@ -198,9 +199,9 @@ public: std::string coefs_header() const; /** - * @brief Copy the error into a new array + * @brief Copy the training error into a different vector * - * @param res pointer to the beginning of the vector to store the residual + * @param res Pointer to the head of the new vector to store the residual */ inline void copy_error(double* res) const {std::copy_n(_loss->error_train().data(), _n_samp_train, res);} diff --git a/src/descriptor_identifier/Model/ModelLogRegressor.hpp b/src/descriptor_identifier/Model/ModelLogRegressor.hpp index b94332a9283b274288e1f789eb5797a8fb87988b..b57965afe654e6723174e4d5b6b9c12f8156b52c 100644 --- a/src/descriptor_identifier/Model/ModelLogRegressor.hpp +++ b/src/descriptor_identifier/Model/ModelLogRegressor.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file descriptor_identifier/ModelLogRegressor/ModelLogRegressor.hpp - * @brief Object to store the models generated form SISSO + * @brief Object to store the models generated form SISSO * * Creates a ModelLogRegressor generated from SISSO and the corresponding output file. * It also has functionality to read in an output file to regenerate the model. @@ -64,19 +64,17 @@ public: // DocString: model_log_reg_init_train /** * @brief Construct a ModelLogRegressor from a training output file - * @details Reads in all of the data from the output file and recreates the model object * - * @param train_file (str) Previously generated model file + * @param train_file (str) Previously generated model output file for the training data */ ModelLogRegressor(std::string train_file); // DocString: model_log_reg_init_test_train /** * @brief Construct a ModelLogRegressor from a training and testing output file - * @details Reads in all of the data from the output files and recreates the model object * - * @param train_file (str) Previously generated training model output file - * @param test_file (str) Previously generated testing model output file + * @param train_file (str) Previously generated model output file for the training data + * @param test_file (str) Previously generated model output file for the test data */ ModelLogRegressor(std::string train_file, std::string test_file); @@ -108,15 +106,13 @@ public: */ ModelLogRegressor& operator= (ModelLogRegressor&& o) = default; - - /** * @brief Create the LossFunctionLogPearsonRMSE for the Model when constructed from a file * - * @param prop_train Vector storing all data to train the SISSO models with - * @param prop_test Vector storing all data to test the SISSO models with - * @param task_sizes_train Number of training samples per task - * @param task_sizes_test Number of testing samples per task + * @param prop_train The property vector for all of the training samples + * @param prop_test The property vector for all of the test samples + * @param task_sizes_train The number of training samples per task + * @param task_sizes_test The number of test samples per task */ void make_loss( std::vector<double>& prop_train, @@ -126,7 +122,7 @@ public: ); /** - * @brief Based off of the model line in a model file determine if the intercept is fixed + * @brief Based off of the model line in a model file determine if the bias term is 0.0 * * @param model_line the model line from the file * @return True if the intercept should be fixed @@ -171,14 +167,14 @@ public: /** * @brief Get the matlab expression for this model - * @return The matlab exprssion for the model + * @return The matlab expression for the model */ std::string matlab_expr() const; /** - * @brief Copy the error into a new array + * @brief Copy the training error into a different vector * - * @param res pointer to the beginning of the vector to store the residual + * @param res Pointer to the head of the new vector to store the residual */ inline void copy_error(double* res) const {std::copy_n(_loss->error_train().data(), _n_samp_train, res);} diff --git a/src/descriptor_identifier/Model/ModelRegressor.hpp b/src/descriptor_identifier/Model/ModelRegressor.hpp index 2c90c4619da366d5cc51f28773d22a19e213b908..93713be12e2210201ff4e8b4c282e20ad2360ebc 100644 --- a/src/descriptor_identifier/Model/ModelRegressor.hpp +++ b/src/descriptor_identifier/Model/ModelRegressor.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file descriptor_identifier/ModelRegressor/ModelRegressor.hpp - * @brief Object to store the models generated form SISSO + * @brief Object to store the models generated form SISSO * * Creates a ModelRegressor generated from SISSO and the corresponding output file. * It also has functionality to read in an output file to regenerate the model. @@ -63,19 +63,17 @@ public: // DocString: model_reg_init_train /** * @brief Construct a ModelRegressor from a training output file - * @details Reads in all of the data from the output file and recreates the model object * - * @param train_file (str) Previously generated model file + * @param train_file (str) Previously generated model output file for the training data */ ModelRegressor(const std::string train_file); // DocString: model_reg_init_test_train /** * @brief Construct a ModelRegressor from a training and testing output file - * @details Reads in all of the data from the output files and recreates the model object * - * @param train_file (str) Previously generated training model output file - * @param test_file (str) Previously generated testing model output file + * @param train_file (str) Previously generated model output file for the training data + * @param test_file (str) Previously generated model output file for the test data */ ModelRegressor(const std::string train_file, const std::string test_file); @@ -96,10 +94,10 @@ public: /** * @brief Create the LossFunctionPearsonRMSE for the Model when constructed from a file * - * @param prop_train Vector storing all data to train the SISSO models with - * @param prop_test Vector storing all data to test the SISSO models with - * @param task_sizes_train Number of training samples per task - * @param task_sizes_test Number of testing samples per task + * @param prop_train The property vector for all of the training samples + * @param prop_test The property vector for all of the test samples + * @param task_sizes_train The number of training samples per task + * @param task_sizes_test The number of test samples per task */ virtual void make_loss( std::vector<double>& prop_train, @@ -139,7 +137,7 @@ public: ModelRegressor& operator= (ModelRegressor&& o) = default; /** - * @brief Based off of the model line in a model file determine if the intercept is fixed + * @brief Based off of the model line in a model file determine if the bias term is 0.0 * * @param model_line the model line from the file * @return True if the intercept should be fixed @@ -184,7 +182,7 @@ public: /** * @brief Get the matlab expression for this model - * @return The matlab exprssion for the model + * @return The matlab expression for the model */ virtual std::string matlab_expr() const; @@ -201,9 +199,9 @@ public: std::string coefs_header() const; /** - * @brief Copy the error into a new array + * @brief Copy the training error into a different vector * - * @param res pointer to the beginning of the vector to store the residual + * @param res Pointer to the head of the new vector to store the residual */ virtual inline void copy_error(double* res) const { diff --git a/src/descriptor_identifier/SISSO_DI/SISSOClassifier.cpp b/src/descriptor_identifier/SISSO_DI/SISSOClassifier.cpp index d68959c376916727de078ba8ffab5915e177d9df..437e27ca8829ea11d75c34732dddc79b654b57c2 100644 --- a/src/descriptor_identifier/SISSO_DI/SISSOClassifier.cpp +++ b/src/descriptor_identifier/SISSO_DI/SISSOClassifier.cpp @@ -124,7 +124,7 @@ void SISSOClassifier::transfer_d_mat_to_sorted() const } } -void SISSOClassifier::l0_norm(const int n_dim) +void SISSOClassifier::l0_regularization(const int n_dim) { const int n_get_models = std::max(_n_residual, _n_models_store); std::vector<double> coefs(n_dim + 1, 0.0); @@ -317,7 +317,7 @@ void SISSOClassifier::fit() } start = omp_get_wtime(); - l0_norm(dd); + l0_regularization(dd); _mpi_comm->barrier(); duration = omp_get_wtime() - start; diff --git a/src/descriptor_identifier/SISSO_DI/SISSOClassifier.hpp b/src/descriptor_identifier/SISSO_DI/SISSOClassifier.hpp index 2d505b0babcf5f98400cb1e438b7523e3f21e6fe..0ba5dc5dc0d3795b431a48274c642e97090e7368 100644 --- a/src/descriptor_identifier/SISSO_DI/SISSOClassifier.hpp +++ b/src/descriptor_identifier/SISSO_DI/SISSOClassifier.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file descriptor_identifier/SISSOClassifier.hpp - * @brief Perform SISSO on a previously generated Feature Space + * @brief Perform SISSO on a previously generated Feature Space * * Takes in a feature space and performs SISSO on it while storing the selected features in _models * @@ -51,21 +51,20 @@ protected: int _n_class; //!< The number of classes in the calculation public: - /** /** * @brief Create a SISSOClassifier object * - * @param feat_space The FeatureSpace object that will be associated with this classifier (Defines SIS) - * @param prop_label The label used to identify the property column in the DataFrame + * @param feat_space Feature Space for the problem + * @param prop_label The label for the property * @param prop_unit The unit of the property - * @param prop The property vector for all of the training samples - * @param prpo_test The property vector for all of the test samples - * @param task_sizes_train The number of training samples per task - * @param task_sizes_test The number of test samples per task - * @param leave_out_inds List of indexes from the initial data file in the test set - * @param n_dim The highest possible dimension for the linear model - * @param n_residual The number of residuals each iteration of SIS acts on - * @param n_models_store The number of models to store in output files + * @param prop The value of the property to evaluate the loss function against for the training set + * @param prpo_test The value of the property to evaluate the loss function against for the test set + * @param task_sizes_train Number of training samples per task + * @param task_sizes_test Number of testing samples per task + * @param leave_out_inds List of indexes from the initial data file in the test set + * @param n_dim The maximum number of features allowed in the linear model + * @param n_residual Number of residuals to pass to the next SIS operation + * @param n_models_store The number of models to output to files */ SISSOClassifier( const std::shared_ptr<FeatureSpace> feat_space, @@ -96,32 +95,31 @@ public: /** * @brief Gets the max error index for the classification problem - * @details [long description] * * @param n_models number of models to be stored * @param n_convex_overlap number of points in the overlapping convex hull regions (in all models) * @param svm_score the number of points misclassified by SVM (in all models) * @param svm_margin The margin of the SVM model (in all models) * @param scores the pointer to the scores array - * @return Get the index with the maximum error + * @return The index with the maximum error */ int get_max_error_ind(const int n_models, const int* n_convex_overlap, const double* svm_score, const double* svm_margin, double* scores) const; /** - * @brief sets up _sample_inds_to_sorted_dmat_inds + * @brief Sort the property vector by class and store the mapped indexes to _sample_inds_to_sorted_dmat_inds */ void setup_d_mat_transfer(); /** - * @brief Preform the l0 normalization for a property or the residual + * @brief Preform an l0-Regularization to find the best n_dim dimensional model * - * @param n_dim the dimensionality of the model + * @param n_dim The number of features to use in the linear model */ - void l0_norm(const int n_dim); + void l0_regularization(const int n_dim); // DocString: sisso_class_fit /** - * @brief Perform the SISSO calculation to find the best model for each dimension up to n_dim dimensions equal to _n_dim + * @brief Iteratively run SISSO on the FeatureSpace an Property vector until the maximum dimenisonality is reached */ void fit(); @@ -136,17 +134,17 @@ public: /** * @brief Create a SISSOClassifier object * - * @param feat_space (FeatureSpace) The FeatureSpace object that will be associated with this classifier (Defines SIS) - * @param prop_label (str) The label used to identify the property column in the DataFrame + * @param feat_space (FeatureSpace) Feature Space for the problem + * @param prop_label (str) The label for the property * @param prop_unit (Unit) The unit of the property - * @param prop (np.ndarray) The property vector for all of the training samples - * @param prpo_test (np.ndarray) The property vector for all of the test samples - * @param task_sizes_train (list) The number of training samples per task - * @param task_sizes_test (list) The number of test samples per task - * @param leave_out_inds (list) List of indexes from the initial data file in the test set - * @param n_dim (int) The highest possible dimension for the linear model - * @param n_residual (int) The number of residuals each iteration of SIS acts on - * @param n_models_store (int) The number of models to store in output files + * @param prop (np.ndarray) The value of the property to evaluate the loss function against for the training set + * @param prpo_test (np.ndarray) The value of the property to evaluate the loss function against for the test set + * @param task_sizes_train (list) Number of training samples per task + * @param task_sizes_test (list) Number of testing samples per task + * @param leave_out_inds (list) List of indexes from the initial data file in the test set + * @param n_dim (int) The maximum number of features allowed in the linear model + * @param n_residual (int) Number of residuals to pass to the next SIS operation + * @param n_models_store (int) The number of models to output to files */ SISSOClassifier( std::shared_ptr<FeatureSpace> feat_space, @@ -166,17 +164,17 @@ public: /** * @brief Create a SISSOClassifier object * - * @param feat_space (FeatureSpace) The FeatureSpace object that will be associated with this classifier (Defines SIS) - * @param prop_label (str) The label used to identify the property column in the DataFrame + * @param feat_space (FeatureSpace) Feature Space for the problem + * @param prop_label (str) The label for the property * @param prop_unit (Unit) The unit of the property - * @param prop (list) The property vector for all of the training samples - * @param prpo_test (list) The property vector for all of the test samples - * @param task_sizes_train (list) The number of training samples per task - * @param task_sizes_test (list) The number of test samples per task - * @param leave_out_inds (list) List of indexes from the initial data file in the test set - * @param n_dim (int) The highest possible dimension for the linear model - * @param n_residual (int) The number of residuals each iteration of SIS acts on - * @param n_models_store (int) The number of models to store in output files + * @param prop (list) The value of the property to evaluate the loss function against for the training set + * @param prpo_test (list) The value of the property to evaluate the loss function against for the test set + * @param task_sizes_train (list) Number of training samples per task + * @param task_sizes_test (list) Number of testing samples per task + * @param leave_out_inds (list) List of indexes from the initial data file in the test set + * @param n_dim (int) The maximum number of features allowed in the linear model + * @param n_residual (int) Number of residuals to pass to the next SIS operation + * @param n_models_store (int) The number of models to output to files */ SISSOClassifier( std::shared_ptr<FeatureSpace> feat_space, diff --git a/src/descriptor_identifier/SISSO_DI/SISSOLogRegressor.cpp b/src/descriptor_identifier/SISSO_DI/SISSOLogRegressor.cpp index 2373961ae95f3835b1c6b9568181c22e74a044b1..d46b45b615e4e27695674f8b14331c621b38607d 100644 --- a/src/descriptor_identifier/SISSO_DI/SISSOLogRegressor.cpp +++ b/src/descriptor_identifier/SISSO_DI/SISSOLogRegressor.cpp @@ -87,7 +87,7 @@ void SISSOLogRegressor::add_models(const std::vector<std::vector<int>> indexes) _loss->reset_projection_prop(min_nodes); } -void SISSOLogRegressor::l0_norm(const int n_dim) +void SISSOLogRegressor::l0_regularization(const int n_dim) { int n_get_models = std::max(_n_residual, _n_models_store); diff --git a/src/descriptor_identifier/SISSO_DI/SISSOLogRegressor.hpp b/src/descriptor_identifier/SISSO_DI/SISSOLogRegressor.hpp index 01133fb4b15a0f9333c0e7d00555afb3bc191758..448aae513c4afaf973aac82f14cd76c522dc3b20 100644 --- a/src/descriptor_identifier/SISSO_DI/SISSOLogRegressor.hpp +++ b/src/descriptor_identifier/SISSO_DI/SISSOLogRegressor.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file descriptor_identifier/SISSOLogRegressor.hpp - * @brief Perform SISSO on a previously generated Feature Space + * @brief Perform SISSO on a previously generated Feature Space * * Takes in a feature space and performs SISSO on it while storing the selected features in _models * @@ -44,18 +44,18 @@ public: /** * @brief Create a SISSOLogRegressor object * - * @param feat_space The FeatureSpace object that will be associated with this classifier (Defines SIS) - * @param prop_label The label used to identify the property column in the DataFrame + * @param feat_space Feature Space for the problem + * @param prop_label The label for the property * @param prop_unit The unit of the property - * @param prop The property vector for all of the training samples - * @param prpo_test The property vector for all of the test samples - * @param task_sizes_train The number of training samples per task - * @param task_sizes_test The number of test samples per task - * @param leave_out_inds List of indexes from the initial data file in the test set - * @param n_dim The highest possible dimension for the linear model - * @param n_residual The number of residuals each iteration of SIS acts on - * @param n_models_store The number of models to store in output files - * @param fix_intrecept If true fix bias term to 0 + * @param prop The value of the property to evaluate the loss function against for the training set + * @param prpo_test The value of the property to evaluate the loss function against for the test set + * @param task_sizes_train Number of training samples per task + * @param task_sizes_test Number of testing samples per task + * @param leave_out_inds List of indexes from the initial data file in the test set + * @param n_dim The maximum number of features allowed in the linear model + * @param n_residual Number of residuals to pass to the next SIS operation + * @param n_models_store The number of models to output to files + * @param fix_intrecept If true the bias term is fixed at 0 */ SISSOLogRegressor( const std::shared_ptr<FeatureSpace> feat_space, @@ -73,25 +73,23 @@ public: ); /** - * @brief Adds a model to the model list + * @brief Create a Model for a given set of features and store them in _models * - * @param indexes Vector storing all of the indexes of features in _phi_selected to use for the model + * @param indexes Vector storing all of the indexes of features in _feat_space->phi_selected() to use for the model */ void add_models(const std::vector<std::vector<int>> indexes); /** * @brief Output the models to files and copy the residuals - * - * @param residual vector where all of the residuals are stored */ void output_models(); /** - * @brief Preform the l0 normalization for a property or the residual + * @brief Preform an l0-Regularization to find the best n_dim dimensional model * - * @param n_dim the dimensionality of the model + * @param n_dim The number of features to use in the linear model */ - void l0_norm(const int n_dim); + void l0_regularization(const int n_dim); /** * @brief The selected models (n_dim, n_models_store) @@ -104,18 +102,18 @@ public: /** * @brief Create a SISSOLogRegressor object * - * @param feat_space (FeatureSpace) The FeatureSpace object that will be associated with this classifier (Defines SIS) - * @param prop_label (str) The label used to identify the property column in the DataFrame + * @param feat_space (FeatureSpace) Feature Space for the problem + * @param prop_label (str) The label for the property * @param prop_unit (Unit) The unit of the property - * @param prop (np.ndarray) The property vector for all of the training samples - * @param prpo_test (np.ndarray) The property vector for all of the test samples - * @param task_sizes_train (list) The number of training samples per task - * @param task_sizes_test (list) The number of test samples per task - * @param leave_out_inds (list) List of indexes from the initial data file in the test set - * @param n_dim (int) The highest possible dimension for the linear model - * @param n_residual (int) The number of residuals each iteration of SIS acts on - * @param n_models_store (int) The number of models to store in output files - * @param fix_intrecept (bool) If true fix bias term to 0 + * @param prop (np.ndarray) The value of the property to evaluate the loss function against for the training set + * @param prpo_test (np.ndarray) The value of the property to evaluate the loss function against for the test set + * @param task_sizes_train (list) Number of training samples per task + * @param task_sizes_test (list) Number of testing samples per task + * @param leave_out_inds (list) List of indexes from the initial data file in the test set + * @param n_dim (int) The maximum number of features allowed in the linear model + * @param n_residual (int) Number of residuals to pass to the next SIS operation + * @param n_models_store (int) The number of models to output to files + * @param fix_intrecept (bool) If true the bias term is fixed at 0 */ SISSOLogRegressor( std::shared_ptr<FeatureSpace> feat_space, @@ -136,18 +134,18 @@ public: /** * @brief Create a SISSOLogRegressor object * - * @param feat_space (FeatureSpace) The FeatureSpace object that will be associated with this classifier (Defines SIS) - * @param prop_label (str) The label used to identify the property column in the DataFrame + * @param feat_space (FeatureSpace) Feature Space for the problem + * @param prop_label (str) The label for the property * @param prop_unit (Unit) The unit of the property - * @param prop (list) The property vector for all of the training samples - * @param prpo_test (list) The property vector for all of the test samples - * @param task_sizes_train (list) The number of training samples per task - * @param task_sizes_test (list) The number of test samples per task - * @param leave_out_inds (list) List of indexes from the initial data file in the test set - * @param n_dim (int) The highest possible dimension for the linear model - * @param n_residual (int) The number of residuals each iteration of SIS acts on - * @param n_models_store (int) The number of models to store in output files - * @param fix_intrecept (bool) If true fix bias term to 0 + * @param prop (list) The value of the property to evaluate the loss function against for the training set + * @param prpo_test (list) The value of the property to evaluate the loss function against for the test set + * @param task_sizes_train (list) Number of training samples per task + * @param task_sizes_test (list) Number of testing samples per task + * @param leave_out_inds (list) List of indexes from the initial data file in the test set + * @param n_dim (int) The maximum number of features allowed in the linear model + * @param n_residual (int) Number of residuals to pass to the next SIS operation + * @param n_models_store (int) The number of models to output to files + * @param fix_intrecept (bool) If true the bias term is fixed at 0 */ SISSOLogRegressor( std::shared_ptr<FeatureSpace> feat_space, diff --git a/src/descriptor_identifier/SISSO_DI/SISSORegressor.cpp b/src/descriptor_identifier/SISSO_DI/SISSORegressor.cpp index dac7160641725122fdaf180b20a5cfff4414bd35..bde3be0701dd1e0cec6658afea6293830bf4bd58 100644 --- a/src/descriptor_identifier/SISSO_DI/SISSORegressor.cpp +++ b/src/descriptor_identifier/SISSO_DI/SISSORegressor.cpp @@ -87,7 +87,7 @@ void SISSORegressor::output_models() } } -void SISSORegressor::l0_norm(const int n_dim) +void SISSORegressor::l0_regularization(const int n_dim) { int n_get_models = std::max(_n_residual, _n_models_store); std::vector<double> coefs(n_dim + 1, 0.0); @@ -209,7 +209,7 @@ void SISSORegressor::fit() } start = omp_get_wtime(); - l0_norm(dd); + l0_regularization(dd); _mpi_comm->barrier(); duration = omp_get_wtime() - start; diff --git a/src/descriptor_identifier/SISSO_DI/SISSORegressor.hpp b/src/descriptor_identifier/SISSO_DI/SISSORegressor.hpp index 4b7f1f59065c1c989bc7a20950db73cca545e078..4a6ce8ee594948db08466a4d2271ec4db336cba0 100644 --- a/src/descriptor_identifier/SISSO_DI/SISSORegressor.hpp +++ b/src/descriptor_identifier/SISSO_DI/SISSORegressor.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file descriptor_identifier/SISSORegressor.hpp - * @brief Perform SISSO on a previously generated Feature Space + * @brief Perform SISSO on a previously generated Feature Space * * Takes in a feature space and performs SISSO on it while storing the selected features in _models * @@ -44,18 +44,18 @@ public: /** * @brief Create a SISSORegressor object * - * @param feat_space The FeatureSpace object that will be associated with this classifier (Defines SIS) - * @param prop_label The label used to identify the property column in the DataFrame + * @param feat_space Feature Space for the problem + * @param prop_label The label for the property * @param prop_unit The unit of the property - * @param prop The property vector for all of the training samples - * @param prpo_test The property vector for all of the test samples - * @param task_sizes_train The number of training samples per task - * @param task_sizes_test The number of test samples per task - * @param leave_out_inds List of indexes from the initial data file in the test set - * @param n_dim The highest possible dimension for the linear model - * @param n_residual The number of residuals each iteration of SIS acts on - * @param n_models_store The number of models to store in output files - * @param fix_intrecept If true fix bias term to 0 + * @param prop The value of the property to evaluate the loss function against for the training set + * @param prpo_test The value of the property to evaluate the loss function against for the test set + * @param task_sizes_train Number of training samples per task + * @param task_sizes_test Number of testing samples per task + * @param leave_out_inds List of indexes from the initial data file in the test set + * @param n_dim The maximum number of features allowed in the linear model + * @param n_residual Number of residuals to pass to the next SIS operation + * @param n_models_store The number of models to output to files + * @param fix_intrecept If true the bias term is fixed at 0 */ SISSORegressor( const std::shared_ptr<FeatureSpace> feat_space, @@ -73,29 +73,27 @@ public: ); /** - * @brief Adds a model to the model list + * @brief Create a Model for a given set of features and store them in _models * - * @param indexes Vector storing all of the indexes of features in _phi_selected to use for the model + * @param indexes Vector storing all of the indexes of features in _feat_space->phi_selected() to use for the model */ virtual void add_models(const std::vector<std::vector<int>> indexes); /** * @brief Output the models to files and copy the residuals - * - * @param residual vector where all of the residuals are stored */ virtual void output_models(); /** - * @brief Preform the l0 normalization for a property or the residual + * @brief Preform an l0-Regularization to find the best n_dim dimensional model * - * @param n_dim the dimensionality of the model + * @param n_dim The number of features to use in the linear model */ - virtual void l0_norm(const int n_dim); + virtual void l0_regularization(const int n_dim); // DocString: sisso_reg_fit /** - * @brief Perform the SISSO calculation to find the best model for each dimension up to n_dim dimensions equal to _n_dim + * @brief Iteratively run SISSO on the FeatureSpace an Property vector until the maximum dimenisonality is reached */ virtual void fit(); @@ -111,18 +109,18 @@ public: /** * @brief Create a SISSORegressor object * - * @param feat_space (FeatureSpace) The FeatureSpace object that will be associated with this classifier (Defines SIS) - * @param prop_label (str) The label used to identify the property column in the DataFrame + * @param feat_space (FeatureSpace) Feature Space for the problem + * @param prop_label (str) The label for the property * @param prop_unit (Unit) The unit of the property - * @param prop (np.ndarray) The property vector for all of the training samples - * @param prpo_test (np.ndarray) The property vector for all of the test samples - * @param task_sizes_train (list) The number of training samples per task - * @param task_sizes_test (list) The number of test samples per task - * @param leave_out_inds (list) List of indexes from the initial data file in the test set - * @param n_dim (int) The highest possible dimension for the linear model - * @param n_residual (int) The number of residuals each iteration of SIS acts on - * @param n_models_store (int) The number of models to store in output files - * @param fix_intrecept (bool) If true fix bias term to 0 + * @param prop (np.ndarray) The value of the property to evaluate the loss function against for the training set + * @param prpo_test (np.ndarray) The value of the property to evaluate the loss function against for the test set + * @param task_sizes_train (list) Number of training samples per task + * @param task_sizes_test (list) Number of testing samples per task + * @param leave_out_inds (list) List of indexes from the initial data file in the test set + * @param n_dim (int) The maximum number of features allowed in the linear model + * @param n_residual (int) Number of residuals to pass to the next SIS operation + * @param n_models_store (int) The number of models to output to files + * @param fix_intrecept (bool) If true the bias term is fixed at 0 */ SISSORegressor( std::shared_ptr<FeatureSpace> feat_space, @@ -143,18 +141,18 @@ public: /** * @brief Create a SISSORegressor object * - * @param feat_space (FeatureSpace) The FeatureSpace object that will be associated with this classifier (Defines SIS) - * @param prop_label (str) The label used to identify the property column in the DataFrame + * @param feat_space (FeatureSpace) Feature Space for the problem + * @param prop_label (str) The label for the property * @param prop_unit (Unit) The unit of the property - * @param prop (list) The property vector for all of the training samples - * @param prpo_test (list) The property vector for all of the test samples - * @param task_sizes_train (list) The number of training samples per task - * @param task_sizes_test (list) The number of test samples per task - * @param leave_out_inds (list) List of indexes from the initial data file in the test set - * @param n_dim (int) The highest possible dimension for the linear model - * @param n_residual (int) The number of residuals each iteration of SIS acts on - * @param n_models_store (int) The number of models to store in output files - * @param fix_intrecept (bool) If true fix bias term to 0 + * @param prop (list) The value of the property to evaluate the loss function against for the training set + * @param prpo_test (list) The value of the property to evaluate the loss function against for the test set + * @param task_sizes_train (list) Number of training samples per task + * @param task_sizes_test (list) Number of testing samples per task + * @param leave_out_inds (list) List of indexes from the initial data file in the test set + * @param n_dim (int) The maximum number of features allowed in the linear model + * @param n_residual (int) Number of residuals to pass to the next SIS operation + * @param n_models_store (int) The number of models to output to files + * @param fix_intrecept (bool) If true the bias term is fixed at 0 */ SISSORegressor( std::shared_ptr<FeatureSpace> feat_space, diff --git a/src/descriptor_identifier/SISSO_DI/SISSO_DI.hpp b/src/descriptor_identifier/SISSO_DI/SISSO_DI.hpp index f88c831422c302f8298941fa96d2cf551e1eb4b2..a386f3384471e59374c6dc77287c195b742aabbf 100644 --- a/src/descriptor_identifier/SISSO_DI/SISSO_DI.hpp +++ b/src/descriptor_identifier/SISSO_DI/SISSO_DI.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file descriptor_identifier/SISSO_DI/SISSO_DI.hpp - * @brief Base class used to perform SISSO on a previously generated Feature Space + * @brief Base class used to perform SISSO on a previously generated Feature Space * * Takes in a feature space and performs SISSO on it while storing the selected features in _models * @@ -42,36 +42,36 @@ protected: const std::vector<int> _task_sizes_test; //!< Number of testing samples per task const std::vector<int> _leave_out_inds; //!< List of indexes from the initial data file in the test set - const Unit _prop_unit; //!< The Unit for the property - const std::string _prop_label; //!< The label for the property + const Unit _prop_unit; //!< The Unit of the property + const std::string _prop_label; //!< The label of the property const std::shared_ptr<FeatureSpace> _feat_space; //!< Feature Space for the problem - std::shared_ptr<MPI_Interface> _mpi_comm; //!< MPI Communicator - std::shared_ptr<LossFunction> _loss; //!< The loss function for the calculation + std::shared_ptr<MPI_Interface> _mpi_comm; //!< MPI Communicator for the calculation + std::shared_ptr<LossFunction> _loss; //!< The loss function used to evaluate models const int _n_task; //!< The number of tasks - const int _n_samp; //!< the number of samples per feature - const int _n_dim; //!< Number of dimensions to calculate + const int _n_samp; //!< The number of training samples per feature + const int _n_dim; //!< The maximum number of features allowed in the linear model const int _n_residual; //!< Number of residuals to pass to the next sis model - const int _n_models_store; //!< The number of models to store in files + const int _n_models_store; //!< The number of models to output to files - const bool _fix_intercept; //!< If true fix intercept to 0 + const bool _fix_intercept; //!< If true the bias term is fixed at 0 public: /** - * @brief Constructor for the Regressor + * @brief Constructor for the Solver * - * @param feat_space The feature space to run SISSO on + * @param feat_space Feature Space for the problem * @param prop_label The label for the property * @param prop_unit The unit of the property - * @param prop Vector storing all data to train the SISSO models with - * @param prpo_test Vector storing all data to test the SISSO models with + * @param prop The value of the property to evaluate the loss function against for the training set + * @param prpo_test The value of the property to evaluate the loss function against for the test set * @param task_sizes_train Number of training samples per task * @param task_sizes_test Number of testing samples per task - * @param leave_out_inds List of indexes from the initial data file in the test set - * @param n_dim Maximum dimensionality of the generated models + * @param leave_out_inds List of indexes from the initial data file in the test set + * @param n_dim The maximum number of features allowed in the linear model * @param n_residual Number of residuals to pass to the next SIS operation - * @param n_models_store Number of features to store in files - * @param fix_intrecept If true fix intercept to 0 + * @param n_models_store The number of models to output to files + * @param fix_intrecept If true the bias term is fixed at 0 */ SISSO_DI( const std::string loss_type, @@ -90,18 +90,16 @@ public: ); /** - * @brief Perform SISSO to generate the models - * @details Iteratively perform SISSO on the Feature space and property until the model dimensionality is equal to _n_dim + * @brief Iteratively run SISSO on the FeatureSpace an Property vector until the maximum dimenisonality is reached */ virtual void fit() = 0; /** - * @brief Preform the l0 normalization for a property or the residual + * @brief Preform an l0-Regularization to find the best n_dim dimensional model * - * @param prop The property to fit - * @param n_dim the dimensionality of the model + * @param n_dim The number of features to use in the linear model */ - virtual void l0_norm(const int n_dim) = 0; + virtual void l0_regularization(const int n_dim) = 0; /** * @brief The FeatureSpace object associated with this solver @@ -131,7 +129,7 @@ public: // DocString: sisso_di_n_dim /** - * @brief The highest possible dimension for the linear model + * @brief The maximum number of features allowed in the linear model */ inline int n_dim() const {return _n_dim;} @@ -143,7 +141,7 @@ public: // DocString: sisso_di_n_modles_store /** - * @brief The number of models to store in output files + * @brief The number of models to output to files */ inline int n_models_store() const {return _n_models_store;} @@ -152,20 +150,20 @@ public: // DocString: sisso_di_init_arr /** - * @brief Constructor for the Regressor that takes in python objects (cpp definition in <python/descriptor_identifier/SISSO_DI.cpp) + * @brief Constructor for the solver that takes in python objects * - * @param feat_space The feature space to run SISSO on + * @param feat_space Feature Space for the problem * @param prop_label The label for the property * @param prop_unit The unit of the property - * @param prop Vector storing all data to train the SISSO models with - * @param prpo_test Vector storing all data to test the SISSO models with + * @param prop The value of the property to evaluate the loss function against for the training set + * @param prpo_test The value of the property to evaluate the loss function against for the test set * @param task_sizes_train Number of training samples per task * @param task_sizes_test Number of testing samples per task - * @param leave_out_inds List of indexes from the initial data file in the test set - * @param n_dim Maximum dimensionality of the generated models + * @param leave_out_inds List of indexes from the initial data file in the test set + * @param n_dim The maximum number of features allowed in the linear model * @param n_residual Number of residuals to pass to the next SIS operation - * @param n_models_store Number of features to store in files - * @param fix_intrecept If true fix intercept to 0 + * @param n_models_store The number of models to output to files + * @param fix_intrecept If true the bias term is fixed at 0 */ SISSO_DI( std::string loss_type, @@ -185,20 +183,20 @@ public: // DocString: sisso_di_init_list /** - * @brief Constructor for the Regressor that takes in python objects (cpp definition in <python/descriptor_identifier/SISSO_DI.cpp) + * @brief Constructor for the solver that takes in python objects * - * @param feat_space The feature space to run SISSO on + * @param feat_space Feature Space for the problem * @param prop_label The label for the property * @param prop_unit The unit of the property - * @param prop Vector storing all data to train the SISSO models with - * @param prpo_test Vector storing all data to test the SISSO models with + * @param prop The value of the property to evaluate the loss function against for the training set + * @param prpo_test The value of the property to evaluate the loss function against for the test set * @param task_sizes_train Number of training samples per task * @param task_sizes_test Number of testing samples per task - * @param leave_out_inds List of indexes from the initial data file in the test set - * @param n_dim Maximum dimensionality of the generated models + * @param leave_out_inds List of indexes from the initial data file in the test set + * @param n_dim The maximum number of features allowed in the linear model * @param n_residual Number of residuals to pass to the next SIS operation - * @param n_models_store Number of features to store in files - * @param fix_intrecept If true fix intercept to 0 + * @param n_models_store The number of models to output to files + * @param fix_intrecept If true the bias term is fixed at 0 */ SISSO_DI( std::string loss_type, diff --git a/src/feature_creation/feature_space/FeatureSpace.cpp b/src/feature_creation/feature_space/FeatureSpace.cpp index 71aa00ae4416d7be7457bab49ea40e5ad5c4a261..535faf9a8e7627c8d0589aa70f2c39b46d5e4e31 100644 --- a/src/feature_creation/feature_space/FeatureSpace.cpp +++ b/src/feature_creation/feature_space/FeatureSpace.cpp @@ -59,9 +59,9 @@ FeatureSpace::FeatureSpace( std::vector<double> prop, std::vector<int> task_sizes, std::string project_type, - int max_phi, + int max_rung, int n_sis_select, - int max_store_rung, + int n_rung_store, int n_rung_generate, double cross_corr_max, double min_abs_feat_val, @@ -72,13 +72,13 @@ FeatureSpace::FeatureSpace( _phi(phi_0), _phi_0(phi_0), _end_no_params(1, phi_0.size()), - _start_gen_reparam(1, 0), + _start_rung_reparam(1, 0), _allowed_param_ops(allowed_param_ops), _allowed_ops(allowed_ops), _prop(prop), _scores(phi_0.size(), 0.0), _task_sizes(task_sizes), - _start_gen(1, 0), + _start_rung(1, 0), _feature_space_file("feature_space/selected_features.txt"), _feature_space_summary_file("feature_space/SIS_summary.txt"), _project_type(project_type), @@ -86,11 +86,11 @@ FeatureSpace::FeatureSpace( _cross_cor_max(cross_corr_max), _l_bound(min_abs_feat_val), _u_bound(max_abs_feat_val), - _max_phi(max_phi), + _max_rung(max_rung), _n_sis_select(n_sis_select), _n_samp(phi_0[0]->n_samp()), _n_feat(phi_0.size()), - _n_rung_store(max_store_rung), + _n_rung_store(n_rung_store), _n_rung_generate(n_rung_generate), _max_param_depth(max_param_depth), _reparam_residual(reparam_residual) @@ -105,9 +105,9 @@ FeatureSpace::FeatureSpace( std::vector<double> prop, std::vector<int> task_sizes, std::string project_type, - int max_phi, + int max_rung, int n_sis_select, - int max_store_rung, + int n_rung_store, int n_rung_generate, double cross_corr_max, double min_abs_feat_val, @@ -119,7 +119,7 @@ FeatureSpace::FeatureSpace( _prop(prop), _scores(phi_0.size(), 0.0), _task_sizes(task_sizes), - _start_gen(1, 0), + _start_rung(1, 0), _feature_space_file("feature_space/selected_features.txt"), _feature_space_summary_file("feature_space/SIS_summary.txt"), _project_type(project_type), @@ -127,11 +127,11 @@ FeatureSpace::FeatureSpace( _cross_cor_max(cross_corr_max), _l_bound(min_abs_feat_val), _u_bound(max_abs_feat_val), - _max_phi(max_phi), + _max_rung(max_rung), _n_sis_select(n_sis_select), _n_samp(phi_0[0]->n_samp()), _n_feat(phi_0.size()), - _n_rung_store(max_store_rung), + _n_rung_store(n_rung_store), _n_rung_generate(n_rung_generate), _max_param_depth(0), _reparam_residual(false) @@ -145,9 +145,9 @@ void FeatureSpace::initialize_fs() #ifdef PARAMETERIZE if(_max_param_depth == -1) { - _max_param_depth = _max_phi; + _max_param_depth = _max_rung; } - if((_max_param_depth < 0) || (_max_param_depth > _max_phi)) + if((_max_param_depth < 0) || (_max_param_depth > _max_rung)) { throw std::logic_error("Invalid parameter depth."); } @@ -177,20 +177,20 @@ void FeatureSpace::initialize_fs() if(_n_rung_store == -1) { - _n_rung_store = _max_phi - 1; + _n_rung_store = _max_rung - 1; } if(_n_rung_generate > 1) { throw std::logic_error("A maximum of one rung can be generated on the fly."); } - else if(_max_phi - _n_rung_generate < _n_rung_store) + else if(_max_rung - _n_rung_generate < _n_rung_store) { throw std::logic_error("Requesting to store more rungs than what can be pre-generated."); } node_value_arrs::set_task_sz_train(_task_sizes); int n_max_ops = 0; - for(int rr = 0; rr < _max_phi - _n_rung_store; ++rr) + for(int rr = 0; rr < _max_rung - _n_rung_store; ++rr) { n_max_ops += std::pow(2, rr); } @@ -324,7 +324,7 @@ void FeatureSpace::generate_reparam_feats( { for(int rr = 0; rr <= cur_rung; ++rr) { - for(auto feat_2 = _phi.begin() + _start_gen[rr]; (feat_2 != feat) || (feat_2 != _phi.begin() + _end_no_params[rr]); ++feat_2) + for(auto feat_2 = _phi.begin() + _start_rung[rr]; (feat_2 != feat) || (feat_2 != _phi.begin() + _end_no_params[rr]); ++feat_2) { op(feat_set, *feat, *feat_2, feat_ind, l_bound, u_bound, optimizer); } @@ -338,7 +338,7 @@ void FeatureSpace::generate_reparam_feats( { for(int rr = 0; rr <= cur_rung; ++rr) { - for(auto feat_2 = _phi.begin() + _start_gen[rr]; (feat_2 != feat) || (feat_2 != _phi.begin() + _end_no_params[rr]); ++feat_2) + for(auto feat_2 = _phi.begin() + _start_rung[rr]; (feat_2 != feat) || (feat_2 != _phi.begin() + _end_no_params[rr]); ++feat_2) { op(feat_set, *feat, *feat_2, feat_ind, l_bound, u_bound, optimizer); op(feat_set, *feat_2, *feat, feat_ind, l_bound, u_bound, optimizer); @@ -359,10 +359,10 @@ void FeatureSpace::generate_reparam_feature_set(const std::vector<double>& prop) double l_bound = 1e-50; std::vector<int> inds; - for(int nn = 1; nn <= _max_phi - _n_rung_generate; ++nn) + for(int nn = 1; nn <= _max_rung - _n_rung_generate; ++nn) { node_value_arrs::clear_temp_reg(); - if(nn == _max_phi) + if(nn == _max_rung) { u_bound = _u_bound; l_bound = _l_bound; @@ -377,15 +377,15 @@ void FeatureSpace::generate_reparam_feature_set(const std::vector<double>& prop) #pragma omp parallel firstprivate(feat_ind, l_bound, u_bound) { std::vector<node_ptr> next_phi_private; - std::shared_ptr<NLOptimizer> optimizer_param = nlopt_wrapper::get_optimizer(_project_type, _task_sizes, _prop, _max_phi, _max_param_depth); - std::shared_ptr<NLOptimizer> optimizer_reparam = nlopt_wrapper::get_optimizer(_project_type, _task_sizes, prop, _max_phi, _max_param_depth); + std::shared_ptr<NLOptimizer> optimizer_param = nlopt_wrapper::get_optimizer(_project_type, _task_sizes, _prop, _max_rung, _max_param_depth); + std::shared_ptr<NLOptimizer> optimizer_reparam = nlopt_wrapper::get_optimizer(_project_type, _task_sizes, prop, _max_rung, _max_param_depth); #ifdef OMP45 #pragma omp for schedule(monotonic: dynamic) #else #pragma omp for schedule(dynamic) #endif - for(auto feat_1 = _phi_reparam.begin() + _start_gen_reparam.back() + _mpi_comm->rank(); feat_1 < _phi_reparam.end(); feat_1 += _mpi_comm->size()) + for(auto feat_1 = _phi_reparam.begin() + _start_rung_reparam.back() + _mpi_comm->rank(); feat_1 < _phi_reparam.end(); feat_1 += _mpi_comm->size()) { generate_non_param_feats(feat_1, next_phi_private, _phi_reparam.begin(), feat_ind, l_bound, u_bound); generate_param_feats(feat_1, next_phi_private, _phi_reparam.begin(), feat_ind, optimizer_param, l_bound, u_bound); @@ -396,7 +396,7 @@ void FeatureSpace::generate_reparam_feature_set(const std::vector<double>& prop) #else #pragma omp for schedule(dynamic) #endif - for(auto feat_1 = _phi.begin() + _start_gen[nn-1] + _mpi_comm->rank(); feat_1 < _phi.begin() + _end_no_params[nn-1]; feat_1 += _mpi_comm->size()) + for(auto feat_1 = _phi.begin() + _start_rung[nn-1] + _mpi_comm->rank(); feat_1 < _phi.begin() + _end_no_params[nn-1]; feat_1 += _mpi_comm->size()) { generate_reparam_feats(feat_1, next_phi_private, feat_ind, optimizer_reparam, l_bound, u_bound); } @@ -404,9 +404,9 @@ void FeatureSpace::generate_reparam_feature_set(const std::vector<double>& prop) #pragma omp critical next_phi.insert(next_phi.end(), next_phi_private.begin(), next_phi_private.end()); } - _start_gen_reparam.push_back(_phi_reparam.size()); + _start_rung_reparam.push_back(_phi_reparam.size()); node_value_arrs::clear_temp_reg(); - if(nn < _max_phi) + if(nn < _max_rung) { int new_phi_size; int phi_size_start = _phi_reparam.size(); @@ -423,14 +423,14 @@ void FeatureSpace::generate_reparam_feature_set(const std::vector<double>& prop) // Sort the features to ensure consistent feature spaces for all MPI/OpenMP configurations std::sort( - _phi_reparam.begin() + _start_gen_reparam.back(), + _phi_reparam.begin() + _start_rung_reparam.back(), _phi_reparam.end(), [feat_ind](node_ptr n1, node_ptr n2){return n1->sort_score(feat_ind) < n2->sort_score(feat_ind);} ); // Reindex sorted features std::for_each( - _phi_reparam.begin() + _start_gen_reparam.back(), + _phi_reparam.begin() + _start_rung_reparam.back(), _phi_reparam.end(), [&feat_ind](node_ptr n){n->reindex(feat_ind); ++feat_ind;} ); @@ -460,13 +460,13 @@ void FeatureSpace::generate_reparam_feature_set(const std::vector<double>& prop) } node_value_arrs::clear_temp_reg(); - if(nn < _max_phi) + if(nn < _max_rung) { // Remove identical features std::vector<double> scores(_phi_reparam.size()); _mpi_comm->barrier(); project_funcs::project_r(_prop.data(), scores.data(), _phi_reparam, _task_sizes, 1); - scores.erase(scores.begin(), scores.begin() + _start_gen_reparam.back()); + scores.erase(scores.begin(), scores.begin() + _start_rung_reparam.back()); inds = util_funcs::argsort<double>(scores); std::vector<int> del_inds; @@ -476,7 +476,7 @@ void FeatureSpace::generate_reparam_feature_set(const std::vector<double>& prop) for(int sc = 0; sc < scores.size() - 1; ++sc) { #ifdef PARAMETERIZE - if(_phi_reparam[inds[sc] + _start_gen_reparam.back()]->n_params() > 0) + if(_phi_reparam[inds[sc] + _start_rung_reparam.back()]->n_params() > 0) { continue; } @@ -486,8 +486,8 @@ void FeatureSpace::generate_reparam_feature_set(const std::vector<double>& prop) { double base_val = std::abs( util_funcs::r( - _phi_reparam[_start_gen_reparam.back() + inds[sc]]->value_ptr(), - _phi_reparam[_start_gen_reparam.back() + inds[sc]]->value_ptr(), + _phi_reparam[_start_rung_reparam.back() + inds[sc]]->value_ptr(), + _phi_reparam[_start_rung_reparam.back() + inds[sc]]->value_ptr(), _n_samp ) ); @@ -496,15 +496,15 @@ void FeatureSpace::generate_reparam_feature_set(const std::vector<double>& prop) double comp = std::abs( base_val - std::abs( util_funcs::r( - _phi_reparam[_start_gen_reparam.back() + inds[sc]]->value_ptr(), - _phi_reparam[_start_gen_reparam.back() + inds[sc2]]->value_ptr(0, true), + _phi_reparam[_start_rung_reparam.back() + inds[sc]]->value_ptr(), + _phi_reparam[_start_rung_reparam.back() + inds[sc2]]->value_ptr(0, true), _n_samp ) ) ); if(comp < 1e-10) { - del_inds.push_back(-1 * (inds[sc] + _start_gen_reparam.back())); + del_inds.push_back(-1 * (inds[sc] + _start_rung_reparam.back())); break; } } @@ -513,23 +513,23 @@ void FeatureSpace::generate_reparam_feature_set(const std::vector<double>& prop) { double base_val = std::abs( util_funcs::r( - _phi_reparam[_start_gen_reparam.back() + inds[sc]]->value_ptr(), - _phi_reparam[_start_gen_reparam.back() + inds[sc]]->value_ptr(), + _phi_reparam[_start_rung_reparam.back() + inds[sc]]->value_ptr(), + _phi_reparam[_start_rung_reparam.back() + inds[sc]]->value_ptr(), _n_samp ) ); double comp = std::abs( base_val - std::abs( util_funcs::r( - _phi_reparam[_start_gen_reparam.back() + inds[sc]]->value_ptr(), - _phi_reparam[_start_gen_reparam.back() + inds[sc + 1]]->value_ptr(0, true), + _phi_reparam[_start_rung_reparam.back() + inds[sc]]->value_ptr(), + _phi_reparam[_start_rung_reparam.back() + inds[sc + 1]]->value_ptr(0, true), _n_samp ) ) ); if(comp < 1e-10) { - del_inds.push_back(-1 * (inds[sc] + _start_gen.back())); + del_inds.push_back(-1 * (inds[sc] + _start_rung.back())); } } } @@ -541,7 +541,7 @@ void FeatureSpace::generate_reparam_feature_set(const std::vector<double>& prop) } // Reindex - for(int ff = _start_gen_reparam.back(); ff < _phi_reparam.size(); ++ff) + for(int ff = _start_rung_reparam.back(); ff < _phi_reparam.size(); ++ff) { _phi_reparam[ff]->reindex(ff + _n_feat); } @@ -592,10 +592,10 @@ void FeatureSpace::generate_feature_space() double l_bound = 1e-50; std::vector<int> inds; - for(int nn = 1; nn <= _max_phi - _n_rung_generate; ++nn) + for(int nn = 1; nn <= _max_rung - _n_rung_generate; ++nn) { node_value_arrs::clear_temp_reg(); - if(nn == _max_phi) + if(nn == _max_rung) { u_bound = _u_bound; l_bound = _l_bound; @@ -611,14 +611,14 @@ void FeatureSpace::generate_feature_space() #pragma omp parallel firstprivate(feat_ind, l_bound, u_bound) { std::vector<node_ptr> next_phi_private; - std::shared_ptr<NLOptimizer> optimizer = nlopt_wrapper::get_optimizer(_project_type, _task_sizes, _prop, _max_phi, _max_param_depth); + std::shared_ptr<NLOptimizer> optimizer = nlopt_wrapper::get_optimizer(_project_type, _task_sizes, _prop, _max_rung, _max_param_depth); #ifdef OMP45 #pragma omp for schedule(monotonic: dynamic) #else #pragma omp for schedule(dynamic) #endif - for(auto feat_1 = _phi.begin() + _start_gen.back() + _mpi_comm->rank(); feat_1 < _phi.end(); feat_1 += _mpi_comm->size()) + for(auto feat_1 = _phi.begin() + _start_rung.back() + _mpi_comm->rank(); feat_1 < _phi.end(); feat_1 += _mpi_comm->size()) { generate_non_param_feats(feat_1, next_phi_private, _phi.begin(), feat_ind, l_bound, u_bound); generate_param_feats(feat_1, next_phi_private, _phi.begin(), feat_ind, optimizer, l_bound, u_bound); @@ -636,7 +636,7 @@ void FeatureSpace::generate_feature_space() #else #pragma omp for schedule(dynamic) #endif - for(auto feat_1 = _phi.begin() + _start_gen.back() + _mpi_comm->rank(); feat_1 < _phi.end(); feat_1 += _mpi_comm->size()) + for(auto feat_1 = _phi.begin() + _start_rung.back() + _mpi_comm->rank(); feat_1 < _phi.end(); feat_1 += _mpi_comm->size()) { generate_non_param_feats(feat_1, next_phi_private, _phi.begin(), feat_ind, l_bound, u_bound); } @@ -645,9 +645,9 @@ void FeatureSpace::generate_feature_space() next_phi.insert(next_phi.end(), next_phi_private.begin(), next_phi_private.end()); } #endif - _start_gen.push_back(_phi.size()); + _start_rung.push_back(_phi.size()); node_value_arrs::clear_temp_reg(); - if((nn < _max_phi) || (nn <= _n_rung_store) || (_mpi_comm->size() == 1)) + if((nn < _max_rung) || (nn <= _n_rung_store) || (_mpi_comm->size() == 1)) { int new_phi_size; int phi_size_start = _phi.size(); @@ -664,14 +664,14 @@ void FeatureSpace::generate_feature_space() // Sort the features to ensure consistent feature spaces for all MPI/OpenMP configurations std::sort( - _phi.begin() + _start_gen.back(), + _phi.begin() + _start_rung.back(), _phi.end(), [feat_ind](node_ptr n1, node_ptr n2){return n1->sort_score(feat_ind) < n2->sort_score(feat_ind);} ); // Reindex sorted features std::for_each( - _phi.begin() + _start_gen.back(), + _phi.begin() + _start_rung.back(), _phi.end(), [&feat_ind](node_ptr n){n->reindex(feat_ind); ++feat_ind;} ); @@ -701,13 +701,13 @@ void FeatureSpace::generate_feature_space() } node_value_arrs::clear_temp_reg(); - if(nn < _max_phi) + if(nn < _max_rung) { // Remove identical features _scores.resize(_phi.size()); _mpi_comm->barrier(); project_funcs::project_r(_prop.data(), _scores.data(), _phi, _task_sizes, 1); - _scores.erase(_scores.begin(), _scores.begin() + _start_gen[_start_gen.size() - 1]); + _scores.erase(_scores.begin(), _scores.begin() + _start_rung[_start_rung.size() - 1]); inds = util_funcs::argsort<double>(_scores); std::vector<int> del_inds; @@ -717,7 +717,7 @@ void FeatureSpace::generate_feature_space() for(int sc = 0; sc < _scores.size() - 1; ++sc) { #ifdef PARAMETERIZE - if(_phi[inds[sc] + _start_gen.back()]->n_params() > 0) + if(_phi[inds[sc] + _start_rung.back()]->n_params() > 0) { continue; } @@ -727,8 +727,8 @@ void FeatureSpace::generate_feature_space() { double base_val = std::abs( util_funcs::r( - _phi[_start_gen.back() + inds[sc]]->value_ptr(), - _phi[_start_gen.back() + inds[sc]]->value_ptr(), + _phi[_start_rung.back() + inds[sc]]->value_ptr(), + _phi[_start_rung.back() + inds[sc]]->value_ptr(), _n_samp ) ); @@ -737,15 +737,15 @@ void FeatureSpace::generate_feature_space() double comp = std::abs( base_val - std::abs( util_funcs::r( - _phi[_start_gen.back() + inds[sc]]->value_ptr(), - _phi[_start_gen.back() + inds[sc2]]->value_ptr(0, true), + _phi[_start_rung.back() + inds[sc]]->value_ptr(), + _phi[_start_rung.back() + inds[sc2]]->value_ptr(0, true), _n_samp ) ) ); if(comp < 1e-10) { - del_inds.push_back(-1 * (inds[sc] + _start_gen.back())); + del_inds.push_back(-1 * (inds[sc] + _start_rung.back())); break; } } @@ -754,23 +754,23 @@ void FeatureSpace::generate_feature_space() { double base_val = std::abs( util_funcs::r( - _phi[_start_gen.back() + inds[sc]]->value_ptr(), - _phi[_start_gen.back() + inds[sc]]->value_ptr(), + _phi[_start_rung.back() + inds[sc]]->value_ptr(), + _phi[_start_rung.back() + inds[sc]]->value_ptr(), _n_samp ) ); double comp = std::abs( base_val - std::abs( util_funcs::r( - _phi[_start_gen.back() + inds[sc]]->value_ptr(), - _phi[_start_gen.back() + inds[sc + 1]]->value_ptr(0, true), + _phi[_start_rung.back() + inds[sc]]->value_ptr(), + _phi[_start_rung.back() + inds[sc + 1]]->value_ptr(0, true), _n_samp ) ) ); if(comp < 1e-10) { - del_inds.push_back(-1 * (inds[sc] + _start_gen.back())); + del_inds.push_back(-1 * (inds[sc] + _start_rung.back())); } } } @@ -782,13 +782,13 @@ void FeatureSpace::generate_feature_space() } // Reindex - for(int ff = _start_gen.back(); ff < _phi.size(); ++ff) + for(int ff = _start_rung.back(); ff < _phi.size(); ++ff) { _phi[ff]->reindex(ff); } } node_value_arrs::clear_temp_reg(); - for(int ff = _start_gen.back(); ff < _phi.size(); ++ff) + for(int ff = _start_rung.back(); ff < _phi.size(); ++ff) { _phi[ff]->reset_feats(_phi); } @@ -797,7 +797,7 @@ void FeatureSpace::generate_feature_space() { node_value_arrs::resize_values_arr(nn, _phi.size()); - for(int ff = _start_gen.back(); ff < _phi.size(); ++ff) + for(int ff = _start_rung.back(); ff < _phi.size(); ++ff) { _phi[ff]->set_value(); _phi[ff]->set_test_value(); @@ -941,7 +941,7 @@ void FeatureSpace::generate_feature_space() } #pragma omp parallel for - for(int ff = _start_gen.back(); ff < _phi.size(); ++ff) + for(int ff = _start_rung.back(); ff < _phi.size(); ++ff) { _phi[ff]->reindex(ff + n_feat_below_rank, ff); _phi[ff]->set_value(); @@ -951,23 +951,23 @@ void FeatureSpace::generate_feature_space() #ifdef PARAMETERIZE // Reorder features based on the number of parameters they have (none goes first) - std::vector<int> feat_n_params(_phi.size() - _start_gen.back()); + std::vector<int> feat_n_params(_phi.size() - _start_rung.back()); std::transform( - _phi.begin() + _start_gen.back(), + _phi.begin() + _start_rung.back(), _phi.end(), feat_n_params.begin(), [](node_ptr feat){return feat->n_params();} ); inds = util_funcs::argsort<int>(feat_n_params); next_phi.resize(feat_n_params.size()); - std::copy_n(_phi.begin() + _start_gen.back(), feat_n_params.size(), next_phi.begin()); + std::copy_n(_phi.begin() + _start_rung.back(), feat_n_params.size(), next_phi.begin()); std::transform( inds.begin(), inds.end(), - _phi.begin() + _start_gen.back(), + _phi.begin() + _start_rung.back(), [&next_phi](int ind){return next_phi[ind];} ); - for(int ff = _start_gen.back(); ff < _phi.size(); ++ff) + for(int ff = _start_rung.back(); ff < _phi.size(); ++ff) { _phi[ff]->reindex(ff); _phi[ff]->set_value(); @@ -982,8 +982,8 @@ void FeatureSpace::generate_feature_space() _n_feat = _phi.size(); } -// void FeatureSpace::project_generated(const double* prop, const int size, std::vector<node_ptr>& phi_sel, std::vector<double>& scores_sel) -void FeatureSpace::project_generated(std::shared_ptr<LossFunction> loss, std::vector<node_ptr>& phi_sel, std::vector<double>& scores_sel) +// void FeatureSpace::generate_and_project(const double* prop, const int size, std::vector<node_ptr>& phi_sel, std::vector<double>& scores_sel) +void FeatureSpace::generate_and_project(std::shared_ptr<LossFunction> loss, std::vector<node_ptr>& phi_sel, std::vector<double>& scores_sel) { std::vector<double> scores_sel_all(node_value_arrs::N_SELECTED); if(node_value_arrs::N_SELECTED > _n_sis_select) @@ -1004,12 +1004,12 @@ void FeatureSpace::project_generated(std::shared_ptr<LossFunction> loss, std::ve int index_base = _phi.size() + _n_sis_select * (omp_get_thread_num() + _mpi_comm->size()); #ifdef PARAMETERIZE - std::shared_ptr<NLOptimizer> optimizer = nlopt_wrapper::get_optimizer(_project_type, _task_sizes, _prop, _max_phi, _max_param_depth); + std::shared_ptr<NLOptimizer> optimizer = nlopt_wrapper::get_optimizer(_project_type, _task_sizes, _prop, _max_rung, _max_param_depth); std::shared_ptr<NLOptimizer> reparam_optimizer; if(_reparam_residual) { std::vector<double> prop_vec(loss_copy->prop_project()); - reparam_optimizer = nlopt_wrapper::get_optimizer(_project_type, _task_sizes, prop_vec, _max_phi, _max_param_depth); + reparam_optimizer = nlopt_wrapper::get_optimizer(_project_type, _task_sizes, prop_vec, _max_rung, _max_param_depth); } else { @@ -1022,7 +1022,7 @@ void FeatureSpace::project_generated(std::shared_ptr<LossFunction> loss, std::ve #else #pragma omp for schedule(dynamic) #endif - for(auto feat = _phi.begin() + _start_gen.back() + _mpi_comm->rank(); feat < _phi.end(); feat += _mpi_comm->size()) + for(auto feat = _phi.begin() + _start_rung.back() + _mpi_comm->rank(); feat < _phi.end(); feat += _mpi_comm->size()) { unsigned long int feat_ind = _phi.size() + _n_sis_select * (omp_get_num_threads() + _mpi_comm->size()); @@ -1118,7 +1118,7 @@ void FeatureSpace::project_generated(std::shared_ptr<LossFunction> loss, std::ve { scores_sel[worst_score_ind] = scores_sel_private[sc]; phi_sel[worst_score_ind] = phi_sel_private[sc]; - if(phi_sel[worst_score_ind]->rung() == _max_phi) + if(phi_sel[worst_score_ind]->rung() == _max_rung) { phi_sel[worst_score_ind]->reindex(index_base + worst_score_ind); } @@ -1127,7 +1127,7 @@ void FeatureSpace::project_generated(std::shared_ptr<LossFunction> loss, std::ve { scores_sel.push_back(scores_sel_private[sc]); phi_sel.push_back(phi_sel_private[sc]); - if(phi_sel.back()->rung() == _max_phi) + if(phi_sel.back()->rung() == _max_rung) { phi_sel.back()->reindex(index_base + phi_sel.size()); } @@ -1162,7 +1162,7 @@ void FeatureSpace::sis(std::shared_ptr<LossFunction> loss) double start_time = omp_get_wtime(); _phi.resize(_n_feat); _phi_reparam.resize(0); - _start_gen_reparam.resize(0); + _start_rung_reparam.resize(0); generate_reparam_feature_set(loss->prop_project()); _phi.insert(_phi.end(), _phi_reparam.begin(), _phi_reparam.end()); _scores.resize(_phi.size()); @@ -1255,14 +1255,14 @@ void FeatureSpace::sis(std::shared_ptr<LossFunction> loss) { #ifdef PARAMETERIZE _phi.resize(_n_feat); - _phi.insert(_phi.end(), _phi_reparam.begin() + _start_gen_reparam.back(), _phi_reparam.end()); + _phi.insert(_phi.end(), _phi_reparam.begin() + _start_rung_reparam.back(), _phi_reparam.end()); _scores.resize(_phi.size()); #endif start_time = omp_get_wtime(); phi_sel.resize(cur_feat_local); scores_sel.resize(cur_feat_local); - project_generated(loss, phi_sel, scores_sel); + generate_and_project(loss, phi_sel, scores_sel); _mpi_comm->barrier(); if(_mpi_comm->rank() == 0) diff --git a/src/feature_creation/feature_space/FeatureSpace.hpp b/src/feature_creation/feature_space/FeatureSpace.hpp index 0d587fa324f2b86e610d44de59216645dd31992f..6048fa0d8631569be4d7878757b499d59d577980 100644 --- a/src/feature_creation/feature_space/FeatureSpace.hpp +++ b/src/feature_creation/feature_space/FeatureSpace.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/feature_space/FeatureSpace.hpp - * @brief Create a feature space from an initial set of features and algebraic operators + * @brief Create a feature space from an initial set of features and algebraic operators * * Use an initial set of features and combine them to generate more complicated algebraical features. SIS is also performed here * @@ -48,78 +48,77 @@ */ class FeatureSpace { - std::vector<node_ptr> _phi_selected; //!< selected features - std::vector<node_ptr> _phi; //!< all features - const std::vector<node_ptr> _phi_0; //!< initial feature space + std::vector<node_ptr> _phi_selected; //!< A vector containing all of the selected features + std::vector<node_ptr> _phi; //!< A vector containing all features generated (Not including those created on the Fly during SIS) + const std::vector<node_ptr> _phi_0; //!< A vector containing all of the Primary features #ifdef PARAMETERIZE - std::vector<node_ptr> _phi_reparam; //!< The list of nodes used for reparameterization - std::vector<int> _end_no_params; //!< The list of indexes of each rung where parameterized nodes start - std::vector<int> _start_gen_reparam; //!< The list of indexes of each rung where parameterized nodes start - - 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 - 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<node_ptr> _phi_reparam; //!< A vector containing the features created when reparameterizating using the residuals + std::vector<int> _end_no_params; //!< A vector containing the indexes of each rung where parameterized nodes start + std::vector<int> _start_rung_reparam; //!< A vector containing the indexes of each rung where parameterized nodes start + + std::vector<un_param_op_node_gen> _un_param_operators; //!< Vector containing all parameterized unary operators with free parameters + std::vector<bin_param_op_node_gen> _com_bin_param_operators; //!< Vector containing all parameterized commutable binary operators with free parameters + std::vector<bin_param_op_node_gen> _bin_param_operators; //!< Vector containing all parameterized binary operators with free parameters + std::vector<std::string> _allowed_param_ops; //!< Vector containing all allowed operators strings for operators with free parameters #endif - 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 - std::vector<bin_op_node_gen> _bin_operators; //!< list of all binary operators + std::vector<std::string> _allowed_ops; //!< Vector containing all allowed operators strings + std::vector<un_op_node_gen> _un_operators; //!< Vector containing all unary operators + std::vector<bin_op_node_gen> _com_bin_operators; //!< Vector containing all commutable binary operators + std::vector<bin_op_node_gen> _bin_operators; //!< Vector containing all binary operators - std::vector<double> _prop; //!< The property to fit - std::vector<double> _scores; //!< projection scores for each feature + std::vector<double> _prop; //!< The value of the property vector for each training sample + std::vector<double> _scores; //!< The projection scores for each feature - const std::vector<int> _task_sizes; //!< The number of elements in each task (training data) - std::vector<int> _start_gen; //!< list of the indexes where each generation starts in _phi - const std::string _project_type; //!< The type of projection that should be done during SIS - const std::string _feature_space_file; //!< File to store information about the selected features - const std::string _feature_space_summary_file; //!< File to store information about the selected features + const std::vector<int> _task_sizes; //!< Number of training samples per task + std::vector<int> _start_rung; //!< Vector containing the indexes where each rung starts in _phi + const std::string _project_type; //!< The type of LossFunction to use when projecting the features onto a property + const std::string _feature_space_file; //!< File to output the computer readable representation of the selected features to + const std::string _feature_space_summary_file; //!< File to output the human readable representation of the selected features to - std::function<bool(const double*, const int, const double, const std::vector<double>&, const double, const int, const int)> _is_valid; //!< Function used to calculate the scores for SIS - std::function<bool(const double*, const int, const double, const std::vector<node_ptr>&, const std::vector<double>&, const double)> _is_valid_feat_list; //!< Function used to calculate the scores for SIS without changing omp environment + std::function<bool(const double*, const int, const double, const std::vector<double>&, const double, const int, const int)> _is_valid; //!< Function used to determine of a feature is too correlated to previously selected features + std::function<bool(const double*, const int, const double, const std::vector<node_ptr>&, const std::vector<double>&, const double)> _is_valid_feat_list; //!< Function used to determine of a feature is too correlated to previously selected features within a given list - std::shared_ptr<MPI_Interface> _mpi_comm; //!< MPI communicator + std::shared_ptr<MPI_Interface> _mpi_comm; //!< the MPI communicator for the calculation const double _cross_cor_max; //!< Maximum cross-correlation used for selecting features - const double _l_bound; //!< lower bound for absolute value of the features - const double _u_bound; //!< upper bound for absolute value of the features + const double _l_bound; //!< The lower bound for the maximum absolute value of the features + const double _u_bound; //!< The upper bound for the maximum absolute value of the features - int _n_rung_store; //!< Total rungs stored - int _n_feat; //!< Total number of features - int _max_phi; //!< Maximum rung for the feature creation + int _n_rung_store; //!< The number of rungs to calculate and store the value of the features for all samples + int _n_feat; //!< Total number of features in the feature space + int _max_rung; //!< Maximum rung for the feature creation - const int _n_sis_select; //!< Number of features to select for each dimensions - const int _n_samp; //!< Number of samples (training data) - const int _n_rung_generate; //!< Total number of rungs to generate on the fly + const int _n_sis_select; //!< Number of features to select during each SIS iteration + const int _n_samp; //!< Number of samples in the training set + const int _n_rung_generate; //!< Either 0 or 1, and is the number of rungs to generate on the fly during SIS - int _max_param_depth; //!< Max depth to parameterize a feature (default=_max_rung) - const bool _reparam_residual; //!< If True then reparameterize using the residuals of each model + int _max_param_depth; //!< The maximum depth in the binary expression tree to set non-linear optimization + const bool _reparam_residual; //!< If True then reparameterize features using the residuals of each model public: #ifdef PARAMETERIZE /** - * @brief Constructor for the feature space - * @details constructs the feature space from an initial set of features and a list of allowed operators + * @brief FeatureSpace constructor given a set of primary features and operators * * @param mpi_comm MPI communicator for the calculations - * @param phi_0 The initial set of features to combine - * @param allowed_ops list of allowed operators - * @param allowed_param_ops dictionary of the parameterizable operators and their associated free parameters - * @param prop The property to be learned (training data) + * @param phi_0 The set of primary features + * @param allowed_ops The list of allowed operators + * @param allowed_param_ops The list of allowed operators to be used with non-linear optimization + * @param prop List containing the property vector (training data only) * @param task_sizes The number of samples per task - * @param project_type The projection operator to use - * @param max_phi highest rung value for the calculation - * @param n_sis_select number of features to select during each SIS step - * @param max_store_rung number of rungs to calculate and store the value of the features for all samples - * @param n_rung_generate number of rungs to generate on the fly during SIS (this must be 1 or 0 right now, possible to be higher with recursive algorithm) - * @param cross_corr_max Maximum cross-correlation used for selecting features - * @param min_abs_feat_val minimum absolute feature value - * @param max_abs_feat_val maximum absolute feature value - * @param max_param_depth the maximum paremterization depths for features - * @param reparam_residual If True then reparameterize using the residuals of each model + * @param project_type The type of loss function/projection operator to use + * @param max_rung The maximum rung of the feature (Height of the binary expression tree -1) + * @param n_sis_select The number of features to select during each SIS step + * @param n_rung_store The number of rungs whose feature's data is always stored in memory + * @param n_rung_generate Either 0 or 1, and is the number of rungs to generate on the fly during SIS + * @param cross_corr_max The maximum allowed cross-correlation value between selected features + * @param min_abs_feat_val The minimum allowed absolute feature value for a feature + * @param max_abs_feat_val The maximum allowed absolute feature value for a feature + * @param max_param_depth The maximum depth in the binary expression tree to set non-linear optimization + * @param reparam_residual If True then reparameterize features using the residuals of each model */ FeatureSpace( std::shared_ptr<MPI_Interface> mpi_comm, @@ -129,9 +128,9 @@ public: std::vector<double> prop, std::vector<int> task_sizes, std::string project_type="regression", - int max_phi=1, + int max_rung=1, int n_sis_select=1, - int max_store_rung=-1, + int n_rung_store=-1, int n_rung_generate=0, double cross_corr_max=1.0, double min_abs_feat_val=1e-50, @@ -141,22 +140,21 @@ public: ); #else /** - * @brief Constructor for the feature space - * @details constructs the feature space from an initial set of features and a list of allowed operators + * @brief FeatureSpace constructor given a set of primary features and operators * * @param mpi_comm MPI communicator for the calculations - * @param phi_0 The initial set of features to combine - * @param allowed_ops list of allowed operators - * @param prop The property to be learned (training data) + * @param phi_0 The set of primary features + * @param allowed_ops The list of allowed operators + * @param prop List containing the property vector (training data only) * @param task_sizes The number of samples per task - * @param project_type The projection operator to use - * @param max_phi highest rung value for the calculation - * @param n_sis_select number of features to select during each SIS step - * @param max_store_rung number of rungs to calculate and store the value of the features for all samples - * @param n_rung_generate number of rungs to generate on the fly during SIS (this must be 1 or 0 right now, possible to be higher with recursive algorithm) - * @param cross_corr_max Maximum cross-correlation used for selecting features - * @param min_abs_feat_val minimum absolute feature value - * @param max_abs_feat_val maximum absolute feature value + * @param project_type The type of loss function/projection operator to use + * @param max_rung The maximum rung of the feature (Height of the binary expression tree -1) + * @param n_sis_select The number of features to select during each SIS step + * @param n_rung_store The number of rungs whose feature's data is always stored in memory + * @param n_rung_generate Either 0 or 1, and is the number of rungs to generate on the fly during SIS + * @param cross_corr_max The maximum allowed cross-correlation value between selected features + * @param min_abs_feat_val The minimum allowed absolute feature value for a feature + * @param max_abs_feat_val The maximum allowed absolute feature value for a feature */ FeatureSpace( std::shared_ptr<MPI_Interface> mpi_comm, @@ -165,9 +163,9 @@ public: std::vector<double> prop, std::vector<int> task_sizes, std::string project_type="regression", - int max_phi=1, + int max_rung=1, int n_sis_select=1, - int max_store_rung=-1, + int n_rung_store=-1, int n_rung_generate=0, double cross_corr_max=1.0, double min_abs_feat_val=1e-50, @@ -175,42 +173,42 @@ public: ); #endif /** - * @brief Initialize the feature set given a property vector + * @brief Initialize members of the FeatureSpace using _prop */ void initialize_fs(); /** - * @brief Uses _allowed_ops to set the operator lists + * @brief Populate the operator lists using _allowed_ops and _allowed_param_ops */ void set_op_lists(); /** - * @brief Initializes the output files for SIS + * @brief Create SIS output files and write their headers */ void initialize_fs_output_files() const; + /** - * @brief Generate the full feature set from the allowed operators and initial feature set - * @details populates phi with all features from an initial set and the allowed operators + * @brief Populate _phi using _phi_0 and the allowed operators up to (_max_rung - _n_rung_generate)^th rung */ void generate_feature_space(); /** - * @brief The selected feature space + * @brief A vector containing all of the selected features */ inline std::vector<node_ptr> phi_selected() const {return _phi_selected;}; /** - * @brief The full feature space + * @brief A vector containing all features generated (Not including those created on the Fly during SIS) */ inline std::vector<node_ptr> phi() const {return _phi;}; /** - * @brief The initial feature space + * @brief A vector containing all of the Primary features */ inline std::vector<node_ptr> phi0() const {return _phi_0;}; /** - * @brief The vector of projection scores for SIS + * @brief The projection scores for each feature in _phi */ inline std::vector<double> scores() const {return _scores;} @@ -220,55 +218,61 @@ public: inline std::shared_ptr<MPI_Interface> mpi_comm() const {return _mpi_comm;} /** - * @brief The vector storing the number of samples in each task + * @brief Number of training samples per task */ inline std::vector<int> task_sizes() const {return _task_sizes;} // DocString: feat_space_feature_space_file /** - * @brief The feature space filename + * @brief Filename of the file to output the computer readable representation of the selected features to */ inline std::string feature_space_file() const {return _feature_space_file;} + // DocString: feat_space_feature_space_file + /** + * @brief Filename of the file to output the human readable representation of the selected features to + */ + inline std::string feature_space_summary_file() const {return _feature_space_summary_file;} + // DocString: feat_space_l_bound /** - * @brief The minimum absolute value of the feature + * @brief The mlower bound for the maximum absolute value of the features */ inline double l_bound() const {return _l_bound;} // DocString: feat_space_u_bound /** - * @brief The maximum absolute value of the feature + * @brief The upper bound for the maximum absolute value of the features */ inline double u_bound() const {return _u_bound;} - // DocString: feat_space_max_phi + // DocString: feat_space_max_rung /** - * @brief The maximum rung of the feature space + * @brief The maximum rung for the feature creation */ - inline int max_phi() const {return _max_phi;} + inline int max_rung() const {return _max_rung;} // DocString: feat_space_n_sis_select /** - * @brief The number of features selected in each SIS step + * @brief The number of features to select during each SIS iteration */ inline int n_sis_select() const {return _n_sis_select;} // DocString: feat_space_n_samp /** - * @brief The number of samples per feature + * @brief The nuumber of samples in the training set */ inline int n_samp() const {return _n_samp;} // DocString: feat_space_n_feat /** - * @brief The number of features in the feature space + * @brief The total number of features in the feature space */ inline int n_feat() const {return _n_feat;} // DocString: feat_space_n_rung_store /** - * @brief The number of rungs whose feature's data is always stored in memory + * @brief The number of rungs to calculate and store the value of the features for all samples */ inline int n_rung_store() const {return _n_rung_store;} @@ -280,14 +284,14 @@ public: /** * @brief Generate a new set of non-parameterized features from a single feature - * @details Take in the feature and perform all valid algebraic operations on it. + * @details Perform all valid algebraic operations on the passed feature and all features that appear before it in _phi. * * @param feat The feature to spawn new features from - * @param feat_set The feature set to pull features from for combinations + * @param feat_set The feature set to pull features from for binary operations + * @param start The point in feat_set to begin pulling features from for binary operations * @param feat_ind starting index for the next feature generated - * @param optimizer The object used to optimize the parameterized features - * @param l_bound lower bound for the absolute value of the feature - * @param u_bound upper bound for the abosulte value of the feature + * @param l_bound lower bound for the maximum absolute value of the feature + * @param u_bound upper bound for the maximum abosulte value of the feature */ void generate_non_param_feats( std::vector<node_ptr>::iterator& feat, @@ -301,14 +305,15 @@ public: #ifdef PARAMETERIZE /** * @brief Generate a new set of parameterized features from a single feature - * @details Take in the feature and perform all valid algebraic operations on it. + * @details Perform all valid algebraic operations on the passed feature and all features that appear before it in _phi. * * @param feat The feature to spawn new features from - * @param feat_set The feature set to pull features from for combinations + * @param feat_set The feature set to pull features from for binary operations + * @param start The point in feat_set to begin pulling features from for binary operations * @param feat_ind starting index for the next feature generated * @param optimizer The object used to optimize the parameterized features - * @param l_bound lower bound for the absolute value of the feature - * @param u_bound upper bound for the abosulte value of the feature + * @param l_bound lower bound for the maximum absolute value of the feature + * @param u_bound upper bound for the maximum abosulte value of the feature */ void generate_param_feats( std::vector<node_ptr>::iterator& feat, @@ -324,11 +329,11 @@ public: * @brief Generate a new set of parameterized features for the residuals * * @param feat The feature to spawn new features from - * @param feat_set The feature set to pull features from for combinations + * @param feat_set The feature set to pull features from for binary operations * @param feat_ind starting index for the next feature generated * @param optimizer The object used to optimize the parameterized features - * @param l_bound lower bound for the absolute value of the feature - * @param u_bound upper bound for the abosulte value of the feature + * @param l_bound lower bound for the maximum absolute value of the feature + * @param u_bound upper bound for the maximum abosulte value of the feature */ void generate_reparam_feats( std::vector<node_ptr>::iterator& feat, @@ -348,15 +353,13 @@ public: #endif /** - * @brief Calculate the SIS Scores for feature generated on the fly - * @details Create the next rung of features and calculate their projection scores. Only keep those that can be selected by SIS. + * @brief Generate the final rung of features on the fly and calculate their projection scores for SISat can be selected by SIS. * - * @param prop Pointer to the start of the vector storing the data to project the features onto - * @param size The size of the data to project over - * @param phi_selected The features that would be selected from the previous rungs - * @param scores_selected The projection scores of the features that would be selected from the previous rungs + * @param loss The LossFunction used to project over all of the features + * @param phi_selected The set of features that would be selected excluding the final rung + * @param scores_selected The projection scores of all features in phi_selected */ - void project_generated(std::shared_ptr<LossFunction> loss, std::vector<node_ptr>& phi_selected, std::vector<double>& scores_selected); + void generate_and_project(std::shared_ptr<LossFunction> loss, std::vector<node_ptr>& phi_selected, std::vector<double>& scores_selected); /** * @brief Perform Sure-Independence Screening over the FeatureSpace. The features are ranked using a projection operator constructed using _project_type and the Property vector @@ -403,9 +406,9 @@ public: * @param allowed_param_ops (list) The list of allowed operators to be used with non-linear optimization * @param prop (list) List containing the property vector (training data only) * @param project_type (str) The type of loss function/projection operator to use - * @param max_phi (int) The maximum rung of the feature (Height of the binary expression tree -1) + * @param max_rung (int) The maximum rung of the feature (Height of the binary expression tree -1) * @param n_sis_select (int) The number of features to select during each SIS step - * @param max_store_rung (int) The number of rungs whose feature's data is always stored in memory + * @param n_rung_store (int) The number of rungs whose feature's data is always stored in memory * @param n_rung_generate (int) Either 0 or 1, and is the number of rungs to generate on the fly during SIS * @param cross_corr_max (double) The maximum allowed cross-correlation value between selected features * @param min_abs_feat_val (double) The minimum allowed absolute feature value for a feature @@ -419,9 +422,9 @@ public: py::list allowed_param_ops, py::list prop, std::string project_type="regression", - int max_phi=1, + int max_rung=1, int n_sis_select=1, - int max_store_rung=-1, + int n_rung_store=-1, int n_rung_generate=0, double cross_corr_max=1.0, double min_abs_feat_val=1e-50, @@ -439,9 +442,9 @@ public: * @param allowed_param_ops (list) The list of allowed operators to be used with non-linear optimization * @param prop (np.ndarray) List containing the property vector (training data only) * @param project_type (str) The type of loss function/projection operator to use - * @param max_phi (int) The maximum rung of the feature (Height of the binary expression tree -1) + * @param max_rung (int) The maximum rung of the feature (Height of the binary expression tree -1) * @param n_sis_select (int) The number of features to select during each SIS step - * @param max_store_rung (int) The number of rungs whose feature's data is always stored in memory + * @param n_rung_store (int) The number of rungs whose feature's data is always stored in memory * @param n_rung_generate (int) Either 0 or 1, and is the number of rungs to generate on the fly during SIS * @param cross_corr_max (double) The maximum allowed cross-correlation value between selected features * @param min_abs_feat_val (double) The minimum allowed absolute feature value for a feature @@ -455,9 +458,9 @@ public: py::list allowed_param_ops, np::ndarray prop, std::string project_type="regression", - int max_phi=1, + int max_rung=1, int n_sis_select=1, - int max_store_rung=-1, + int n_rung_store=-1, int n_rung_generate=0, double cross_corr_max=1.0, double min_abs_feat_val=1e-50, @@ -476,9 +479,9 @@ public: * @param allowed_ops (list) The list of allowed operators * @param prop (list) List containing the property vector (training data only) * @param project_type (str) The type of loss function/projection operator to use - * @param max_phi (int) The maximum rung of the feature (Height of the binary expression tree -1) + * @param max_rung (int) The maximum rung of the feature (Height of the binary expression tree -1) * @param n_sis_select (int) The number of features to select during each SIS step - * @param max_store_rung (int) The number of rungs whose feature's data is always stored in memory + * @param n_rung_store (int) The number of rungs whose feature's data is always stored in memory * @param n_rung_generate (int) Either 0 or 1, and is the number of rungs to generate on the fly during SIS * @param cross_corr_max (double) The maximum allowed cross-correlation value between selected features * @param min_abs_feat_val (double) The minimum allowed absolute feature value for a feature @@ -489,9 +492,9 @@ public: py::list allowed_ops, py::list prop, std::string project_type="regression", - int max_phi=1, + int max_rung=1, int n_sis_select=1, - int max_store_rung=-1, + int n_rung_store=-1, int n_rung_generate=0, double cross_corr_max=1.0, double min_abs_feat_val=1e-50, @@ -506,9 +509,9 @@ public: * @param allowed_ops (list) The list of allowed operators * @param prop (np.ndarray) List containing the property vector (training data only) * @param project_type (str) The type of loss function/projection operator to use - * @param max_phi (int) The maximum rung of the feature (Height of the binary expression tree -1) + * @param max_rung (int) The maximum rung of the feature (Height of the binary expression tree -1) * @param n_sis_select (int) The number of features to select during each SIS step - * @param max_store_rung (int) The number of rungs whose feature's data is always stored in memory + * @param n_rung_store (int) The number of rungs whose feature's data is always stored in memory * @param n_rung_generate (int) Either 0 or 1, and is the number of rungs to generate on the fly during SIS * @param cross_corr_max (double) The maximum allowed cross-correlation value between selected features * @param min_abs_feat_val (double) The minimum allowed absolute feature value for a feature @@ -519,9 +522,9 @@ public: py::list allowed_ops, np::ndarray prop, std::string project_type="regression", - int max_phi=1, + int max_rung=1, int n_sis_select=1, - int max_store_rung=-1, + int n_rung_store=-1, int n_rung_generate=0, double cross_corr_max=1.0, double min_abs_feat_val=1e-50, @@ -599,21 +602,21 @@ public: // DocString: feat_space_phi_selected_py /** - * @brief A list of all of the selected features + * @brief A list containing all of the selected features */ py::list phi_selected_py(); // DocString: feat_space_phi0_py /** - * @brief A list containing all of the primary features + * @brief A list containing all features generated (Not including those created on the Fly during SIS) */ - py::list phi0_py(); + py::list phi_py(); // DocString: feat_space_phi_py /** - * @brief A list of all features in the FeatureSpace + * @brief A list containing all of the Primary features */ - py::list phi_py(); + py::list phi0_py(); // DocString: feat_space_scores_py /** @@ -633,11 +636,11 @@ public: */ inline py::list allowed_ops_py(){return python_conv_utils::to_list<std::string>(_allowed_ops);} - // DocString: feat_space_start_gen_py + // DocString: feat_space_start_rung_py /** * @brief A list containing the index of the first feature of each rung in the feature space. */ - inline py::list start_gen_py(){return python_conv_utils::to_list<int>(_start_gen);} + inline py::list start_rung_py(){return python_conv_utils::to_list<int>(_start_rung);} // DocString: feat_space_get_feature /** diff --git a/src/feature_creation/node/FeatureNode.hpp b/src/feature_creation/node/FeatureNode.hpp index c56ad79ba7aaa9749d33e895d99f94e2387e51df..f5cb3e900ca424efedc620273d57b0b4199a5a28 100644 --- a/src/feature_creation/node/FeatureNode.hpp +++ b/src/feature_creation/node/FeatureNode.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/FeatureNode.hpp - * @brief The class for describing the initial features + * @brief The class for describing the initial features * * This class represents the leaves of all of the binary expression trees. * @@ -56,8 +56,8 @@ class FeatureNode: public Node } protected: - std::vector<double> _value; //!< values for the feature - std::vector<double> _test_value; //!< test values for the feature + std::vector<double> _value; //!< The value for this feature's training data + std::vector<double> _test_value; //!< The value for this feature's test data Unit _unit; //!< Unit for the feature std::string _expr; //!< Expression of the feature @@ -71,12 +71,12 @@ public: /** * @brief Constructs a feature node * - * @param feat_ind index of the feature + * @param feat_ind The index of the feature * @param expr Expression for the feature - * @param value Value of the feature for each sample - * @param test_value Value of the feature for each test sample + * @param value The value for this feature's training data + * @param test_value The value for this feature's test data * @param unit Unit of the feature - * @param set_val if true set the value inside the VALUES_ARR object + * @param set_val If true set the value inside the VALUES_ARR object */ FeatureNode( const unsigned long int feat_ind, @@ -86,15 +86,16 @@ public: const Unit unit, const bool set_val=true ); + #ifdef PY_BINDINGS // DocString: feat_node_init_arr /** * @brief Constructs a feature node using numpy arrays (cpp definition in python/feature_creation/FeatureNode.cpp) * - * @param feat_ind (int) index of the feature + * @param feat_ind (int) The index of the feature * @param expr (str) Expression for the feature - * @param value (np.ndarray) Value of the feature for each sample - * @param test_value (np.ndarray) Value of the feature for each test sample + * @param value (np.ndarray) The value for this feature's training data + * @param test_value (np.ndarray) The value for this feature's test data * @param unit (Unit) Unit of the feature */ FeatureNode(unsigned long int feat_ind, std::string expr, np::ndarray value, np::ndarray test_value, Unit unit); @@ -103,10 +104,10 @@ public: /** * @brief Constructs a feature node using Python lists (cpp definition in python/feature_creation/FeatureNode.cpp) * - * @param feat_ind (int) index of the feature + * @param feat_ind (int) The index of the feature * @param expr (str) Expression for the feature - * @param value (list) Value of the feature for each sample - * @param test_value (list) Value of the feature for each test sample + * @param value (list) The value for this feature's training data + * @param test_value (list) The value for this feature's test data * @param unit (Unit) Unit of the feature */ FeatureNode(unsigned long int feat_ind, std::string expr, py::list value, py::list test_value, Unit unit); @@ -145,16 +146,15 @@ public: ~FeatureNode(); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ virtual inline node_ptr hard_copy()const {return std::make_shared<FeatureNode>(*this);} /** - * @brief Resets the features of a operator to ones in the feature_space - * @details Relink all feature to those in the FeatureSpace in case MPI copies break the links + * @brief Relinks all features of an OperatorNodes's _feat member to Nodes inside of phi * - * @param phi feature space vector + * @param phi A vector containing all Nodes that this Node can relink to */ void reset_feats(std::vector<node_ptr>& phi){}; @@ -171,16 +171,16 @@ public: virtual inline int n_leaves(int cur_n_leaves = 0) const {return cur_n_leaves + 1;} /** - * @brief Get the score used to sort the features + * @brief Get the score used to sort the features in the feature space (Based on the type of node and _feat_ind) * - * @param max_ind the maximum index of the input nodes - * @return the score used to sort the feature space + * @param max_ind The maximum index of the input nodes + * @return The score used to sort the feature space */ inline unsigned long long sort_score(unsigned int max_ind) const {return _feat_ind;} // DocString: feat_node_expr_const /** - * @brief Get the expression for the feature (From root node down) + * @brief A human readable equation representing the feature */ inline std::string expr()const{return _expr;} @@ -197,14 +197,12 @@ public: inline Unit unit() const {return _unit;} /** - * @brief An array containing the values of the training set samples for the feature - + * @brief A vector containing the values of the training set samples for the feature */ inline std::vector<double> value() const {return _value;} /** - * @brief An array containing the values of the test set samples for the feature - + * @brief A vector containing the values of the test set samples for the feature */ inline std::vector<double> test_value() const {return _test_value;} @@ -231,7 +229,7 @@ public: { if(!_selected) { - std::copy_n(_test_value.data(), _n_test_samp, test_value_ptr()); + std::copy_n(_test_value.data(), _n_samp_test, test_value_ptr()); } } @@ -283,13 +281,14 @@ public: // DocString: feat_node_rung /** - * @brief return the rung of the feature (Height of the binary expression tree + 1) + * @brief return the rung of the feature (Height of the binary expression tree - 1) * */ inline int rung(int cur_rung = 0) const {return cur_rung;} /** * @brief Get the primary feature decomposition of a feature + * * @return A map representing the primary feature comprising a feature */ std::map<int, int> primary_feature_decomp() const; @@ -316,8 +315,7 @@ public: } /** - * @brief Get the three character representation of the operator - * @return the three character representation of the operator + * @brief Get the term used in the postfix expression for this Node */ inline std::string get_postfix_term() const {return std::to_string(_feat_ind);} @@ -355,57 +353,56 @@ public: } /** - * @brief update the dictionary used to check if an Add/Sub node is valid + * @brief update the dictionary used to check if an Add/Sub/AbsDiff node is valid * * @param add_sub_leaves the dictionary used to check if an Add/Sub node is valid - * @param pl_mn if for an addition node: 1 if for a subtraction node: -1 + * @param pl_mn 1 for addition and -1 for subtraction * @param expected_abs_tot The expected absolute sum of all values in add_sub_leaves */ void update_add_sub_leaves(std::map<std::string, int>& add_sub_leaves, const int pl_mn, int& expected_abs_tot) const; /** - * @brief update the dictionary used to check if a mult/div node is valid + * @brief update the dictionary used to check if an Mult/Div node is valid * * @param div_mult_leaves the dictionary used to check if an Mult/Div node is valid - * @param fact Factor used to update leaves (power of the feature) + * @param fact amount to increment the element (a primary features) of the dictionary by * @param expected_abs_tot The expected absolute sum of all values in div_mult_leaves - * */ void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, const double fact, double& expected_abs_tot) const; #ifdef PARAMETERIZE /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ inline std::vector<double> parameters() const {return std::vector<double>();}; /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node * @param check_sz If true check the size of the parameters */ inline void set_parameters(const std::vector<double> params, const bool check_sz=true){}; /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ inline void set_parameters(const double* params){}; // DocString: feat_node_get_params /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to get the paremeters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ void get_parameters(std::shared_ptr<NLOptimizer> optimizer){}; /** * @brief returns the number of parameters for this feature * - * @param n_cur the current number of parameters for the feature - * @param depth the current depth of the node on the binary expression tree + * @param n_cur A recursive helper variable to count the number of parameters of the Node + * @param depth How far down a given Node is from the root OperatorNode * @return the number of parameters (_params.size()) */ inline int n_params(int n_cur=0, int depth = 1) const {return n_cur;}; @@ -414,9 +411,9 @@ public: * @brief Set the value of all test samples for the feature inside the central data storage array * * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param for_comp(bool) If true then the evaluation is used for comparing features - * @param depth the current depth of the node on the binary expression tree + * @param depth How far down a given Node is from the root OperatorNode */ inline void set_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const {set_value(offset);}; @@ -424,10 +421,10 @@ public: * @brief The pointer to where the feature's training data is stored * * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the current depth of the node on the binary expression tree - * @returns the pointer to the feature's data + * @param depth How far down a given Node is from the root OperatorNode + * @returns The pointer to the feature's data */ inline double* value_ptr(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const {return value_ptr(offset);}; @@ -435,9 +432,9 @@ public: * @brief Set the value of all test samples for the feature inside the central data storage array * * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the current depth of the node on the binary expression tree + * @param depth How far down a given Node is from the root OperatorNode */ inline void set_test_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const {set_test_value(offset);}; @@ -445,28 +442,28 @@ public: * @brief The pointer to where the feature's test data is stored * * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the current depth of the node on the binary expression tree - * @returns the pointer to the feature's data + * @param depth How far down a given Node is from the root OperatorNode + * @returns The pointer to the feature's data */ inline double* test_value_ptr(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const {return test_value_ptr(offset);}; /** * @brief The expression of the feature * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree - * @return feature expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode + * @return A human readable equation representing the feature */ inline std::string expr(const double* params, const int depth = 1) const {return _expr;}; /** * @brief Get the valid LaTeX expression that represents the feature * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree - * @return the latexified expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode + * @return Get the valid LaTeX expression that represents the feature */ inline std::string get_latex_expr(const double* params, const int depth=1) const {return str_utils::latexify(_expr);} @@ -474,8 +471,8 @@ public: /** * @brief Get the string that corresponds to the code needed to evaluate the node in matlab * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode * @return The matlab code for the feature */ virtual inline std::string matlab_fxn_expr(const double* params, const int depth=1) const @@ -484,27 +481,26 @@ public: } /** - * @brief Set the bounds for the nl parameterization + * @brief Set the upper and lower bounds for the scale and bias term of this Node and its children * - * @param lb pointer to the lower bounds data - * @param ub pointer to the upper bounds data - * @param from_parent How many parameters are between the start of this node's parameters and its parent - * @param depth the current depth of the node on the binary expression tree + * @param lb A pointer to the location where the lower bounds for the scale and bias term of this Node is set + * @param ub A pointer to the location where the upper bounds for the scale and bias term of this Node is set + * @param depth How far down a given Node is from the root OperatorNode */ inline void set_bounds(double* lb, double* ub, const int depth=1) const {}; /** - * @brief Set the bounds for the nl parameterization + * @brief Initialize the scale and bias terms for this Node and its children * - * @param params pointer to the parameters vector - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode */ virtual void initialize_params(double* params, const int depth = 1) const {}; /** * @brief Calculates the derivative of an operation with respect to the parameters for a given sample * - * @param params pointer to the parameters + * @param params A pointer to the bias and scale terms for this Node and its children * @param dfdp pointer to where the feature derivative pointers are located */ void param_derivative(const double* params, double* dfdp) const {} @@ -525,7 +521,7 @@ public: * * @param grad pointer to the gradient storage * @param dfdp pointer to where the feature derivative pointers are located - * @param params pointer to the parameters vector + * @param params A pointer to the bias and scale terms for this Node and its children */ inline void gradient(double* grad, double* dfdp, const double* params) const {}; #endif diff --git a/src/feature_creation/node/ModelNode.cpp b/src/feature_creation/node/ModelNode.cpp index 0ff3883435708347d8d6f37bff269e719b1dea53..b72010520db5db26e6e14a1a6e51e6c95da47c0c 100644 --- a/src/feature_creation/node/ModelNode.cpp +++ b/src/feature_creation/node/ModelNode.cpp @@ -21,7 +21,7 @@ ModelNode::ModelNode( const unsigned long int rung, const std::string expr, const std::string latex_expr, - const std::string expr_postfix, + const std::string postfix_expr, const std::string matlab_fxn_expr, const std::vector<double> value, const std::vector<double> test_value, @@ -30,10 +30,10 @@ ModelNode::ModelNode( ) : FeatureNode(feat_ind, expr, value, test_value, unit, false), _value_svm(_n_samp), - _test_value_svm(_n_test_samp), + _test_value_svm(_n_samp_test), _x_in_expr_list(x_in_expr_list), _latex_expr(latex_expr), - _expr_postfix(expr_postfix), + _postfix_expr(postfix_expr), _matlab_fxn_expr(matlab_fxn_expr), _b_remap_svm(0.0), _w_remap_svm(1.0), @@ -66,10 +66,10 @@ ModelNode::ModelNode( ModelNode::ModelNode(node_ptr in_node) : FeatureNode(in_node->feat_ind(), in_node->expr(), in_node->value(), in_node->test_value(), in_node->unit(), false), _value_svm(_n_samp), - _test_value_svm(_n_test_samp), + _test_value_svm(_n_samp_test), _x_in_expr_list(in_node->get_x_in_expr_list()), _latex_expr(in_node->latex_expr()), - _expr_postfix(in_node->postfix_expr()), + _postfix_expr(in_node->postfix_expr()), _matlab_fxn_expr(in_node->matlab_fxn_expr()), _b_remap_svm(0.0), _w_remap_svm(1.0), @@ -101,7 +101,7 @@ ModelNode::ModelNode(node_ptr in_node) : void ModelNode::generate_fxn_list() { - std::vector<std::string> postfix_split = str_utils::split_string_trim(_expr_postfix, "|"); + std::vector<std::string> postfix_split = str_utils::split_string_trim(_postfix_expr, "|"); std::vector<double> params; int pp = 0; std::vector<fxn_nterms_pair> fxn_list_rev; @@ -864,7 +864,7 @@ void ModelNode::generate_fxn_list() double ModelNode::eval(double* x_in) { std::vector<double*> stack; - std::vector<std::string> postfix_split = str_utils::split_string_trim(_expr_postfix, "|"); + std::vector<std::string> postfix_split = str_utils::split_string_trim(_postfix_expr, "|"); int ff = 0; int xx = 0; @@ -923,7 +923,7 @@ double ModelNode::eval(std::map<std::string, double> x_in_dct) std::vector<double> ModelNode::eval(std::vector<double>* x_in) { std::vector<double*> stack; - std::vector<std::string> postfix_split = str_utils::split_string_trim(_expr_postfix, "|"); + std::vector<std::string> postfix_split = str_utils::split_string_trim(_postfix_expr, "|"); int ff = 0; int xx = 0; @@ -1027,7 +1027,7 @@ void ModelNode::update_div_mult_leaves(std::map<std::string, double>& div_mult_l std::map<int, int> ModelNode::primary_feature_decomp() const { std::map<int, int> pf_decomp; - std::vector<std::string> split_postfix = str_utils::split_string_trim(_expr_postfix, "|"); + std::vector<std::string> split_postfix = str_utils::split_string_trim(_postfix_expr, "|"); for(auto& part : split_postfix) { try @@ -1053,7 +1053,7 @@ std::map<int, int> ModelNode::primary_feature_decomp() const void ModelNode::update_primary_feature_decomp(std::map<int, int>& pf_decomp) const { pf_decomp.clear(); - std::vector<std::string> split_postfix = str_utils::split_string_trim(_expr_postfix, "|"); + std::vector<std::string> split_postfix = str_utils::split_string_trim(_postfix_expr, "|"); for(auto& part : split_postfix) { try diff --git a/src/feature_creation/node/ModelNode.hpp b/src/feature_creation/node/ModelNode.hpp index 36d791e77d68626c9206b142e10865f12b464e37..212ec2632a7eb400c2919d99e5fb3e01dfe2882a 100644 --- a/src/feature_creation/node/ModelNode.hpp +++ b/src/feature_creation/node/ModelNode.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/ModelNode.hpp - * @brief The base class for describing features selected in SISSO Models + * @brief The base class for describing features selected in SISSO Models * * This is a standardized feature type for all features selected in SISSO Models. This is created to allow for easier I/O of the models * @@ -46,7 +46,7 @@ class ModelNode: public FeatureNode ar & _value_svm; ar & _test_value_svm; ar & _x_in_expr_list; - ar & _expr_postfix; + ar & _postfix_expr; ar & _latex_expr; ar & _matlab_fxn_expr; ar & _b_remap_svm; @@ -61,16 +61,16 @@ protected: std::vector<fxn_nterms_pair> _fxn_list; //!< list of functions used for evaluating feature values - std::vector<std::string> _x_in_expr_list; //!< vector storing the expressions for all primary features that show up in feature in the order they appear in the postfix notation - std::string _expr_postfix; //!< postfix expression for the feature - std::string _latex_expr; //!< postfix expression for the feature - std::string _matlab_fxn_expr; //!< The Matlab code needed to evaluate the feature + std::vector<std::string> _x_in_expr_list; //!< A vector storing the expressions for all primary features in the order they appear in the postfix expression + std::string _postfix_expr; //!< A computer readable representation of the feature. Primary features represented by their index in phi_0, node types are represented by abbreviations, and the order is the same as the postfix representation of the expression + std::string _latex_expr; //!< The valid LaTeX expression that represents the feature + std::string _matlab_fxn_expr; //!< The string that corresponds to the code needed to evaluate the node in matlab - double _b_remap_svm; //!< value to remap the b from SVM to real life - double _w_remap_svm; //!< value to remap the w from SVM to real life + double _b_remap_svm; //!< value to remap the b from SVM to the real value + double _w_remap_svm; //!< value to remap the w from SVM to the real value - int _rung; //!< rung of the feature - int _n_leaves; //!< Total number of primary features of the feature + int _rung; //!< The rung of the feature (Height of the binary expression tree - 1) + int _n_leaves; //!< The number of primary features (non-unique) this feature contains (The number of leaves of the Binary Expression Tree) public: /** * @brief Base Constructor @@ -82,13 +82,13 @@ public: /** * @brief Constructs a feature node * - * @param feat_ind index of the feature + * @param feat_ind The index of the feature * @param rung the rung of the feature * @param expr Expression for the feature - * @param latex_expr The LaTeXified expression for the feature + * @param latex_expr Get the valid LaTeX expression that represents the feature for the feature * @param matlab_fxn_expr The code to evaluate the feature in matlab - * @param value Value of the feature for each sample - * @param test_value Value of the feature for each test sample + * @param value The value for this feature's training data + * @param test_value The value for this feature's test data * @param x_in_expr_list vector storing the expressions for all primary features that show up in feature in the order they appear in the postfix notation * @param unit Unit of the feature */ @@ -97,7 +97,7 @@ public: const unsigned long int rung, const std::string expr, const std::string latex_expr, - const std::string expr_postfix, + const std::string postfix_expr, const std::string matlab_fxn_expr, const std::vector<double> value, const std::vector<double> test_value, @@ -146,8 +146,8 @@ public: ~ModelNode(); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ inline node_ptr hard_copy()const {return std::make_shared<ModelNode>(*this);} @@ -249,10 +249,10 @@ public: // DocString: model_node_set_value /** - * @brief Set the value of all training samples for the feature inside the central data storage array + * @brief Set the value of all training samples for the feature inside the central data storage arrays * * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth - * @param for_comp(bool) If true then the evaluation is used for comparing features + * @param for_comp (bool) If true then the evaluation is used for comparing features */ inline void set_value(int offset=-1, const bool for_comp=false) const {return;} @@ -261,7 +261,7 @@ public: * @brief Set the value of all test samples for the feature inside the central data storage array * * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth - * @param for_comp(bool) If true then the evaluation is used for comparing features + * @param for_comp (bool) If true then the evaluation is used for comparing features */ inline void set_test_value(int offset=-1, const bool for_comp=false) const {return;} @@ -328,8 +328,7 @@ public: // DocString: model_node_rung /** - * @brief return the rung of the feature (Height of the binary expression tree + 1) - * + * @brief return the rung of the feature (Height of the binary expression tree - 1) */ inline int rung(int cur_rung = 0) const {return _rung;} @@ -342,15 +341,15 @@ public: /** * @brief Get the primary feature decomposition of a feature + * * @return A map representing the primary feature comprising a feature */ std::map<int, int> primary_feature_decomp() const; /** - * @brief Get the three character representation of the operator - * @return the three character representation of the operator + * @brief Get the term used in the postfix expression for this Node */ - inline std::string get_postfix_term() const {return _expr_postfix;} + inline std::string get_postfix_term() const {return _postfix_expr;} // DocString: model_node_latex_expr /** @@ -370,21 +369,20 @@ public: } /** - * @brief update the dictionary used to check if an Add/Sub node is valid + * @brief update the dictionary used to check if an Add/Sub/AbsDiff node is valid * * @param add_sub_leaves the dictionary used to check if an Add/Sub node is valid - * @param pl_mn if for an addition node: 1 if for a subtraction node: -1 + * @param pl_mn 1 for addition and -1 for subtraction * @param expected_abs_tot The expected absolute sum of all values in add_sub_leaves */ void update_add_sub_leaves(std::map<std::string, int>& add_sub_leaves, const int pl_mn, int& expected_abs_tot) const; /** - * @brief update the dictionary used to check if a mult/div node is valid + * @brief update the dictionary used to check if an Mult/Div node is valid * * @param div_mult_leaves the dictionary used to check if an Mult/Div node is valid - * @param fact Factor used to update leaves (power of the feature) + * @param fact amount to increment the element (a primary features) of the dictionary by * @param expected_abs_tot The expected absolute sum of all values in div_mult_leaves - * */ void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, const double fact, double& expected_abs_tot) const; @@ -393,14 +391,15 @@ public: /** * @brief Constructs a feature node * - * @param feat_ind (int) index of the feature + * @param feat_ind (int)The index of the feature * @param rung (int) the rung of the feature * @param expr (str) Expression for the feature - * @param latex_expr (str) The LaTeXified expression for the feature + * @param latex_expr (str) Get the valid LaTeX expression that represents the feature for the feature + * @param postfix_expr (str) A computer readable representation of the feature. Primary features represented by their index in phi_0, node types are represented by abbreviations, and the order is the same as the postfix representation of the expression * @param matlab_fxn_expr (str) The code to evaluate the feature in matlab - * @param value (list) Value of the feature for each sample - * @param test_value (list) Value of the feature for each test sample - * @param x_in_expr_list (list) //!< vector storing the expressions for all primary features that show up in feature in the order they appear in the postfix notation + * @param value (list) The value for this feature's training data + * @param test_value (list) The value for this feature's test data + * @param x_in_expr_list (list) vector storing the expressions for all primary features that show up in feature in the order they appear in the postfix notation * @param unit (Unit) Unit of the feature */ ModelNode( @@ -408,7 +407,7 @@ public: const unsigned long int rung, const std::string expr, const std::string latex_expr, - const std::string expr_postfix, + const std::string postfix_expr, const std::string matlab_fxn_expr, const py::list value, const py::list test_value, @@ -420,14 +419,15 @@ public: /** * @brief Constructs a feature node * - * @param feat_ind (int) index of the feature + * @param feat_ind (int)The index of the feature * @param rung (int) the rung of the feature * @param expr (str) Expression for the feature - * @param latex_expr (str) The LaTeXified expression for the feature + * @param latex_expr (str) Get the valid LaTeX expression that represents the feature for the feature + * @param postfix_expr (str) A computer readable representation of the feature. Primary features represented by their index in phi_0, node types are represented by abbreviations, and the order is the same as the postfix representation of the expression * @param matlab_fxn_expr (str) The code to evaluate the feature in matlab - * @param value (np.ndarray) Value of the feature for each sample - * @param test_value (np.ndarray) Value of the feature for each test sample - * @param x_in_expr_list (list) //!< vector storing the expressions for all primary features that show up in feature in the order they appear in the postfix notation + * @param value (np.ndarray) The value for this feature's training data + * @param test_value (np.ndarray) The value for this feature's test data + * @param x_in_expr_list (np.ndarray) vector storing the expressions for all primary features that show up in feature in the order they appear in the postfix notation * @param unit (Unit) Unit of the feature */ ModelNode( @@ -435,7 +435,7 @@ public: const unsigned long int rung, const std::string expr, const std::string latex_expr, - const std::string expr_postfix, + const std::string postfix_expr, const std::string matlab_fxn_expr, const np::ndarray value, const np::ndarray test_value, @@ -490,7 +490,6 @@ public: /** * @brief get the list of feature expressions for each of the leaves - * @return Python list containing the expression for each leaf in the binary expression tree */ inline py::list x_in_expr_list_py(){return python_conv_utils::to_list<std::string>(_x_in_expr_list);} #endif @@ -500,8 +499,8 @@ public: /** * @brief Get the string that corresponds to the code needed to evaluate the node in matlab * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode * @return The matlab code for the feature */ inline std::string matlab_fxn_expr(const double* params, const int depth=1) const diff --git a/src/feature_creation/node/Node.cpp b/src/feature_creation/node/Node.cpp index beec8bb39857447a24ce69767b3003926a1ccd70..9fa6a13939cdc4abb9e7f4209726bdd44f465bfa 100644 --- a/src/feature_creation/node/Node.cpp +++ b/src/feature_creation/node/Node.cpp @@ -16,8 +16,8 @@ Node::Node() {} -Node::Node(const unsigned long int feat_ind, const int n_samp, const int n_test_samp) : - _n_test_samp(n_test_samp), +Node::Node(const unsigned long int feat_ind, const int n_samp, const int n_samp_test) : + _n_samp_test(n_samp_test), _n_samp(n_samp), _feat_ind(feat_ind), _arr_ind(feat_ind), diff --git a/src/feature_creation/node/Node.hpp b/src/feature_creation/node/Node.hpp index 6b4e7a8a325484d2d8cf39750167cf33bf12e0a1..cf160dbb32945cad4835f35ab85265466f464e1b 100644 --- a/src/feature_creation/node/Node.hpp +++ b/src/feature_creation/node/Node.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/Node.hpp - * @brief The base class for describing features + * @brief The base class for describing features * * This package represents the features in SISSO as a binary expression tree and are accessible from the root node of that tree. * The node class are the vertices of the tree and represent initial features (FeatureNode) and all algebraic operators (OperatorNodes). @@ -58,7 +58,7 @@ class Node template <typename Archive> void serialize(Archive& ar, const unsigned int version) { - ar & _n_test_samp; + ar & _n_samp_test; ar & _n_samp; ar & _feat_ind; ar & _arr_ind; @@ -67,11 +67,11 @@ class Node } protected: - int _n_test_samp; //!< Number of samples in the feature's test set - int _n_samp; //!< Number of samples in the feature's test set - unsigned long int _feat_ind; //!< Index of the feature - unsigned long int _arr_ind; //!< Index of the feature for the value arrays - int _d_mat_ind; //!< Index for the feature matrix + int _n_samp; //!< Number of samples in the training set + int _n_samp_test; //!< Number of samples in the test set + unsigned long int _feat_ind; //!< The unique index ID for the feature + unsigned long int _arr_ind; //!< The index that is used to access the data stored in the central data storage + int _d_mat_ind; //!< The index used to access the data stored in the description matrix bool _selected; //!< True if the feature is selected; public: @@ -84,11 +84,11 @@ public: /** * @brief Constructor that specifies feature index and number of samples * - * @param feat_ind index of the feature - * @param n_samp number of samples in the node - * @param n_samp number of test samples in the node + * @param feat_ind The index of the feature + * @param n_samp The number of samples in the training set + * @param n_samp_test The number of samples in the test set */ - Node(const unsigned long int feat_ind, const int n_samp, int n_test_samp); + Node(const unsigned long int feat_ind, const int n_samp, int n_samp_test); /** * @brief Copy Constructor @@ -124,16 +124,15 @@ public: virtual ~Node(); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ virtual std::shared_ptr<Node> hard_copy()const = 0; /** - * @brief Resets the features of a operator to ones in the feature_space - * @details Relink all feature to those in the FeatureSpace in case MPI copies break the links + * @brief Relinks all features of an OperatorNodes's _feat member to Nodes inside of phi * - * @param phi feature space vector + * @param phi A vector containing all Nodes that this Node can relink to */ virtual void reset_feats(std::vector<std::shared_ptr<Node>>& phi) = 0; @@ -170,10 +169,10 @@ public: inline void reindex(const unsigned long int feat_ind, const unsigned long int arr_ind){_feat_ind = feat_ind; _arr_ind = arr_ind;} /** - * @brief Get the score used to sort the features + * @brief Get the score used to sort the features in the feature space (Based on the type of node and _feat_ind) * - * @param max_ind the maximum index of the input nodes - * @return the score used to sort the feature space + * @param max_ind The maximum index of the input nodes + * @return The score used to sort the feature space */ virtual unsigned long long sort_score(unsigned int max_ind) const = 0; @@ -183,11 +182,11 @@ public: */ inline int n_samp() const {return _n_samp;} - // DocString: node_n_test_samp + // DocString: node_n_samp_test /** * @brief The number of samples in the test set */ - inline int n_test_samp() const {return _n_test_samp;} + inline int n_samp_test() const {return _n_samp_test;} // DocString: node_feat_ind /** @@ -210,7 +209,7 @@ public: /** * @brief Setter function for _selected * - * @param sel is the feature selected? + * @param sel True if the feature selected */ inline void set_selected(const bool sel){_selected = sel;} @@ -251,21 +250,18 @@ public: virtual Unit unit() const = 0; /** - * @brief An array containing the values of the training set samples for the feature - + * @brief A vector containing the values of the training set samples for the feature */ virtual std::vector<double> value() const = 0; /** - * @brief An array containing the values of the test set samples for the feature - + * @brief A vector containing the values of the test set samples for the feature */ virtual std::vector<double> test_value() const = 0; - // DocString: node_set_value /** - * @brief Set the value of all training samples for the feature inside the central data storage array + * @brief Set the value of all training samples for the feature inside the central data storage arrays * * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features @@ -277,6 +273,8 @@ public: * * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features + * + * @return pointer to the feature's training value */ virtual double* value_ptr(int offset=-1, const bool for_comp=false) const = 0; @@ -294,6 +292,8 @@ public: * * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features + * + * @return pointer to the feature's test values */ virtual double* test_value_ptr(int offset=-1, const bool for_comp=false) const = 0; @@ -320,7 +320,7 @@ public: // DocString: node_rung /** - * @brief return the rung of the feature (Height of the binary expression tree + 1) + * @brief Return the rung of the feature (Height of the binary expression tree - 1) * * @param cur_rung (int) A recursive helper counter for the rung */ @@ -328,6 +328,7 @@ public: /** * @brief Get the primary feature decomposition of a feature + * * @return A map representing the primary feature comprising a feature */ virtual std::map<int, int> primary_feature_decomp() const = 0; @@ -340,12 +341,12 @@ public: virtual void update_primary_feature_decomp(std::map<int, int>& pf_decomp) const = 0; /** - * @brief Converts a feature into a postfix expression (reverse polish notation) + * @brief Converts a feature into a postfix expression * * @details Recursively creates a postfix representation of the string * * @param cur_expr The current expression - * @param add_params If true include the parameters in teh postfix expression + * @param add_params If true include the parameters in the postfix expression * @return The current postfix expression of the feature */ virtual void update_postfix(std::string& cur_expr, const bool add_params=true) const = 0; @@ -357,14 +358,13 @@ public: inline std::string postfix_expr() const {std::string cur_expr = ""; update_postfix(cur_expr); return cur_expr.substr(0, cur_expr.size() - 1);} /** - * @brief Get a computer readable representation of the feature. Primary features represented by their index in phi_0, node types are represented by abbreviations, and the order is the same as the postfix representation of the expression - * @return the string representation of the node for the postfix expression + * @brief Get the term used in the postfix expression for this Node */ virtual std::string get_postfix_term() const = 0; // DocString: node_matlab_expr /** - * @brief Get the string that corresponds to the code needed to evaluate the node in matlab + * @brief The string that corresponds to the code needed to evaluate the node in matlab * @return The matlab code for the feature */ virtual std::string matlab_fxn_expr() const = 0; @@ -373,7 +373,7 @@ public: * @brief update the dictionary used to check if an Add/Sub/AbsDiff node is valid * * @param add_sub_leaves the dictionary used to check if an Add/Sub node is valid - * @param pl_mn if for an addition node: 1 if for a subtraction node: -1 + * @param pl_mn 1 for addition and -1 for subtraction * @param expected_abs_tot The expected absolute sum of all values in add_sub_leaves */ virtual void update_add_sub_leaves(std::map<std::string, int>& add_sub_leaves, const int pl_mn, int& expected_abs_tot) const = 0; @@ -382,7 +382,7 @@ public: * @brief update the dictionary used to check if an Mult/Div node is valid * * @param div_mult_leaves the dictionary used to check if an Mult/Div node is valid - * @param fact amount to increment the dictionary by + * @param fact amount to increment the element (a primary features) of the dictionary by * @param expected_abs_tot The expected absolute sum of all values in div_mult_leaves */ virtual void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, const double fact, double& expected_abs_tot) const = 0; @@ -390,37 +390,37 @@ public: #ifdef PARAMETERIZE /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ virtual std::vector<double> parameters() const = 0; /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node * @param check_sz If true check the size of the parameters */ virtual void set_parameters(const std::vector<double> params, const bool check_sz=true) = 0; /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ virtual void set_parameters(const double* params) = 0; // DocString: node_get_params /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to get the paremeters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ virtual void get_parameters(std::shared_ptr<NLOptimizer> optimizer) = 0; /** * @brief returns the number of parameters for this feature * - * @param n_cur the current number of parameters for the feature - * @param depth the current depth of the node on the binary expression tree + * @param n_cur A recursive helper variable to count the number of parameters of the Node + * @param depth How far down a given Node is from the root OperatorNode * @return the number of parameters (_params.size()) */ virtual int n_params(const int n_cur = 0, const int depth = 1) const = 0; @@ -429,9 +429,9 @@ public: * @brief Set the value of all training samples for the feature inside the central data storage array * * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the current depth of the node in the binary expression tree (from the root) + * @param depth (int) How far down a given Node is from the root OperatorNode */ virtual void set_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const = 0; @@ -439,10 +439,10 @@ public: * @brief The pointer to where the feature's training data is stored * * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the current depth of the node in the binary expression tree (from the root) - * @returns the pointer to the feature's data + * @param depth (int) How far down a given Node is from the root OperatorNode + * @returns The pointer to the feature's data */ virtual double* value_ptr(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const = 0; @@ -450,9 +450,9 @@ public: * @brief Set the value of all test samples for the feature inside the central data storage array * * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the current depth of the node in the binary expression tree (from the root) + * @param depth How far down a given Node is from the root OperatorNode */ virtual void set_test_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const = 0; @@ -460,28 +460,28 @@ public: * @brief The pointer to where the feature's test data is stored * * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the current depth of the node in the binary expression tree (from the root) - * @returns the pointer to the feature's data + * @param depth How far down a given Node is from the root OperatorNode + * @returns The pointer to the feature's data */ virtual double* test_value_ptr(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const = 0; /** * @brief The expression of the feature * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree - * @return feature expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode + * @return A human readable equation representing the feature */ virtual std::string expr(const double* params, const int depth = 1) const = 0; /** * @brief Get valid LaTeX equation that represents the feature * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree - * @return the latexified expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode + * @return Get the valid LaTeX expression that represents the feature */ virtual std::string get_latex_expr(const double* params, const int depth=1) const = 0; @@ -489,34 +489,33 @@ public: /** * @brief Get the string that corresponds to the code needed to evaluate the node in matlab * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode * @return The matlab code for the feature */ virtual std::string matlab_fxn_expr(const double* params, const int depth=1) const = 0; /** - * @brief Set the bounds for the nl parameterization + * @brief Set the upper and lower bounds for the scale and bias term of this Node and its children * - * @param lb pointer to the lower bounds data - * @param ub pointer to the upper bounds data - * @param from_parent How many parameters are between the start of this node's parameters and its parent - * @param depth the current depth of the node on the binary expression tree + * @param lb A pointer to the location where the lower bounds for the scale and bias term of this Node is set + * @param ub A pointer to the location where the upper bounds for the scale and bias term of this Node is set + * @param depth How far down a given Node is from the root OperatorNode */ virtual void set_bounds(double* lb, double* ub, const int depth=1) const = 0; /** - * @brief Set the bounds for the nl parameterization + * @brief Initialize the scale and bias terms for this Node and its children * - * @param params pointer to the parameters vector - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode */ virtual void initialize_params(double* params, const int depth = 1) const = 0; /** * @brief Calculates the derivative of an operation with respect to the parameters for a given sample * - * @param params pointer to the parameters + * @param params A pointer to the bias and scale terms for this Node and its children * @param samp_ind sample index number */ virtual void param_derivative(const double* params, double* dfdp) const = 0; @@ -534,7 +533,7 @@ public: * * @param grad pointer to the gradient storage * @param dfdp pointer to where the feature derivative pointers are located - * @param params pointer to the parameters vector + * @param params A pointer to the bias and scale terms for this Node and its children */ virtual void gradient(double* grad, double* dfdp, const double* params) const = 0; #endif @@ -572,7 +571,7 @@ public: #ifdef PARAMETERIZE // DocString: node_parameters_py /** - * @brief The vector storing all non-linear parameters of the feature + * @brief A list containing all scale and bias terms for this Node */ inline py::list parameters_py(){return python_conv_utils::to_list<double>(parameters());} #endif @@ -588,6 +587,10 @@ public: typedef std::shared_ptr<Node> node_ptr; +/** + * @brief Exception used when a Node Object can't be created for some reason + * + */ class InvalidFeatureException: public std::exception { inline const char * what () const throw () { diff --git a/src/feature_creation/node/operator_nodes/OperatorNode.hpp b/src/feature_creation/node/operator_nodes/OperatorNode.hpp index 0a368c0bb5df806edd4d2ddcbc2aae2667618878..2a18036bb8e271ba49ed4ed00cb87d48a703b99f 100644 --- a/src/feature_creation/node/operator_nodes/OperatorNode.hpp +++ b/src/feature_creation/node/operator_nodes/OperatorNode.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/OperatorNode.hpp - * @brief Base class for representing all algebraic operators in the binary expression tree + * @brief Base class for representing all algebraic operators in the binary expression tree * * This class represents the non-leaf verticies in the binary expression tree. This also stores all edges of the graph * @@ -67,7 +67,7 @@ class OperatorNode: public Node ar & _feats; } protected: - std::array<node_ptr, N> _feats; //!< The features for the operator nodes to act on (edges of the graph) + std::array<node_ptr, N> _feats; //!< The features for the operator nodes to act on (This Node's children) public: /** @@ -81,11 +81,11 @@ public: * @brief Constructor * @details Constructs an operator node with a set of features * - * @param feats array of features that the operator will act on - * @param feat_ind index of the feature + * @param feats Array of features that the operator will act on + * @param feat_ind The index of the feature */ OperatorNode(const std::array<node_ptr, N> feats, const unsigned long int feat_ind) : - Node(feat_ind, feats[0]->n_samp(), feats[0]->n_test_samp()), + Node(feat_ind, feats[0]->n_samp(), feats[0]->n_samp_test()), _feats(feats) {} @@ -123,16 +123,15 @@ public: {} /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ virtual node_ptr hard_copy()const = 0; /** - * @brief Resets the features of a operator to ones in the feature_space - * @details Relink all feature to those in the FeatureSpace in case MPI copies break the links + * @brief Relinks all features of an OperatorNodes's _feat member to Nodes inside of phi * - * @param phi feature space vector + * @param phi A vector containing all Nodes that this Node can relink to */ void reset_feats(std::vector<node_ptr>& phi) { @@ -167,10 +166,10 @@ public: } /** - * @brief Get the score used to sort the features + * @brief Get the score used to sort the features in the feature space (Based on the type of node and _feat_ind) * - * @param max_ind the maximum index of the input nodes - * @return the score used to sort the feature space + * @param max_ind The maximum index of the input nodes + * @return The score used to sort the feature space */ unsigned long long sort_score(unsigned int max_ind) const { @@ -198,8 +197,7 @@ public: virtual std::string get_latex_expr() const = 0; /** - * @brief An array containing the values of the training set samples for the feature - + * @brief A vector containing the values of the training set samples for the feature */ std::vector<double> value() const { @@ -209,13 +207,12 @@ public: } /** - * @brief An array containing the values of the test set samples for the feature - + * @brief A vector containing the values of the test set samples for the feature */ std::vector<double> test_value() const { - std::vector<double> val(_n_test_samp, 0.0); - std::copy_n(test_value_ptr(), _n_test_samp, val.data()); + std::vector<double> val(_n_samp_test, 0.0); + std::copy_n(test_value_ptr(), _n_samp_test, val.data()); return val; } @@ -241,7 +238,7 @@ public: * @brief Get the pointer to the feature's training data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * * @return pointer to the feature's training value @@ -272,7 +269,7 @@ public: * @brief Get the pointer to the feature's test data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * * @return pointer to the feature's test values @@ -328,7 +325,7 @@ public: // DocString: op_node_rung /** - * @brief return the rung of the feature (Height of the binary expression tree + 1) + * @brief return the rung of the feature (Height of the binary expression tree - 1) * * @param cur_rung (int) A recursive helper counter for the rung */ @@ -341,6 +338,7 @@ public: /** * @brief Get the primary feature decomposition of a feature + * * @return A map representing the primary feature comprising a feature */ std::map<int, int> primary_feature_decomp() const @@ -384,8 +382,7 @@ public: } /** - * @brief Get the string character representation of the node for the postfix expression - * @return the string representation of the node for the postfix expression + * @brief Get the term used in the postfix expression for this Node */ virtual std::string get_postfix_term() const = 0; @@ -420,36 +417,35 @@ public: } /** - * @brief update the dictionary used to check if an Add/Sub node is valid + * @brief update the dictionary used to check if an Add/Sub/AbsDiff node is valid * * @param add_sub_leaves the dictionary used to check if an Add/Sub node is valid - * @param pl_mn if for an addition node: 1 if for a subtraction node: -1 + * @param pl_mn 1 for addition and -1 for subtraction * @param expected_abs_tot The expected absolute sum of all values in add_sub_leaves */ virtual void update_add_sub_leaves(std::map<std::string, int>& add_sub_leaves, const int pl_mn, int& expected_abs_tot) const = 0; /** - * @brief update the dictionary used to check if a mult/div node is valid + * @brief update the dictionary used to check if an Mult/Div node is valid * * @param div_mult_leaves the dictionary used to check if an Mult/Div node is valid - * @param fact Factor used to update leaves (power of the feature) + * @param fact amount to increment the element (a primary features) of the dictionary by * @param expected_abs_tot The expected absolute sum of all values in div_mult_leaves - * */ virtual void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, const double fact, double& expected_abs_tot) const = 0; #ifdef PARAMETERIZE /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ virtual std::vector<double> parameters() const = 0; // DocString: op_node_get_params /** - * @brief Optimize the non-linear parameters of the feature - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer (NLOptimizer) The optimizer used to get the parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ virtual void get_parameters(std::shared_ptr<NLOptimizer> optimizer) = 0; @@ -462,7 +458,7 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ virtual void set_parameters(const double* params) = 0; @@ -471,7 +467,7 @@ public: * @brief returns the number of theoretical parameters for this feature * * @param n_cur the current number of parameters - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode * @return the number of theoretical parameters */ virtual inline int n_params(const int n_cur = 0, const int depth = 1) const @@ -487,21 +483,21 @@ public: /** * @brief Set the value of all training samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ virtual void set_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const = 0; /** * @brief The pointer to where the feature's training data is stored * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) - * @returns the pointer to the feature's data + * @param depth (int) How far down a given Node is from the root OperatorNode + * @returns The pointer to the feature's data */ double* value_ptr(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const { @@ -518,21 +514,21 @@ public: /** * @brief Set the value of all test samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ virtual void set_test_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const = 0; /** * @brief The pointer to where the feature's test data is stored * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) - * @returns the pointer to the feature's data + * @param depth (int) How far down a given Node is from the root OperatorNode + * @returns The pointer to the feature's test data */ double* test_value_ptr(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const { @@ -545,52 +541,51 @@ public: /** * @brief A human readable equation representing the feature * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree - * @return feature expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode + * @return A human readable equation representing the feature */ virtual std::string expr(const double* params, const int depth=1) const = 0; /** * @brief Get the valid LaTeX expression that represents the feature * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree - * @return the latexified expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode + * @return Get the valid LaTeX expression that represents the feature */ virtual std::string get_latex_expr(const double* params, const int depth=1) const = 0; /** * @brief Get the string that corresponds to the code needed to evaluate the node in matlab * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode * @return The matlab code for the feature */ virtual std::string matlab_fxn_expr(const double* params, const int depth=1) const = 0; /** - * @brief Set the bounds for the nl parameterization + * @brief Set the upper and lower bounds for the scale and bias term of this Node and its children * - * @param lb pointer to the lower bounds data - * @param ub pointer to the upper bounds data - * @param from_parent How many parameters are between the start of this node's parameters and its parent - * @param depth the current depth of the node on the binary expression tree + * @param lb A pointer to the location where the lower bounds for the scale and bias term of this Node is set + * @param ub A pointer to the location where the upper bounds for the scale and bias term of this Node is set + * @param depth How far down a given Node is from the root OperatorNode */ virtual void set_bounds(double* lb, double* ub, const int depth=1) const = 0; /** - * @brief Set the bounds for the nl parameterization + * @brief Initialize the scale and bias terms for this Node and its children * - * @param params pointer to the parameters vector - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode */ virtual void initialize_params(double* params, const int depth = 1) const = 0; /** * @brief Calculates the derivative of an operation with respect to the parameters for a given sample * - * @param params pointer to the parameters + * @param params A pointer to the bias and scale terms for this Node and its children * @param dfdp pointer to where the feature derivative pointers are located */ virtual void param_derivative(const double* params, double* dfdp) const = 0; @@ -615,7 +610,7 @@ public: * * @param grad pointer to the gradient storage * @param dfdp pointer to where the feature derivative are located - * @param params pointer to the parameters vector + * @param params A pointer to the bias and scale terms for this Node and its children */ void gradient(double* grad, double* dfdp, const double* params) const { diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs/absolute_value.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs/absolute_value.cpp index dcee8ea2de7d2a4389646d32ed5a35a470e511ee..d63a154b4f8dca47f46c830660c59a5b7617ffb1 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs/absolute_value.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs/absolute_value.cpp @@ -159,7 +159,7 @@ void AbsNode::set_test_value(int offset, const bool for_comp) const { offset += (offset == -1); allowed_op_funcs::abs( - _n_test_samp, + _n_samp_test, _feats[0]->test_value_ptr(2 * offset, for_comp), 1.0, 0.0, diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs/absolute_value.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs/absolute_value.hpp index dbc724269b9d0605630c4822471aaa451c38eb78..26926db8d70a0616f6d526328d520d3441fdd33c 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs/absolute_value.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs/absolute_value.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/absolute_value.hpp - * @brief Class describing the absolute value operator + * @brief Class describing the absolute value operator * * This class represents the unary operator -> |A| * @@ -52,8 +52,7 @@ public: AbsNode(); /** - * @brief Constructor - * @details Constructs the Node from an array of features to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -62,8 +61,7 @@ public: // DocString: abs_node_init /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -73,8 +71,8 @@ public: AbsNode(const node_ptr feat, const unsigned long int feat_ind, const double l_bound, const double u_bound); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ virtual node_ptr hard_copy()const; @@ -128,7 +126,7 @@ public: // DocString: abs_node_rung /** - * @brief return the rung of the feature (Height of the binary expression tree + 1) + * @brief return the rung of the feature (Height of the binary expression tree - 1) * */ inline int rung(const int cur_rung=0) const {return _feats[0]->rung(cur_rung + 1);} @@ -139,8 +137,7 @@ public: virtual inline NODE_TYPE type() const {return NODE_TYPE::ABS;} /** - * @brief Get the string character representation of the node for the postfix expression - * @return the string representation of the node for the postfix expression + * @brief Get the term used in the postfix expression for this Node */ inline std::string get_postfix_term() const {return "abs";} @@ -159,35 +156,34 @@ public: } /** - * @brief update the dictionary used to check if an Add/Sub node is valid + * @brief update the dictionary used to check if an Add/Sub/AbsDiff node is valid * * @param add_sub_leaves the dictionary used to check if an Add/Sub node is valid - * @param pl_mn if for an addition node: 1 if for a subtraction node: -1 + * @param pl_mn 1 for addition and -1 for subtraction * @param expected_abs_tot The expected absolute sum of all values in add_sub_leaves */ void update_add_sub_leaves(std::map<std::string, int>& add_sub_leaves, const int pl_mn, int& expected_abs_tot) const; /** - * @brief update the dictionary used to check if a mult/div node is valid + * @brief update the dictionary used to check if an Mult/Div node is valid * * @param div_mult_leaves the dictionary used to check if an Mult/Div node is valid - * @param fact Factor used to update leaves (power of the feature) + * @param fact amount to increment the element (a primary features) of the dictionary by * @param expected_abs_tot The expected absolute sum of all values in div_mult_leaves - * */ void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, const double fact, double& expected_abs_tot) const; #ifdef PARAMETERIZE /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ virtual std::vector<double> parameters() const {return {};} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ virtual void get_parameters(std::shared_ptr<NLOptimizer> optimizer){return;} @@ -200,36 +196,36 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ virtual void set_parameters(const double* params){return;} /** * @brief Set the value of all training samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief Set the value of all test samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_test_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief A human readable equation representing the feature * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree - * @return feature expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode + * @return A human readable equation representing the feature */ inline std::string expr(const double* params, const int depth=1) const { @@ -244,9 +240,9 @@ public: /** * @brief Get the valid LaTeX expression that represents the feature * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree - * @return the latexified expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode + * @return Get the valid LaTeX expression that represents the feature */ inline std::string get_latex_expr(const double* params, const int depth=1) const { @@ -261,8 +257,8 @@ public: /** * @brief Get the string that corresponds to the code needed to evaluate the node in matlab * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode * @return The matlab code for the feature */ inline std::string matlab_fxn_expr(const double* params, const int depth=1) const @@ -276,27 +272,26 @@ public: } /** - * @brief Set the bounds for the nl parameterization + * @brief Set the upper and lower bounds for the scale and bias term of this Node and its children * - * @param lb pointer to the lower bounds data - * @param ub pointer to the upper bounds data - * @param from_parent How many parameters are between the start of this node's parameters and its parent - * @param depth the current depth of the node on the binary expression tree + * @param lb A pointer to the location where the lower bounds for the scale and bias term of this Node is set + * @param ub A pointer to the location where the upper bounds for the scale and bias term of this Node is set + * @param depth How far down a given Node is from the root OperatorNode */ void set_bounds(double* lb, double* ub, const int depth=1) const; /** - * @brief Set the bounds for the nl parameterization + * @brief Initialize the scale and bias terms for this Node and its children * - * @param params pointer to the parameters vector - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode */ void initialize_params(double* params, const int depth = 1) const; /** * @brief Calculates the derivative of an operation with respect to the parameters for a given sample * - * @param params pointer to the parameters + * @param params A pointer to the bias and scale terms for this Node and its children * @param dfdp pointer to where the feature derivative pointers are located */ inline void param_derivative(const double* params, double* dfdp) const @@ -312,9 +307,9 @@ public: * * @param feat_list list of features already generated * @param feat feature to attempt to take the absolute value of - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. */ void generateAbsNode( std::vector<node_ptr>& feat_list, diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs/parameterized_absolute_value.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs/parameterized_absolute_value.cpp index 107b90ea9273bf2af201dc76cf308cdeb9ec890f..5b4d2a630d08401d97af37a4711b1931234a2f9e 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs/parameterized_absolute_value.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs/parameterized_absolute_value.cpp @@ -147,7 +147,7 @@ void AbsNode::set_test_value(const double* params, int offset, const bool for_co } allowed_op_funcs::abs( - _n_test_samp, vp_0, params[0], params[1], node_value_arrs::access_param_storage_test(rung(), offset, for_comp) + _n_samp_test, vp_0, params[0], params[1], node_value_arrs::access_param_storage_test(rung(), offset, for_comp) ); } diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs/parameterized_absolute_value.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs/parameterized_absolute_value.hpp index 2245168598e64997147ddb7bd6f2d84c2eeda897..8ec5026b5908adaec593f52bbb68867b0021d3ce 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs/parameterized_absolute_value.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs/parameterized_absolute_value.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/abs/parameterized_absolute_value.hpp - * @brief Class describing the parameterized absolute value operator + * @brief Class describing the parameterized absolute value operator * * This class represents the parameterized unary operator -> |alpha * A + a| * @@ -55,7 +55,7 @@ protected: using AbsNode::get_latex_expr; using AbsNode::matlab_fxn_expr; - std::vector<double> _params; //!< The parameters vector + std::vector<double> _params; //!< The vector containing the scale and bias terms for the Node public: /** @@ -65,14 +65,13 @@ public: AbsParamNode(); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature * @param l_bound (double) Minimum absolute value allowed for the feature. * @param u_bound (double) Maximum absolute value allowed for the feature. - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ AbsParamNode( const node_ptr feat, @@ -83,19 +82,17 @@ public: ); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ AbsParamNode(const node_ptr feat, const unsigned long int feat_ind, std::shared_ptr<NLOptimizer> optimizer); // DocString: abs_param_node_init /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -105,8 +102,8 @@ public: AbsParamNode(const node_ptr feat, const unsigned long int feat_ind, double const l_bound=1e-50, const double u_bound=1e50); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ node_ptr hard_copy()const; @@ -132,10 +129,10 @@ public: * @brief Get the pointer to the feature's training data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * - * @return pointer to the feature's test values + * @return A pointer to the feature's training data */ inline double* value_ptr(int offset=-1, const bool for_comp=false) const {return value_ptr(_params.data(), offset, for_comp);} @@ -143,7 +140,7 @@ public: * @brief Get the pointer to the feature's test data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * * @return pointer to the feature's test values @@ -176,15 +173,15 @@ public: inline std::string matlab_fxn_expr() const {return matlab_fxn_expr(_params.data());} /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ inline std::vector<double> parameters() const {return _params;} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ void get_parameters(std::shared_ptr<NLOptimizer> optimizer); @@ -205,7 +202,7 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ inline void set_parameters(const double* params) { @@ -229,9 +226,9 @@ public: * * @param feat_list list of features already generated * @param feat feature to attempt to take the absolute value of - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. * @param optimizer The optimizer used to find the parameters of the node */ void generateAbsParamNode( diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs_diff/absolute_difference.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs_diff/absolute_difference.cpp index 1e573558770e602d95b2e76406d2e507958f16b3..ca73bda552b75146955c5587ff4dd55ad1376f59 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs_diff/absolute_difference.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs_diff/absolute_difference.cpp @@ -196,7 +196,7 @@ void AbsDiffNode::set_test_value(int offset, const bool for_comp) const { offset += (offset == -1); allowed_op_funcs::abs_diff( - _n_test_samp, + _n_samp_test, _feats[0]->test_value_ptr(2 * offset, for_comp), _feats[1]->test_value_ptr(2 * offset + 1, for_comp), 1.0, diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs_diff/absolute_difference.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs_diff/absolute_difference.hpp index 19d45fc9660673686daf22136e38c2fc0479b09b..86533e75c3f903aec02bc8455fdcb1c2f08e015d 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs_diff/absolute_difference.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs_diff/absolute_difference.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/absolute_difference.hpp - * @brief Class describing the absolute difference operator + * @brief Class describing the absolute difference operator * * This class represents the binary operator -> |A - B| * @@ -53,21 +53,17 @@ public: AbsDiffNode(); /** - * @brief Constructor - * @details Constructs the Node from an array of features to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * * @param feat_1 (Node) shared_ptr of the first feature to operate on (A) * @param feat_2 (Node) shared_ptr of the second feature to operate on (B) * @param feat_ind (int) Index of the new feature - * @param l_bound (double) Minimum absolute value allowed for the feature. - * @param u_bound (double) Maximum absolute value allowed for the feature. */ AbsDiffNode(const node_ptr feat_1, const node_ptr feat_2, const unsigned long int feat_ind); // DocString: abs_diff_node_init /** - * @brief Constructor - * @details Constructs the Node from node pointer of the features to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat_1 (Node) shared_ptr of the first feature to operate on (A) * @param feat_2 (Node) shared_ptr of the second feature to operate on (B) @@ -78,8 +74,8 @@ public: AbsDiffNode(const node_ptr feat_1, const node_ptr feat_2, const unsigned long int feat_ind, const double l_bound, const double u_bound); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ virtual node_ptr hard_copy()const; @@ -136,7 +132,7 @@ public: // DocString: abs_diff_node_rung /** - * @brief return the rung of the feature (Height of the binary expression tree + 1) + * @brief return the rung of the feature (Height of the binary expression tree - 1) * */ inline int rung(const int cur_rung=0) const {return std::max(_feats[0]->rung(cur_rung + 1), _feats[1]->rung(cur_rung + 1));} @@ -147,8 +143,7 @@ public: virtual inline NODE_TYPE type() const {return NODE_TYPE::ABS_DIFF;} /** - * @brief Get the string character representation of the node for the postfix expression - * @return the string representation of the node for the postfix expression + * @brief Get the term used in the postfix expression for this Node */ inline std::string get_postfix_term() const {return "abd";} @@ -174,35 +169,34 @@ public: void check_feats(); /** - * @brief update the dictionary used to check if an Add/Sub node is valid + * @brief update the dictionary used to check if an Add/Sub/AbsDiff node is valid * * @param add_sub_leaves the dictionary used to check if an Add/Sub node is valid - * @param pl_mn if for an addition node: 1 if for a subtraction node: -1 + * @param pl_mn 1 for addition and -1 for subtraction * @param expected_abs_tot The expected absolute sum of all values in add_sub_leaves */ void update_add_sub_leaves(std::map<std::string, int>& add_sub_leaves, const int pl_mn, int& expected_abs_tot) const; /** - * @brief update the dictionary used to check if a mult/div node is valid + * @brief update the dictionary used to check if an Mult/Div node is valid * * @param div_mult_leaves the dictionary used to check if an Mult/Div node is valid - * @param fact Factor used to update leaves (power of the feature) + * @param fact amount to increment the element (a primary features) of the dictionary by * @param expected_abs_tot The expected absolute sum of all values in div_mult_leaves - * */ void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, const double fact, double& expected_abs_tot) const; #ifdef PARAMETERIZE /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ virtual std::vector<double> parameters() const {return {};} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ virtual void get_parameters(std::shared_ptr<NLOptimizer> optimizer){return;} @@ -215,36 +209,36 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ virtual void set_parameters(const double* params){return;} /** * @brief Set the value of all training samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief Set the value of all test samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_test_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief A human readable equation representing the feature * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree - * @return feature expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode + * @return A human readable equation representing the feature */ inline std::string expr(const double* params, const int depth=1) const { @@ -260,9 +254,9 @@ public: /** * @brief Get the valid LaTeX expression that represents the feature * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree - * @return the latexified expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode + * @return Get the valid LaTeX expression that represents the feature */ inline std::string get_latex_expr(const double* params, const int depth=1) const { @@ -278,8 +272,8 @@ public: /** * @brief Get the string that corresponds to the code needed to evaluate the node in matlab * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode * @return The matlab code for the feature */ inline std::string matlab_fxn_expr(const double* params, const int depth=1) const @@ -294,27 +288,26 @@ public: } /** - * @brief Set the bounds for the nl parameterization + * @brief Set the upper and lower bounds for the scale and bias term of this Node and its children * - * @param lb pointer to the lower bounds data - * @param ub pointer to the upper bounds data - * @param from_parent How many parameters are between the start of this node's parameters and its parent - * @param depth the current depth of the node on the binary expression tree + * @param lb A pointer to the location where the lower bounds for the scale and bias term of this Node is set + * @param ub A pointer to the location where the upper bounds for the scale and bias term of this Node is set + * @param depth How far down a given Node is from the root OperatorNode */ void set_bounds(double* lb, double* ub, const int depth=1) const; /** - * @brief Set the bounds for the nl parameterization + * @brief Initialize the scale and bias terms for this Node and its children * - * @param params pointer to the parameters vector - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode */ void initialize_params(double* params, const int depth = 1) const; /** * @brief Calculates the derivative of an operation with respect to the parameters for a given sample * - * @param params pointer to the parameters + * @param params A pointer to the bias and scale terms for this Node and its children * @param dfdp pointer to where the feature derivative pointers are located */ inline void param_derivative(const double* params, double* dfdp) const @@ -338,9 +331,9 @@ public: * @param feat_list list of features already generated * @param feat_1 The (A) feature * @param feat_2 The (B) feature - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. */ void generateAbsDiffNode(std::vector<node_ptr>& feat_list, const node_ptr feat_1, const node_ptr feat_2, unsigned long int& feat_ind, const double l_bound, const double u_bound); diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs_diff/parameterized_absolute_difference.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs_diff/parameterized_absolute_difference.cpp index 30c0ed0f5fec1c0fb26cc8816e643ce2327b86ed..8db24edb020a2fa530683e70a91cb01de48013d7 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs_diff/parameterized_absolute_difference.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs_diff/parameterized_absolute_difference.cpp @@ -210,7 +210,7 @@ void AbsDiffNode::set_test_value(const double* params, int offset, const bool fo } allowed_op_funcs::abs_diff( - _n_test_samp, vp_0, vp_1, params[0], params[1], node_value_arrs::access_param_storage_test(rung(), offset, for_comp) + _n_samp_test, vp_0, vp_1, params[0], params[1], node_value_arrs::access_param_storage_test(rung(), offset, for_comp) ); } diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs_diff/parameterized_absolute_difference.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs_diff/parameterized_absolute_difference.hpp index fc8f89c396b9bc10c24c104aaca69ea93a9786e1..40a591792fa37b1a73c0964bc7acbe8795b9153d 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs_diff/parameterized_absolute_difference.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs_diff/parameterized_absolute_difference.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/abs_diff/parameterized_absolute_difference.hpp - * @brief Class describing the parameterized absolute difference operator + * @brief Class describing the parameterized absolute difference operator * * This class represents the parameterized unary operator -> |A - alpha * B + a| * @@ -63,15 +63,14 @@ public: AbsDiffParamNode(); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * - * @param feat_1 shared_ptr of the feature to operate on (A) - * @param feat_2 shared_ptr of the feature to operate on (B) + * @param feat_1 (Node) shared_ptr of the feature to operate on (A) + * @param feat_2 (Node) shared_ptr of the feature to operate on (B) * @param feat_ind (int) Index of the new feature * @param l_bound (double) Minimum absolute value allowed for the feature. * @param u_bound (double) Maximum absolute value allowed for the feature. - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ AbsDiffParamNode( const node_ptr feat_1, @@ -83,23 +82,21 @@ public: ); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * - * @param feat_1 shared_ptr of the feature to operate on (A) - * @param feat_2 shared_ptr of the feature to operate on (B) + * @param feat_1 (Node) shared_ptr of the feature to operate on (A) + * @param feat_2 (Node) shared_ptr of the feature to operate on (B) * @param feat_ind (int) Index of the new feature - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ AbsDiffParamNode(const node_ptr feat_1, const node_ptr feat_2, const unsigned long int feat_ind, std::shared_ptr<NLOptimizer> optimizer); // DocString: abs_diff_param_node_init /** * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on * - * @param feat_1 shared_ptr of the feature to operate on (A) - * @param feat_2 shared_ptr of the feature to operate on (B) + * @param feat_1 (Node) shared_ptr of the feature to operate on (A) + * @param feat_2 (Node) shared_ptr of the feature to operate on (B) * @param feat_ind (int) Index of the new feature * @param l_bound (double) Minimum absolute value allowed for the feature. * @param u_bound (double) Maximum absolute value allowed for the feature. @@ -107,8 +104,8 @@ public: AbsDiffParamNode(const node_ptr feat_1, const node_ptr feat_2, const unsigned long int feat_ind, double const l_bound=1e-50, const double u_bound=1e50); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ node_ptr hard_copy()const; @@ -134,10 +131,10 @@ public: * @brief Get the pointer to the feature's training data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * - * @return pointer to the feature's test values + * @return A pointer to the feature's training data */ inline double* value_ptr(int offset=-1, const bool for_comp=false) const {return value_ptr(_params.data(), offset, for_comp);} @@ -145,7 +142,7 @@ public: * @brief Get the pointer to the feature's test data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * * @return pointer to the feature's test values @@ -178,15 +175,15 @@ public: inline std::string matlab_fxn_expr() const {return matlab_fxn_expr(_params.data());} /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ inline std::vector<double> parameters() const {return _params;} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ void get_parameters(std::shared_ptr<NLOptimizer> optimizer); @@ -207,7 +204,7 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ inline void set_parameters(const double* params) { @@ -232,9 +229,9 @@ public: * @param feat_list list of features already generated * @param feat_1 The (A) feature * @param feat_2 The (B) feature - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. * @param optimizer The optimizer used to find the parameters of the node */ void generateAbsDiffParamNode( diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/add/add.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/add/add.cpp index 053785876373729cbe65af94d6a8b8304f04a08b..48c639337fb35534f8b5ac5cd39a011bc059c601 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/add/add.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/add/add.cpp @@ -189,7 +189,7 @@ void AddNode::set_test_value(int offset, const bool for_comp) const { offset += (offset == -1); allowed_op_funcs::add( - _n_test_samp, + _n_samp_test, _feats[0]->test_value_ptr(2 * offset, for_comp), _feats[1]->test_value_ptr(2 * offset + 1, for_comp), 1.0, diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/add/add.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/add/add.hpp index b0794f3145474c41bbea0a0501b361f003a0b375..5c521ecdbbc780542ebf654cacdc36802eede40d 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/add/add.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/add/add.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/add.hpp - * @brief Class describing the addition operator + * @brief Class describing the addition operator * * This class represents the binary operator -> A + B * @@ -52,8 +52,7 @@ public: AddNode(); /** - * @brief Constructor - * @details Constructs the Node from an array of features to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * * @param feat_1 (Node) shared_ptr of the first feature to operate on (A) * @param feat_2 (Node) shared_ptr of the second feature to operate on (B) @@ -63,8 +62,7 @@ public: // DocString: add_node_init /** - * @brief Constructor - * @details Constructs the Node from node pointer of the features to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat_1 (Node) shared_ptr of the first feature to operate on (A) * @param feat_2 (Node) shared_ptr of the second feature to operate on (B) @@ -75,8 +73,8 @@ public: AddNode(const node_ptr feat_1, const node_ptr feat_2, const unsigned long int feat_ind, const double l_bound, const double u_bound); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ virtual node_ptr hard_copy()const; @@ -118,7 +116,7 @@ public: // DocString: add_node_rung /** - * @brief return the rung of the feature (Height of the binary expression tree + 1) + * @brief return the rung of the feature (Height of the binary expression tree - 1) * */ inline int rung(const int cur_rung=0) const {return std::max(_feats[0]->rung(cur_rung + 1), _feats[1]->rung(cur_rung + 1));} @@ -142,8 +140,7 @@ public: virtual inline NODE_TYPE type() const {return NODE_TYPE::ADD;} /** - * @brief Get the string character representation of the node for the postfix expression - * @return the string representation of the node for the postfix expression + * @brief Get the term used in the postfix expression for this Node */ inline std::string get_postfix_term() const {return "add";} @@ -168,35 +165,34 @@ public: void check_feats(); /** - * @brief update the dictionary used to check if an Add/Sub node is valid + * @brief update the dictionary used to check if an Add/Sub/AbsDiff node is valid * * @param add_sub_leaves the dictionary used to check if an Add/Sub node is valid - * @param pl_mn if for an addition node: 1 if for a subtraction node: -1 + * @param pl_mn 1 for addition and -1 for subtraction * @param expected_abs_tot The expected absolute sum of all values in add_sub_leaves */ void update_add_sub_leaves(std::map<std::string, int>& add_sub_leaves, const int pl_mn, int& expected_abs_tot) const; /** - * @brief update the dictionary used to check if a mult/div node is valid + * @brief update the dictionary used to check if an Mult/Div node is valid * * @param div_mult_leaves the dictionary used to check if an Mult/Div node is valid - * @param fact Factor used to update leaves (power of the feature) + * @param fact amount to increment the element (a primary features) of the dictionary by * @param expected_abs_tot The expected absolute sum of all values in div_mult_leaves - * */ void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, const double fact, double& expected_abs_tot) const; #ifdef PARAMETERIZE /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ virtual std::vector<double> parameters() const {return {};} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ virtual void get_parameters(std::shared_ptr<NLOptimizer> optimizer){return;} @@ -209,36 +205,36 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ virtual void set_parameters(const double* params){return;} /** * @brief Set the value of all training samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief Set the value of all test samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_test_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief A human readable equation representing the feature * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree - * @return feature expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode + * @return A human readable equation representing the feature */ inline std::string expr(const double* params, const int depth=1) const { @@ -253,9 +249,9 @@ public: /** * @brief Get the valid LaTeX expression that represents the feature * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree - * @return the latexified expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode + * @return Get the valid LaTeX expression that represents the feature */ inline std::string get_latex_expr(const double* params, const int depth=1) const { @@ -270,8 +266,8 @@ public: /** * @brief Get the string that corresponds to the code needed to evaluate the node in matlab * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode * @return The matlab code for the feature */ inline std::string matlab_fxn_expr(const double* params, const int depth=1) const @@ -285,27 +281,26 @@ public: } /** - * @brief Set the bounds for the nl parameterization + * @brief Set the upper and lower bounds for the scale and bias term of this Node and its children * - * @param lb pointer to the lower bounds data - * @param ub pointer to the upper bounds data - * @param from_parent How many parameters are between the start of this node's parameters and its parent - * @param depth the current depth of the node on the binary expression tree + * @param lb A pointer to the location where the lower bounds for the scale and bias term of this Node is set + * @param ub A pointer to the location where the upper bounds for the scale and bias term of this Node is set + * @param depth How far down a given Node is from the root OperatorNode */ void set_bounds(double* lb, double* ub, const int depth=1) const; /** - * @brief Set the bounds for the nl parameterization + * @brief Initialize the scale and bias terms for this Node and its children * - * @param params pointer to the parameters vector - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode */ void initialize_params(double* params, const int depth = 1) const; /** * @brief Calculates the derivative of an operation with respect to the parameters for a given sample * - * @param params pointer to the parameters + * @param params A pointer to the bias and scale terms for this Node and its children * @param dfdp pointer to where the feature derivative pointers are located */ inline void param_derivative(const double* params, double* dfdp) const {std::fill_n(dfdp, _n_samp, 1.0);} @@ -318,9 +313,9 @@ public: * @param feat_list list of features already generated * @param feat_1 The (A) feature * @param feat_2 The (B) feature - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. */ void generateAddNode(std::vector<node_ptr>& feat_list, const node_ptr feat_1, const node_ptr feat_2, unsigned long int& feat_ind, const double l_bound, const double u_bound); diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/add/parameterized_add.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/add/parameterized_add.cpp index 5aae7814ac9d0320b310e36039319d796fd885e2..2e6c7763de2441ffbc5c7d40a92feae51413a6e2 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/add/parameterized_add.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/add/parameterized_add.cpp @@ -173,7 +173,7 @@ void AddNode::set_test_value(const double* params, int offset, const bool for_co } allowed_op_funcs::add( - _n_test_samp, + _n_samp_test, vp_0, vp_1, params[0], diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/add/parameterized_add.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/add/parameterized_add.hpp index 923867899096c5fde6a95f6aed1e925a5083612d..27816574bdcdd9a213e5f76736627f815fc90744 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/add/parameterized_add.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/add/parameterized_add.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/add/parameterized_add.hpp - * @brief Class describing the parameterized addition operator + * @brief Class describing the parameterized addition operator * * This class represents the parameterized unary operator -> A + alpha * B + a * @@ -65,15 +65,14 @@ public: AddParamNode(); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * - * @param feat_1 shared_ptr of the feature to operate on (A) - * @param feat_2 shared_ptr of the feature to operate on (B) + * @param feat_1 (Node) shared_ptr of the feature to operate on (A) + * @param feat_2 (Node) shared_ptr of the feature to operate on (B) * @param feat_ind (int) Index of the new feature * @param l_bound (double) Minimum absolute value allowed for the feature. * @param u_bound (double) Maximum absolute value allowed for the feature. - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ AddParamNode( const node_ptr feat_1, @@ -85,20 +84,18 @@ public: ); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * - * @param feat_1 shared_ptr of the feature to operate on (A) - * @param feat_2 shared_ptr of the feature to operate on (B) + * @param feat_1 (Node) shared_ptr of the feature to operate on (A) + * @param feat_2 (Node) shared_ptr of the feature to operate on (B) * @param feat_ind (int) Index of the new feature - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ AddParamNode(const node_ptr feat_1, const node_ptr feat_2, const unsigned long int feat_ind, std::shared_ptr<NLOptimizer> optimizer); // DocString: add_param_node_init /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -108,8 +105,8 @@ public: AddParamNode(const node_ptr feat_1, const node_ptr feat_2, const unsigned long int feat_ind, double const l_bound=1e-50, const double u_bound=1e50); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ node_ptr hard_copy()const; @@ -135,10 +132,10 @@ public: * @brief Get the pointer to the feature's training data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * - * @return pointer to the feature's test values + * @return A pointer to the feature's training data */ inline double* value_ptr(int offset=-1, const bool for_comp=false) const {return value_ptr(_params.data(), offset, for_comp);} @@ -146,7 +143,7 @@ public: * @brief Get the pointer to the feature's test data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * * @return pointer to the feature's test values @@ -179,15 +176,15 @@ public: inline std::string matlab_fxn_expr() const {return matlab_fxn_expr(_params.data());} /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ inline std::vector<double> parameters() const {return _params;} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ void get_parameters(std::shared_ptr<NLOptimizer> optimizer); @@ -208,7 +205,7 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ inline void set_parameters(const double* params) { @@ -233,9 +230,9 @@ public: * @param feat_list list of features already generated * @param feat_1 The (A) feature * @param feat_2 The (B) feature - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. * @param optimizer The optimizer used to find the parameters of the node */ void generateAddParamNode( diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cb/cube.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cb/cube.cpp index 0a80999e40a8e4b553a054b5c1d0dc294f45afb4..bcd1b8299e846391edf12578ae49f8f26987e401 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cb/cube.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cb/cube.cpp @@ -143,7 +143,7 @@ void CbNode::set_test_value(int offset, const bool for_comp) const { offset += (offset == -1); allowed_op_funcs::cb( - _n_test_samp, + _n_samp_test, _feats[0]->test_value_ptr(2 * offset, for_comp), 1.0, 0.0, diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cb/cube.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cb/cube.hpp index 0507c0f1b685c03a8be1b0519b77d2e7e521c23a..1dc050d509c8c87616c4e41ba822dbb282b531c4 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cb/cube.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cb/cube.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/cube.hpp - * @brief Class describing the cube operator + * @brief Class describing the cube operator * * This class represents the unary operator -> (A)^3 * @@ -52,8 +52,7 @@ public: CbNode(); /** - * @brief Constructor - * @details Constructs the Node from an array of features to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -62,8 +61,7 @@ public: // DocString: cb_node_init /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -73,8 +71,8 @@ public: CbNode(const node_ptr feat, const unsigned long int feat_ind, const double l_bound, const double u_bound); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ virtual node_ptr hard_copy()const; @@ -128,7 +126,7 @@ public: // DocString: cb_node_rung /** - * @brief return the rung of the feature (Height of the binary expression tree + 1) + * @brief return the rung of the feature (Height of the binary expression tree - 1) * */ inline int rung(const int cur_rung=0) const {return _feats[0]->rung(cur_rung + 1);} @@ -139,8 +137,7 @@ public: virtual inline NODE_TYPE type() const {return NODE_TYPE::CB;} /** - * @brief Get the string character representation of the node for the postfix expression - * @return the string representation of the node for the postfix expression + * @brief Get the term used in the postfix expression for this Node */ inline std::string get_postfix_term() const {return "cb";} @@ -159,35 +156,34 @@ public: } /** - * @brief update the dictionary used to check if an Add/Sub node is valid + * @brief update the dictionary used to check if an Add/Sub/AbsDiff node is valid * * @param add_sub_leaves the dictionary used to check if an Add/Sub node is valid - * @param pl_mn if for an addition node: 1 if for a subtraction node: -1 + * @param pl_mn 1 for addition and -1 for subtraction * @param expected_abs_tot The expected absolute sum of all values in add_sub_leaves */ void update_add_sub_leaves(std::map<std::string, int>& add_sub_leaves, const int pl_mn, int& expected_abs_tot) const; /** - * @brief update the dictionary used to check if a mult/div node is valid + * @brief update the dictionary used to check if an Mult/Div node is valid * * @param div_mult_leaves the dictionary used to check if an Mult/Div node is valid - * @param fact Factor used to update leaves (power of the feature) + * @param fact amount to increment the element (a primary features) of the dictionary by * @param expected_abs_tot The expected absolute sum of all values in div_mult_leaves - * */ void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, const double fact, double& expected_abs_tot) const; #ifdef PARAMETERIZE /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ virtual std::vector<double> parameters() const {return {};} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ virtual void get_parameters(std::shared_ptr<NLOptimizer> optimizer){return;} @@ -200,36 +196,36 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ virtual void set_parameters(const double* params){return;} /** * @brief Set the value of all training samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief Set the value of all test samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_test_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief A human readable equation representing the feature * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree - * @return feature expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode + * @return A human readable equation representing the feature */ inline std::string expr(const double* params, const int depth=1) const { @@ -243,9 +239,9 @@ public: /** * @brief Get the valid LaTeX expression that represents the feature * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree - * @return the latexified expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode + * @return Get the valid LaTeX expression that represents the feature */ inline std::string get_latex_expr(const double* params, const int depth=1) const { @@ -259,8 +255,8 @@ public: /** * @brief Get the string that corresponds to the code needed to evaluate the node in matlab * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode * @return The matlab code for the feature */ inline std::string matlab_fxn_expr(const double* params, const int depth=1) const @@ -273,27 +269,26 @@ public: } /** - * @brief Set the bounds for the nl parameterization + * @brief Set the upper and lower bounds for the scale and bias term of this Node and its children * - * @param lb pointer to the lower bounds data - * @param ub pointer to the upper bounds data - * @param from_parent How many parameters are between the start of this node's parameters and its parent - * @param depth the current depth of the node on the binary expression tree + * @param lb A pointer to the location where the lower bounds for the scale and bias term of this Node is set + * @param ub A pointer to the location where the upper bounds for the scale and bias term of this Node is set + * @param depth How far down a given Node is from the root OperatorNode */ void set_bounds(double* lb, double* ub, const int depth=1) const; /** - * @brief Set the bounds for the nl parameterization + * @brief Initialize the scale and bias terms for this Node and its children * - * @param params pointer to the parameters vector - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode */ void initialize_params(double* params, const int depth = 1) const; /** * @brief Calculates the derivative of an operation with respect to the parameters for a given sample * - * @param params pointer to the parameters + * @param params A pointer to the bias and scale terms for this Node and its children * @param dfdp pointer to where the feature derivative pointers are located */ inline void param_derivative(const double* params, double* dfdp) const @@ -309,9 +304,9 @@ public: * * @param feat_list list of features already generated * @param feat feature to attempt to take the cube of - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. */ void generateCbNode( std::vector<node_ptr>& feat_list, diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cb/parameterized_cube.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cb/parameterized_cube.cpp index 2760a06cad72c5671aae808247b6701618b4d113..fd465f0a5126293dc91cfdfa19d99e058a244565 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cb/parameterized_cube.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cb/parameterized_cube.cpp @@ -187,7 +187,7 @@ void CbNode::set_test_value(const double* params, int offset, const bool for_com } allowed_op_funcs::cb( - _n_test_samp, + _n_samp_test, vp_0, params[0], params[1], diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cb/parameterized_cube.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cb/parameterized_cube.hpp index 1bf2287db58e22f039515730c04f048c8cde0214..ea095e25a6c4930bdd2dc625fe652f23db9b2de6 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cb/parameterized_cube.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cb/parameterized_cube.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/cb/parameterized_cube.hpp - * @brief Class describing the parameterized cube operator + * @brief Class describing the parameterized cube operator * * This class represents the parameterized unary operator -> (alpha * A + a)^3 * @@ -55,7 +55,7 @@ protected: using CbNode::get_latex_expr; using CbNode::matlab_fxn_expr; - std::vector<double> _params; //!< The parameters vector + std::vector<double> _params; //!< The vector containing the scale and bias terms for the Node public: /** @@ -65,14 +65,13 @@ public: CbParamNode(); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature * @param l_bound (double) Minimum absolute value allowed for the feature. * @param u_bound (double) Maximum absolute value allowed for the feature. - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ CbParamNode( const node_ptr feat, @@ -83,19 +82,17 @@ public: ); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ CbParamNode(const node_ptr feat, const unsigned long int feat_ind, std::shared_ptr<NLOptimizer> optimizer); // DocString: cb_param_node_init /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -105,8 +102,8 @@ public: CbParamNode(const node_ptr feat, const unsigned long int feat_ind, double const l_bound=1e-50, const double u_bound=1e50); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ node_ptr hard_copy()const; @@ -132,10 +129,10 @@ public: * @brief Get the pointer to the feature's training data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * - * @return pointer to the feature's test values + * @return A pointer to the feature's training data */ inline double* value_ptr(int offset=-1, const bool for_comp=false) const {return value_ptr(_params.data(), offset, for_comp);} @@ -143,7 +140,7 @@ public: * @brief Get the pointer to the feature's test data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * * @return pointer to the feature's test values @@ -176,15 +173,15 @@ public: inline std::string matlab_fxn_expr() const {return matlab_fxn_expr(_params.data());} /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ inline std::vector<double> parameters() const {return _params;} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ void get_parameters(std::shared_ptr<NLOptimizer> optimizer); @@ -205,7 +202,7 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ inline void set_parameters(const double* params) { @@ -229,9 +226,9 @@ public: * * @param feat_list list of features already generated * @param feat feature to attempt to take the cube of - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. * @param optimizer The optimizer used to find the parameters of the node */ void generateCbParamNode( diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cbrt/cube_root.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cbrt/cube_root.cpp index 241b68082a4721b32803d1d890eb3149b412f90d..7d31aec2339734ebb72fc5919268ecb968323af3 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cbrt/cube_root.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cbrt/cube_root.cpp @@ -149,7 +149,7 @@ void CbrtNode::set_test_value(int offset, const bool for_comp) const { offset += (offset == -1); allowed_op_funcs::cbrt( - _n_test_samp, + _n_samp_test, _feats[0]->test_value_ptr(2 * offset, for_comp), 1.0, 0.0, diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cbrt/cube_root.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cbrt/cube_root.hpp index 55f5a107314a835115da890dd3a3a26c6e525f3a..de6822569b0b763498538a17b7c58f548b607c5c 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cbrt/cube_root.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cbrt/cube_root.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/cube_root.hpp - * @brief Class describing the cube root operator + * @brief Class describing the cube root operator * * This class represents the unary operator -> (A)^(1/3) * @@ -52,8 +52,7 @@ public: CbrtNode(); /** - * @brief Constructor - * @details Constructs the Node from an array of features to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -62,8 +61,7 @@ public: // DocString: cbrt_node_init /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -73,8 +71,8 @@ public: CbrtNode(const node_ptr feat, const unsigned long int feat_ind, const double l_bound, const double u_bound); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ virtual node_ptr hard_copy()const; @@ -128,7 +126,7 @@ public: // DocString: cbrt_node_rung /** - * @brief return the rung of the feature (Height of the binary expression tree + 1) + * @brief return the rung of the feature (Height of the binary expression tree - 1) * */ inline int rung(const int cur_rung=0) const {return _feats[0]->rung(cur_rung + 1);} @@ -139,8 +137,7 @@ public: virtual inline NODE_TYPE type() const {return NODE_TYPE::CBRT;} /** - * @brief Get the string character representation of the node for the postfix expression - * @return the string representation of the node for the postfix expression + * @brief Get the term used in the postfix expression for this Node */ inline std::string get_postfix_term() const {return "cbrt";} @@ -168,26 +165,25 @@ public: void update_add_sub_leaves(std::map<std::string, int>& add_sub_leaves, const int pl_mn, int& expected_abs_tot) const; /** - * @brief update the dictionary used to check if a mult/div node is valid + * @brief update the dictionary used to check if an Mult/Div node is valid * * @param div_mult_leaves the dictionary used to check if an Mult/Div node is valid - * @param fact Factor used to update leaves (power of the feature) + * @param fact amount to increment the element (a primary features) of the dictionary by * @param expected_abs_tot The expected absolute sum of all values in div_mult_leaves - * */ void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, const double fact, double& expected_abs_tot) const; #ifdef PARAMETERIZE /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ virtual std::vector<double> parameters() const {return {};} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ virtual void get_parameters(std::shared_ptr<NLOptimizer> optimizer){return;} @@ -200,35 +196,35 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ virtual void set_parameters(const double* params){return;} /** * @brief Set the value of all training samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief Set the value of all test samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_test_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief A human readable equation representing the feature * - * @param params parameter values for non-linear operations - * @return feature expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @return A human readable equation representing the feature */ inline std::string expr(const double* params, const int depth=1) const { @@ -242,9 +238,9 @@ public: /** * @brief Get the valid LaTeX expression that represents the feature * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree - * @return the latexified expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode + * @return Get the valid LaTeX expression that represents the feature */ inline std::string get_latex_expr(const double* params, const int depth=1) const { @@ -258,8 +254,8 @@ public: /** * @brief Get the string that corresponds to the code needed to evaluate the node in matlab * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode * @return The matlab code for the feature */ inline std::string matlab_fxn_expr(const double* params, const int depth=1) const @@ -272,27 +268,26 @@ public: } /** - * @brief Set the bounds for the nl parameterization + * @brief Set the upper and lower bounds for the scale and bias term of this Node and its children * - * @param lb pointer to the lower bounds data - * @param ub pointer to the upper bounds data - * @param from_parent How many parameters are between the start of this node's parameters and its parent - * @param depth the current depth of the node on the binary expression tree + * @param lb A pointer to the location where the lower bounds for the scale and bias term of this Node is set + * @param ub A pointer to the location where the upper bounds for the scale and bias term of this Node is set + * @param depth How far down a given Node is from the root OperatorNode */ void set_bounds(double* lb, double* ub, const int depth=1) const; /** - * @brief Set the bounds for the nl parameterization + * @brief Initialize the scale and bias terms for this Node and its children * - * @param params pointer to the parameters vector - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode */ void initialize_params(double* params, const int depth = 1) const; /** * @brief Calculates the derivative of an operation with respect to the parameters for a given sample * - * @param params pointer to the parameters + * @param params A pointer to the bias and scale terms for this Node and its children * @param dfdp pointer to where the feature derivative pointers are located */ inline void param_derivative(const double* params, double* dfdp) const @@ -308,9 +303,9 @@ public: * * @param feat_list list of features already generated * @param feat feature to attempt to take the absolute value of - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. */ void generateCbrtNode( std::vector<node_ptr>& feat_list, diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cbrt/parameterized_cube_root.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cbrt/parameterized_cube_root.cpp index 753137f33f27850fd0c574134a0587e965a2a4cc..2841784d22dee0d6632bb91b25e43d5fb4e1f5d4 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cbrt/parameterized_cube_root.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cbrt/parameterized_cube_root.cpp @@ -173,7 +173,7 @@ void CbrtNode::set_test_value(const double* params, int offset, const bool for_c } allowed_op_funcs::cbrt( - _n_test_samp, + _n_samp_test, vp_0, params[0], params[1], diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cbrt/parameterized_cube_root.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cbrt/parameterized_cube_root.hpp index 23a0872d25f144bdf2978a7a83c4e9485d3d8bca..e1dfa283615a60cecc49671367231f58a8d315e3 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cbrt/parameterized_cube_root.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cbrt/parameterized_cube_root.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/cbrt/parameterized_cube_root.hpp - * @brief Class describing the parameterized cube root operator + * @brief Class describing the parameterized cube root operator * * This class represents the parameterized unary operator -> cbrt(alpha * A + a) * @@ -55,7 +55,7 @@ protected: using CbrtNode::get_latex_expr; using CbrtNode::matlab_fxn_expr; - std::vector<double> _params; //!< The parameters vector + std::vector<double> _params; //!< The vector containing the scale and bias terms for the Node public: /** * @brief Base Constructor @@ -64,14 +64,13 @@ public: CbrtParamNode(); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature * @param l_bound (double) Minimum absolute value allowed for the feature. * @param u_bound (double) Maximum absolute value allowed for the feature. - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ CbrtParamNode( const node_ptr feat, @@ -82,19 +81,17 @@ public: ); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ CbrtParamNode(const node_ptr feat, const unsigned long int feat_ind, std::shared_ptr<NLOptimizer> optimizer); // DocString: cbrt_param_node_init /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -104,8 +101,8 @@ public: CbrtParamNode(const node_ptr feat, const unsigned long int feat_ind, double const l_bound=1e-50, const double u_bound=1e50); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ node_ptr hard_copy()const; @@ -131,10 +128,10 @@ public: * @brief Get the pointer to the feature's training data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * - * @return pointer to the feature's test values + * @return A pointer to the feature's training data */ inline double* value_ptr(int offset=-1, const bool for_comp=false) const {return value_ptr(_params.data(), offset, for_comp);} @@ -142,7 +139,7 @@ public: * @brief Get the pointer to the feature's test data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * * @return pointer to the feature's test values @@ -175,15 +172,15 @@ public: inline std::string matlab_fxn_expr() const {return matlab_fxn_expr(_params.data());} /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ inline std::vector<double> parameters() const {return _params;} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ void get_parameters(std::shared_ptr<NLOptimizer> optimizer); @@ -204,7 +201,7 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ inline void set_parameters(const double* params) { @@ -228,9 +225,9 @@ public: * * @param feat_list list of features already generated * @param feat feature to attempt to take the absolute value of - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. * @param optimizer The optimizer used to find the parameters of the node */ void generateCbrtParamNode( diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cos/cos.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cos/cos.cpp index 3e6357b49fa33b7c500c0a3059005e9273713c62..81d1dff2b5506937312581ce72d4b42b23908e78 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cos/cos.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cos/cos.cpp @@ -144,7 +144,7 @@ void CosNode::set_test_value(int offset, const bool for_comp) const { offset += (offset == -1); allowed_op_funcs::cos( - _n_test_samp, + _n_samp_test, _feats[0]->test_value_ptr(2 * offset, for_comp), 1.0, 0.0, diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cos/cos.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cos/cos.hpp index c21ccd18337e9211f56e0fdcb6974dad2bd5e7bc..63a18150a00085a54ad3880c2fe919f07a0c5bc4 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cos/cos.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cos/cos.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/cos.hpp - * @brief Class describing the cosine operator + * @brief Class describing the cosine operator * * This class represents the unary operator -> cos(A) * @@ -52,8 +52,7 @@ public: CosNode(); /** - * @brief Constructor - * @details Constructs the Node from an array of features to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -62,8 +61,7 @@ public: // DocString: cos_node_init /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -73,8 +71,8 @@ public: CosNode(const node_ptr feat, const unsigned long int feat_ind, const double l_bound, const double u_bound); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ virtual node_ptr hard_copy()const; @@ -128,7 +126,7 @@ public: // DocString: cos_node_rung /** - * @brief return the rung of the feature (Height of the binary expression tree + 1) + * @brief return the rung of the feature (Height of the binary expression tree - 1) * */ inline int rung(const int cur_rung=0) const {return _feats[0]->rung(cur_rung + 1);} @@ -139,8 +137,7 @@ public: virtual inline NODE_TYPE type() const {return NODE_TYPE::COS;} /** - * @brief Get the string character representation of the node for the postfix expression - * @return the string representation of the node for the postfix expression + * @brief Get the term used in the postfix expression for this Node */ inline std::string get_postfix_term() const {return "cos";} @@ -159,35 +156,34 @@ public: } /** - * @brief update the dictionary used to check if an Add/Sub node is valid + * @brief update the dictionary used to check if an Add/Sub/AbsDiff node is valid * * @param add_sub_leaves the dictionary used to check if an Add/Sub node is valid - * @param pl_mn if for an addition node: 1 if for a subtraction node: -1 + * @param pl_mn 1 for addition and -1 for subtraction * @param expected_abs_tot The expected absolute sum of all values in add_sub_leaves */ void update_add_sub_leaves(std::map<std::string, int>& add_sub_leaves, const int pl_mn, int& expected_abs_tot) const; /** - * @brief update the dictionary used to check if a mult/div node is valid + * @brief update the dictionary used to check if an Mult/Div node is valid * * @param div_mult_leaves the dictionary used to check if an Mult/Div node is valid - * @param fact Factor used to update leaves (power of the feature) + * @param fact amount to increment the element (a primary features) of the dictionary by * @param expected_abs_tot The expected absolute sum of all values in div_mult_leaves - * */ void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, const double fact, double& expected_abs_tot) const; #ifdef PARAMETERIZE /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ virtual std::vector<double> parameters() const {return {};} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ virtual void get_parameters(std::shared_ptr<NLOptimizer> optimizer){return;} @@ -200,35 +196,35 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ virtual void set_parameters(const double* params){return;} /** * @brief Set the value of all training samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief Set the value of all test samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_test_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief A human readable equation representing the feature * - * @param params parameter values for non-linear operations - * @return feature expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @return A human readable equation representing the feature */ inline std::string expr(const double* params, const int depth=1) const { @@ -243,9 +239,9 @@ public: /** * @brief Get the valid LaTeX expression that represents the feature * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree - * @return the latexified expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode + * @return Get the valid LaTeX expression that represents the feature */ inline std::string get_latex_expr(const double* params, const int depth=1) const { @@ -260,8 +256,8 @@ public: /** * @brief Get the string that corresponds to the code needed to evaluate the node in matlab * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode * @return The matlab code for the feature */ inline std::string matlab_fxn_expr(const double* params, const int depth=1) const @@ -275,27 +271,26 @@ public: } /** - * @brief Set the bounds for the nl parameterization + * @brief Set the upper and lower bounds for the scale and bias term of this Node and its children * - * @param lb pointer to the lower bounds data - * @param ub pointer to the upper bounds data - * @param from_parent How many parameters are between the start of this node's parameters and its parent - * @param depth the current depth of the node on the binary expression tree + * @param lb A pointer to the location where the lower bounds for the scale and bias term of this Node is set + * @param ub A pointer to the location where the upper bounds for the scale and bias term of this Node is set + * @param depth How far down a given Node is from the root OperatorNode */ void set_bounds(double* lb, double* ub, const int depth=1) const; /** - * @brief Set the bounds for the nl parameterization + * @brief Initialize the scale and bias terms for this Node and its children * - * @param params pointer to the parameters vector - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode */ void initialize_params(double* params, const int depth = 1) const; /** * @brief Calculates the derivative of an operation with respect to the parameters for a given sample * - * @param params pointer to the parameters + * @param params A pointer to the bias and scale terms for this Node and its children * @param dfdp pointer to where the feature derivative pointers are located */ inline void param_derivative(const double* params, double* dfdp) const @@ -310,10 +305,10 @@ public: * @brief Attempt to generate a new parameterized cosine node cos(A) and add it to feat_list * * @param feat_list list of features already generated - * @param feat feature to attempt to take the cosine of - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat shared_ptr of the feature to operate on (A) + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. */ void generateCosNode( std::vector<node_ptr>& feat_list, diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cos/parameterized_cos.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cos/parameterized_cos.cpp index 1f3845bb1b129e43cb65495f056439cbbb0865d8..b7a51e4cc1a27cff1618003685fe0094e1647c28 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cos/parameterized_cos.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cos/parameterized_cos.cpp @@ -173,7 +173,7 @@ void CosNode::set_test_value(const double* params, int offset, const bool for_co } allowed_op_funcs::cos( - _n_test_samp, + _n_samp_test, vp_0, params[0], params[1], diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cos/parameterized_cos.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cos/parameterized_cos.hpp index 94ef25f352987a4307d4dd460e708f4574c2bbd6..aa5fe2b020bdc0d56f886281a0310329f9f21ee1 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cos/parameterized_cos.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cos/parameterized_cos.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/cos/parameterized_cos.hpp - * @brief Class describing the parameterized cos operator + * @brief Class describing the parameterized cos operator * * This class represents the parameterized unary operator -> cos(alpha * A + a) * @@ -55,7 +55,7 @@ protected: using CosNode::get_latex_expr; using CosNode::matlab_fxn_expr; - std::vector<double> _params; //!< The parameters vector + std::vector<double> _params; //!< The vector containing the scale and bias terms for the Node public: /** @@ -65,14 +65,13 @@ public: CosParamNode(); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature * @param l_bound (double) Minimum absolute value allowed for the feature. * @param u_bound (double) Maximum absolute value allowed for the feature. - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ CosParamNode( const node_ptr feat, @@ -83,19 +82,17 @@ public: ); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ CosParamNode(const node_ptr feat, const unsigned long int feat_ind, std::shared_ptr<NLOptimizer> optimizer); // DocString: cos_param_node_init /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -105,8 +102,8 @@ public: CosParamNode(const node_ptr feat, const unsigned long int feat_ind, double const l_bound=1e-50, const double u_bound=1e50); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ node_ptr hard_copy()const; @@ -132,10 +129,10 @@ public: * @brief Get the pointer to the feature's training data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * - * @return pointer to the feature's test values + * @return A pointer to the feature's training data */ inline double* value_ptr(int offset=-1, const bool for_comp=false) const {return value_ptr(_params.data(), offset, for_comp);} @@ -143,7 +140,7 @@ public: * @brief Get the pointer to the feature's test data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * * @return pointer to the feature's test values @@ -176,15 +173,15 @@ public: inline std::string matlab_fxn_expr() const {return matlab_fxn_expr(_params.data());} /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ inline std::vector<double> parameters() const {return _params;} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ void get_parameters(std::shared_ptr<NLOptimizer> optimizer); @@ -205,7 +202,7 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ inline void set_parameters(const double* params) { @@ -228,10 +225,10 @@ public: * @brief Attempt to generate a new parameterized cosine node cos(\alpha A + a) and add it to feat_list * * @param feat_list list of features already generated - * @param feat feature to attempt to take the cosine of - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat shared_ptr of the feature to operate on (A) + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. * @param optimizer The optimizer used to find the parameters of the node */ void generateCosParamNode( diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/div/divide.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/div/divide.cpp index cbcca7e97e6e73300bd88def0dff64de5486335b..013d9eadb3bf7389ce4610abc43c4b9818fe3c57 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/div/divide.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/div/divide.cpp @@ -191,7 +191,7 @@ void DivNode::set_test_value(int offset, const bool for_comp) const { offset += (offset == -1); allowed_op_funcs::div( - _n_test_samp, + _n_samp_test, _feats[0]->test_value_ptr(2 * offset, for_comp), _feats[1]->test_value_ptr(2 * offset + 1, for_comp), 1.0, diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/div/divide.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/div/divide.hpp index 7732e64842df3af02fae0d4086c4f3b6a4878af4..7d819ba1efe530a2c39285e5c15b4a030adc7be9 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/div/divide.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/div/divide.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/divide.hpp - * @brief Class describing the division operator + * @brief Class describing the division operator * * This class represents the binary operator -> A / B * @@ -52,8 +52,7 @@ public: DivNode(); /** - * @brief Constructor - * @details Constructs the Node from an array of features to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * * @param feat_1 (Node) shared_ptr of the first feature to operate on (A) * @param feat_2 (Node) shared_ptr of the second feature to operate on (B) @@ -75,8 +74,8 @@ public: DivNode(const node_ptr feat_1, const node_ptr feat_2, const unsigned long int feat_ind, const double l_bound, const double u_bound); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ virtual node_ptr hard_copy()const; @@ -132,7 +131,7 @@ public: // DocString: div_node_rung /** - * @brief return the rung of the feature (Height of the binary expression tree + 1) + * @brief return the rung of the feature (Height of the binary expression tree - 1) * */ inline int rung(const int cur_rung=0) const {return std::max(_feats[0]->rung(cur_rung + 1), _feats[1]->rung(cur_rung + 1));} @@ -143,8 +142,7 @@ public: virtual inline NODE_TYPE type() const {return NODE_TYPE::DIV;} /** - * @brief Get the string character representation of the node for the postfix expression - * @return the string representation of the node for the postfix expression + * @brief Get the term used in the postfix expression for this Node */ inline std::string get_postfix_term() const {return "div";} @@ -170,35 +168,34 @@ public: void check_feats(); /** - * @brief update the dictionary used to check if an Add/Sub node is valid + * @brief update the dictionary used to check if an Add/Sub/AbsDiff node is valid * * @param add_sub_leaves the dictionary used to check if an Add/Sub node is valid - * @param pl_mn if for an addition node: 1 if for a subtraction node: -1 + * @param pl_mn 1 for addition and -1 for subtraction * @param expected_abs_tot The expected absolute sum of all values in add_sub_leaves */ void update_add_sub_leaves(std::map<std::string, int>& add_sub_leaves, const int pl_mn, int& expected_abs_tot) const; /** - * @brief update the dictionary used to check if a mult/div node is valid + * @brief update the dictionary used to check if an Mult/Div node is valid * * @param div_mult_leaves the dictionary used to check if an Mult/Div node is valid - * @param fact Factor used to update leaves (power of the feature) + * @param fact amount to increment the element (a primary features) of the dictionary by * @param expected_abs_tot The expected absolute sum of all values in div_mult_leaves - * */ void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, const double fact, double& expected_abs_tot) const; #ifdef PARAMETERIZE /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ virtual std::vector<double> parameters() const {return {};} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ virtual void get_parameters(std::shared_ptr<NLOptimizer> optimizer){return;} @@ -211,36 +208,36 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ virtual void set_parameters(const double* params){return;} /** * @brief Set the value of all training samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief Set the value of all test samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_test_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief A human readable equation representing the feature * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree - * @return feature expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode + * @return A human readable equation representing the feature */ inline std::string expr(const double* params, const int depth=1) const { @@ -255,9 +252,9 @@ public: /** * @brief Get the valid LaTeX expression that represents the feature * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree - * @return the latexified expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode + * @return Get the valid LaTeX expression that represents the feature */ inline std::string get_latex_expr(const double* params, const int depth=1) const { @@ -272,8 +269,8 @@ public: /** * @brief Get the string that corresponds to the code needed to evaluate the node in matlab * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode * @return The matlab code for the feature */ inline std::string matlab_fxn_expr(const double* params, const int depth=1) const @@ -287,27 +284,26 @@ public: } /** - * @brief Set the bounds for the nl parameterization + * @brief Set the upper and lower bounds for the scale and bias term of this Node and its children * - * @param lb pointer to the lower bounds data - * @param ub pointer to the upper bounds data - * @param from_parent How many parameters are between the start of this node's parameters and its parent - * @param depth the current depth of the node on the binary expression tree + * @param lb A pointer to the location where the lower bounds for the scale and bias term of this Node is set + * @param ub A pointer to the location where the upper bounds for the scale and bias term of this Node is set + * @param depth How far down a given Node is from the root OperatorNode */ void set_bounds(double* lb, double* ub, const int depth=1) const; /** - * @brief Set the bounds for the nl parameterization + * @brief Initialize the scale and bias terms for this Node and its children * - * @param params pointer to the parameters vector - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode */ void initialize_params(double* params, const int depth = 1) const; /** * @brief Calculates the derivative of an operation with respect to the parameters for a given sample * - * @param params pointer to the parameters + * @param params A pointer to the bias and scale terms for this Node and its children * @param dfdp pointer to where the feature derivative pointers are located */ inline void param_derivative(const double* params, double* dfdp) const @@ -331,9 +327,9 @@ public: * @param feat_list list of features already generated * @param feat_1 The (A) feature * @param feat_2 The (B) feature - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. */ void generateDivNode(std::vector<node_ptr>& feat_list, const node_ptr feat_1, const node_ptr feat_2, unsigned long int& feat_ind, const double l_bound, const double u_bound); diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/div/parameterized_divide.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/div/parameterized_divide.cpp index 59de9952d39b683b2018ac700ea6e0ac74e7147f..67911e01ac03170762a18e6c7ccc70653902ca33 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/div/parameterized_divide.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/div/parameterized_divide.cpp @@ -199,7 +199,7 @@ void DivNode::set_test_value(const double* params, int offset, const bool for_co vp_1 = _feats[1]->test_value_ptr(2 * offset + 1, for_comp); } allowed_op_funcs::div( - _n_test_samp, + _n_samp_test, vp_0, vp_1, params[0], diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/div/parameterized_divide.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/div/parameterized_divide.hpp index 0636915e7d84810920a4be7187c580df0766a011..3953d9220f7609bf60051092e63e8862ca46b45c 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/div/parameterized_divide.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/div/parameterized_divide.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/div/parameterized_divide.hpp - * @brief Class describing the parameterized addition operator + * @brief Class describing the parameterized addition operator * * This class represents the parameterized unary operator -> A / (alpha * B + a) * @@ -65,15 +65,14 @@ public: DivParamNode(); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * - * @param feat_1 shared_ptr of the feature to operate on (A) - * @param feat_2 shared_ptr of the feature to operate on (B) + * @param feat_1 (Node) shared_ptr of the feature to operate on (A) + * @param feat_2 (Node) shared_ptr of the feature to operate on (B) * @param feat_ind (int) Index of the new feature * @param l_bound (double) Minimum absolute value allowed for the feature. * @param u_bound (double) Maximum absolute value allowed for the feature. - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ DivParamNode( const node_ptr feat_1, @@ -85,20 +84,18 @@ public: ); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * - * @param feat_1 shared_ptr of the feature to operate on (A) - * @param feat_2 shared_ptr of the feature to operate on (B) + * @param feat_1 (Node) shared_ptr of the feature to operate on (A) + * @param feat_2 (Node) shared_ptr of the feature to operate on (B) * @param feat_ind (int) Index of the new feature - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ DivParamNode(const node_ptr feat_1, const node_ptr feat_2, const unsigned long int feat_ind, std::shared_ptr<NLOptimizer> optimizer); // DocString: div_param_node_init /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -108,8 +105,8 @@ public: DivParamNode(const node_ptr feat_1, const node_ptr feat_2, const unsigned long int feat_ind, double const l_bound=1e-50, const double u_bound=1e50); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ node_ptr hard_copy()const; @@ -135,10 +132,10 @@ public: * @brief Get the pointer to the feature's training data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * - * @return pointer to the feature's test values + * @return A pointer to the feature's training data */ inline double* value_ptr(int offset=-1, const bool for_comp=false) const {return value_ptr(_params.data(), offset, for_comp);} @@ -146,7 +143,7 @@ public: * @brief Get the pointer to the feature's test data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * * @return pointer to the feature's test values @@ -179,15 +176,15 @@ public: inline std::string matlab_fxn_expr() const {return matlab_fxn_expr(_params.data());} /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ inline std::vector<double> parameters() const {return _params;} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ void get_parameters(std::shared_ptr<NLOptimizer> optimizer); @@ -208,7 +205,7 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ inline void set_parameters(const double* params) { @@ -233,9 +230,9 @@ public: * @param feat_list list of features already generated * @param feat_1 The (A) feature * @param feat_2 The (B) feature - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. * @param optimizer The optimizer used to find the parameters of the node */ void generateDivParamNode( diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/exp/exponential.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/exp/exponential.cpp index ce0b644f3db905db7616f22ac2f5cc715e4393ea..8d39be61664d688d0567eb6562599a4e9fbaca39 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/exp/exponential.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/exp/exponential.cpp @@ -156,7 +156,7 @@ void ExpNode::set_test_value(int offset, const bool for_comp) const { offset += (offset == -1); allowed_op_funcs::exp( - _n_test_samp, + _n_samp_test, _feats[0]->test_value_ptr(2 * offset, for_comp), 1.0, 0.0, diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/exp/exponential.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/exp/exponential.hpp index c6510d21125bdd8c425d6ba9269a52449af2edf5..d0041b89599cde342f67c6ceb9badfd0bcfdea1c 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/exp/exponential.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/exp/exponential.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/exponential.hpp - * @brief Class describing the exponential operator + * @brief Class describing the exponential operator * * This class represents the unary operator -> exp(A) * @@ -52,8 +52,7 @@ public: ExpNode(); /** - * @brief Constructor - * @details Constructs the Node from an array of features to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -62,8 +61,7 @@ public: // DocString: exp_node_init /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -73,8 +71,8 @@ public: ExpNode(const node_ptr feat, const unsigned long int feat_ind, const double l_bound, const double u_bound); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ virtual node_ptr hard_copy()const; @@ -128,7 +126,7 @@ public: // DocString: exp_node_rung /** - * @brief return the rung of the feature (Height of the binary expression tree + 1) + * @brief return the rung of the feature (Height of the binary expression tree - 1) * */ inline int rung(const int cur_rung=0) const {return _feats[0]->rung(cur_rung + 1);} @@ -139,8 +137,7 @@ public: virtual inline NODE_TYPE type() const {return NODE_TYPE::EXP;} /** - * @brief Get the string character representation of the node for the postfix expression - * @return the string representation of the node for the postfix expression + * @brief Get the term used in the postfix expression for this Node */ inline std::string get_postfix_term() const {return "exp";} @@ -159,35 +156,34 @@ public: } /** - * @brief update the dictionary used to check if an Add/Sub node is valid + * @brief update the dictionary used to check if an Add/Sub/AbsDiff node is valid * * @param add_sub_leaves the dictionary used to check if an Add/Sub node is valid - * @param pl_mn if for an addition node: 1 if for a subtraction node: -1 + * @param pl_mn 1 for addition and -1 for subtraction * @param expected_abs_tot The expected absolute sum of all values in add_sub_leaves */ void update_add_sub_leaves(std::map<std::string, int>& add_sub_leaves, const int pl_mn, int& expected_abs_tot) const; /** - * @brief update the dictionary used to check if a mult/div node is valid + * @brief update the dictionary used to check if an Mult/Div node is valid * * @param div_mult_leaves the dictionary used to check if an Mult/Div node is valid - * @param fact Factor used to update leaves (power of the feature) + * @param fact amount to increment the element (a primary features) of the dictionary by * @param expected_abs_tot The expected absolute sum of all values in div_mult_leaves - * */ void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, const double fact, double& expected_abs_tot) const; #ifdef PARAMETERIZE /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ virtual std::vector<double> parameters() const {return {};} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ virtual void get_parameters(std::shared_ptr<NLOptimizer> optimizer){return;} @@ -200,35 +196,35 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ virtual void set_parameters(const double* params){return;} /** * @brief Set the value of all training samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief Set the value of all test samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_test_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief A human readable equation representing the feature * - * @param params parameter values for non-linear operations - * @return feature expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @return A human readable equation representing the feature */ inline std::string expr(const double* params, const int depth=1) const { @@ -242,9 +238,9 @@ public: /** * @brief Get the valid LaTeX expression that represents the feature * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree - * @return the latexified expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode + * @return Get the valid LaTeX expression that represents the feature */ inline std::string get_latex_expr(const double* params, const int depth=1) const { @@ -258,8 +254,8 @@ public: /** * @brief Get the string that corresponds to the code needed to evaluate the node in matlab * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode * @return The matlab code for the feature */ inline std::string matlab_fxn_expr(const double* params, const int depth=1) const @@ -272,27 +268,26 @@ public: } /** - * @brief Set the bounds for the nl parameterization + * @brief Set the upper and lower bounds for the scale and bias term of this Node and its children * - * @param lb pointer to the lower bounds data - * @param ub pointer to the upper bounds data - * @param from_parent How many parameters are between the start of this node's parameters and its parent - * @param depth the current depth of the node on the binary expression tree + * @param lb A pointer to the location where the lower bounds for the scale and bias term of this Node is set + * @param ub A pointer to the location where the upper bounds for the scale and bias term of this Node is set + * @param depth How far down a given Node is from the root OperatorNode */ void set_bounds(double* lb, double* ub, const int depth=1) const; /** - * @brief Set the bounds for the nl parameterization + * @brief Initialize the scale and bias terms for this Node and its children * - * @param params pointer to the parameters vector - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode */ void initialize_params(double* params, const int depth = 1) const; /** * @brief Calculates the derivative of an operation with respect to the parameters for a given sample * - * @param params pointer to the parameters + * @param params A pointer to the bias and scale terms for this Node and its children * @param dfdp pointer to where the feature derivative pointers are located */ inline void param_derivative(const double* params, double* dfdp) const @@ -309,9 +304,9 @@ public: * * @param feat_list list of features already generated * @param feat feature to attempt to take the exponential of - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. */ void generateExpNode( std::vector<node_ptr>& feat_list, diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/exp/parameterized_exponential.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/exp/parameterized_exponential.cpp index 3d06b727b1f9fa5ad62a907b379c76d15afd2c50..a0a0e3a26990f355ef702ccaf27648da7e2ecf5e 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/exp/parameterized_exponential.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/exp/parameterized_exponential.cpp @@ -185,7 +185,7 @@ void ExpNode::set_test_value(const double* params, int offset, const bool for_co } allowed_op_funcs::exp( - _n_test_samp, + _n_samp_test, vp_0, params[0], params[1], diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/exp/parameterized_exponential.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/exp/parameterized_exponential.hpp index 14a0de44f38cd99eff8aa8fae5405aeee75fa11c..f0f97602aa430059d1c051191f7c7cf22c82a75c 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/exp/parameterized_exponential.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/exp/parameterized_exponential.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/exp/parameterized_exponetial.hpp - * @brief Class describing the parameterized exp operator + * @brief Class describing the parameterized exp operator * * This class represents the parameterized unary operator -> exp(alpha * A + a) * @@ -55,7 +55,7 @@ protected: using ExpNode::get_latex_expr; using ExpNode::matlab_fxn_expr; - std::vector<double> _params; //!< The parameters vector + std::vector<double> _params; //!< The vector containing the scale and bias terms for the Node public: /** @@ -65,14 +65,13 @@ public: ExpParamNode(); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature * @param l_bound (double) Minimum absolute value allowed for the feature. * @param u_bound (double) Maximum absolute value allowed for the feature. - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ ExpParamNode( const node_ptr feat, @@ -83,18 +82,16 @@ public: ); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ ExpParamNode(const node_ptr feat, const unsigned long int feat_ind, std::shared_ptr<NLOptimizer> optimizer); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -104,8 +101,8 @@ public: ExpParamNode(const node_ptr feat, const unsigned long int feat_ind, double const l_bound=1e-50, const double u_bound=1e50); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ node_ptr hard_copy()const; @@ -131,10 +128,10 @@ public: * @brief Get the pointer to the feature's training data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * - * @return pointer to the feature's test values + * @return A pointer to the feature's training data */ inline double* value_ptr(int offset=-1, const bool for_comp=false) const {return value_ptr(_params.data(), offset, for_comp);} @@ -142,7 +139,7 @@ public: * @brief Get the pointer to the feature's test data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * * @return pointer to the feature's test values @@ -175,15 +172,15 @@ public: inline std::string matlab_fxn_expr() const {return matlab_fxn_expr(_params.data());} /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ inline std::vector<double> parameters() const {return _params;} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ void get_parameters(std::shared_ptr<NLOptimizer> optimizer); @@ -204,7 +201,7 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ inline void set_parameters(const double* params) { @@ -228,9 +225,9 @@ public: * * @param feat_list list of features already generated * @param feat feature to attempt to take the exponential of - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. * @param optimizer The optimizer used to find the parameters of the node */ void generateExpParamNode( diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/inv/inverse.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/inv/inverse.cpp index 95d2eb616384334a5aee1b1c80383f08269daa5c..dd759485618d99425acfe0e8485bc68604490755 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/inv/inverse.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/inv/inverse.cpp @@ -139,7 +139,7 @@ void InvNode::set_test_value(int offset, const bool for_comp) const { offset += (offset == -1); allowed_op_funcs::inv( - _n_test_samp, + _n_samp_test, _feats[0]->test_value_ptr(2 * offset, for_comp), 1.0, 0.0, diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/inv/inverse.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/inv/inverse.hpp index 6d153776c63421046ec716188351e3495ea464fe..6ad2945db76adf07df4b2483521c7f0deec28cef 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/inv/inverse.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/inv/inverse.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/inverse.hpp - * @brief Class describing the logarithm operator + * @brief Class describing the logarithm operator * * This class represents the unary operator -> 1 / A * @@ -48,8 +48,7 @@ public: InvNode(); /** - * @brief Constructor - * @details Constructs the Node from an array of features to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -69,8 +68,8 @@ public: InvNode(const node_ptr feat, const unsigned long int feat_ind, const double l_bound, const double u_bound); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ virtual node_ptr hard_copy()const; @@ -124,7 +123,7 @@ public: // DocString: inv_node_rung /** - * @brief return the rung of the feature (Height of the binary expression tree + 1) + * @brief return the rung of the feature (Height of the binary expression tree - 1) * */ inline int rung(const int cur_rung=0) const {return _feats[0]->rung(cur_rung + 1);} @@ -135,8 +134,7 @@ public: virtual inline NODE_TYPE type() const {return NODE_TYPE::INV;} /** - * @brief Get the string character representation of the node for the postfix expression - * @return the string representation of the node for the postfix expression + * @brief Get the term used in the postfix expression for this Node */ inline std::string get_postfix_term() const {return "inv";} @@ -155,35 +153,34 @@ public: } /** - * @brief update the dictionary used to check if an Add/Sub node is valid + * @brief update the dictionary used to check if an Add/Sub/AbsDiff node is valid * * @param add_sub_leaves the dictionary used to check if an Add/Sub node is valid - * @param pl_mn if for an addition node: 1 if for a subtraction node: -1 + * @param pl_mn 1 for addition and -1 for subtraction * @param expected_abs_tot The expected absolute sum of all values in add_sub_leaves */ void update_add_sub_leaves(std::map<std::string, int>& add_sub_leaves, const int pl_mn, int& expected_abs_tot) const; /** - * @brief update the dictionary used to check if a mult/div node is valid + * @brief update the dictionary used to check if an Mult/Div node is valid * * @param div_mult_leaves the dictionary used to check if an Mult/Div node is valid - * @param fact Factor used to update leaves (power of the feature) + * @param fact amount to increment the element (a primary features) of the dictionary by * @param expected_abs_tot The expected absolute sum of all values in div_mult_leaves - * */ void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, const double fact, double& expected_abs_tot) const; #ifdef PARAMETERIZE /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ virtual std::vector<double> parameters() const {return {};} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ virtual void get_parameters(std::shared_ptr<NLOptimizer> optimizer){return;} @@ -196,35 +193,35 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ virtual void set_parameters(const double* params){return;} /** * @brief Set the value of all training samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief Set the value of all test samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_test_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief A human readable equation representing the feature * - * @param params parameter values for non-linear operations - * @return feature expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @return A human readable equation representing the feature */ inline std::string expr(const double* params, const int depth=1) const { @@ -238,9 +235,9 @@ public: /** * @brief Get the valid LaTeX expression that represents the feature * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree - * @return the latexified expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode + * @return Get the valid LaTeX expression that represents the feature */ inline std::string get_latex_expr(const double* params, const int depth=1) const { @@ -254,8 +251,8 @@ public: /** * @brief Get the string that corresponds to the code needed to evaluate the node in matlab * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode * @return The matlab code for the feature */ inline std::string matlab_fxn_expr(const double* params, const int depth=1) const @@ -268,27 +265,26 @@ public: } /** - * @brief Set the bounds for the nl parameterization + * @brief Set the upper and lower bounds for the scale and bias term of this Node and its children * - * @param lb pointer to the lower bounds data - * @param ub pointer to the upper bounds data - * @param from_parent How many parameters are between the start of this node's parameters and its parent - * @param depth the current depth of the node on the binary expression tree + * @param lb A pointer to the location where the lower bounds for the scale and bias term of this Node is set + * @param ub A pointer to the location where the upper bounds for the scale and bias term of this Node is set + * @param depth How far down a given Node is from the root OperatorNode */ void set_bounds(double* lb, double* ub, const int depth=1) const; /** - * @brief Set the bounds for the nl parameterization + * @brief Initialize the scale and bias terms for this Node and its children * - * @param params pointer to the parameters vector - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode */ void initialize_params(double* params, const int depth = 1) const; /** * @brief Calculates the derivative of an operation with respect to the parameters for a given sample * - * @param params pointer to the parameters + * @param params A pointer to the bias and scale terms for this Node and its children * @param dfdp pointer to where the feature derivative pointers are located */ inline void param_derivative(const double* params, double* dfdp) const @@ -304,9 +300,9 @@ public: * * @param feat_list list of features already generated * @param feat feature to attempt to take the inverse of - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. */ void generateInvNode( std::vector<node_ptr>& feat_list, diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/inv/parameterized_inverse.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/inv/parameterized_inverse.cpp index c29dbc4b82261654507d0602fc156d3322702850..8356c716262e52784a4c08492e4324974a15de9f 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/inv/parameterized_inverse.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/inv/parameterized_inverse.cpp @@ -180,7 +180,7 @@ void InvNode::set_test_value(const double* params, int offset, const bool for_co vp_0 = _feats[0]->test_value_ptr(2 * offset, for_comp); } - allowed_op_funcs::inv(_n_test_samp, vp_0, params[0], params[1], node_value_arrs::access_param_storage_test(rung(), offset, for_comp)); + allowed_op_funcs::inv(_n_samp_test, vp_0, params[0], params[1], node_value_arrs::access_param_storage_test(rung(), offset, for_comp)); } void InvNode::set_bounds(double* lb, double* ub, const int depth) const diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/inv/parameterized_inverse.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/inv/parameterized_inverse.hpp index 623f2187ee39599fc023b19327c5843b7407d17e..1d56bf4be89f11cbb044fa7386da5a249a333f39 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/inv/parameterized_inverse.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/inv/parameterized_inverse.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/inv/parameterized_inverse.hpp - * @brief Class describing the parameterized inverse operator + * @brief Class describing the parameterized inverse operator * * This class represents the parameterized unary operator -> 1.0 / (alpha * A + a) * @@ -55,7 +55,7 @@ protected: using InvNode::get_latex_expr; using InvNode::matlab_fxn_expr; - std::vector<double> _params; //!< The parameters vector + std::vector<double> _params; //!< The vector containing the scale and bias terms for the Node public: /** @@ -65,14 +65,13 @@ public: InvParamNode(); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature * @param l_bound (double) Minimum absolute value allowed for the feature. * @param u_bound (double) Maximum absolute value allowed for the feature. - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ InvParamNode( const node_ptr feat, @@ -83,19 +82,17 @@ public: ); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ InvParamNode(const node_ptr feat, const unsigned long int feat_ind, std::shared_ptr<NLOptimizer> optimizer); // DocString: inv_param_node_init /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -105,8 +102,8 @@ public: InvParamNode(const node_ptr feat, const unsigned long int feat_ind, double const l_bound=1e-50, const double u_bound=1e50); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ node_ptr hard_copy()const; @@ -132,10 +129,10 @@ public: * @brief Get the pointer to the feature's training data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * - * @return pointer to the feature's test values + * @return A pointer to the feature's training data */ inline double* value_ptr(int offset=-1, const bool for_comp=false) const {return value_ptr(_params.data(), offset, for_comp);} @@ -143,7 +140,7 @@ public: * @brief Get the pointer to the feature's test data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * * @return pointer to the feature's test values @@ -176,15 +173,15 @@ public: inline std::string matlab_fxn_expr() const {return matlab_fxn_expr(_params.data());} /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ inline std::vector<double> parameters() const {return _params;} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ void get_parameters(std::shared_ptr<NLOptimizer> optimizer); @@ -205,7 +202,7 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ inline void set_parameters(const double* params) { @@ -229,9 +226,9 @@ public: * * @param feat_list list of features already generated * @param feat feature to attempt to take the inverse of - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. * @param optimizer The optimizer used to find the parameters of the node */ void generateInvParamNode( diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/log/log.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/log/log.cpp index f6145a038eed9c0c328d77783717932cbd950eab..39b031f33eed54c5ac7dcc6bca594785e1a8da9b 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/log/log.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/log/log.cpp @@ -181,7 +181,7 @@ void LogNode::set_test_value(int offset, const bool for_comp) const { offset += (offset == -1); allowed_op_funcs::log( - _n_test_samp, + _n_samp_test, _feats[0]->test_value_ptr(2 * offset, for_comp), 1.0, 0.0, diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/log/log.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/log/log.hpp index 0fcba49018320c4c1f602897bbcd3a76eb0faee6..76a066bbc52b1417c234484cb67251e19f94c7ff 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/log/log.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/log/log.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/log.hpp - * @brief Class describing the logarithm operator + * @brief Class describing the logarithm operator * * This class represents the unary operator -> log(A) * @@ -52,8 +52,7 @@ public: LogNode(); /** - * @brief Constructor - * @details Constructs the Node from an array of features to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -62,8 +61,7 @@ public: // DocString: log_node_init /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -73,8 +71,8 @@ public: LogNode(const node_ptr feat, const unsigned long int feat_ind, const double l_bound, const double u_bound); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ virtual node_ptr hard_copy()const; @@ -119,7 +117,7 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ virtual void set_parameters(const double* params){return;} @@ -134,7 +132,7 @@ public: // DocString: log_node_rung /** - * @brief return the rung of the feature (Height of the binary expression tree + 1) + * @brief return the rung of the feature (Height of the binary expression tree - 1) * */ inline int rung(const int cur_rung=0) const {return _feats[0]->rung(cur_rung + 1);} @@ -145,8 +143,7 @@ public: virtual inline NODE_TYPE type() const {return NODE_TYPE::LOG;} /** - * @brief Get the string character representation of the node for the postfix expression - * @return the string representation of the node for the postfix expression + * @brief Get the term used in the postfix expression for this Node */ inline std::string get_postfix_term() const {return "log";} @@ -165,35 +162,34 @@ public: } /** - * @brief update the dictionary used to check if an Add/Sub node is valid + * @brief update the dictionary used to check if an Add/Sub/AbsDiff node is valid * * @param add_sub_leaves the dictionary used to check if an Add/Sub node is valid - * @param pl_mn if for an addition node: 1 if for a subtraction node: -1 + * @param pl_mn 1 for addition and -1 for subtraction * @param expected_abs_tot The expected absolute sum of all values in add_sub_leaves */ void update_add_sub_leaves(std::map<std::string, int>& add_sub_leaves, const int pl_mn, int& expected_abs_tot) const; /** - * @brief update the dictionary used to check if a mult/div node is valid + * @brief update the dictionary used to check if an Mult/Div node is valid * * @param div_mult_leaves the dictionary used to check if an Mult/Div node is valid - * @param fact Factor used to update leaves (power of the feature) + * @param fact amount to increment the element (a primary features) of the dictionary by * @param expected_abs_tot The expected absolute sum of all values in div_mult_leaves - * */ void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, const double fact, double& expected_abs_tot) const; #ifdef PARAMETERIZE /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ virtual std::vector<double> parameters() const {return {};} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ virtual void get_parameters(std::shared_ptr<NLOptimizer> optimizer){return;} @@ -207,28 +203,28 @@ public: /** * @brief Set the value of all training samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief Set the value of all test samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_test_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief A human readable equation representing the feature * - * @param params parameter values for non-linear operations - * @return feature expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @return A human readable equation representing the feature */ inline std::string expr(const double* params, const int depth=1) const { @@ -243,9 +239,9 @@ public: /** * @brief Get the valid LaTeX expression that represents the feature * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree - * @return the latexified expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode + * @return Get the valid LaTeX expression that represents the feature */ inline std::string get_latex_expr(const double* params, const int depth=1) const { @@ -260,8 +256,8 @@ public: /** * @brief Get the string that corresponds to the code needed to evaluate the node in matlab * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode * @return The matlab code for the feature */ inline std::string matlab_fxn_expr(const double* params, const int depth=1) const @@ -275,27 +271,26 @@ public: } /** - * @brief Set the bounds for the nl parameterization + * @brief Set the upper and lower bounds for the scale and bias term of this Node and its children * - * @param lb pointer to the lower bounds data - * @param ub pointer to the upper bounds data - * @param from_parent How many parameters are between the start of this node's parameters and its parent - * @param depth the current depth of the node on the binary expression tree + * @param lb A pointer to the location where the lower bounds for the scale and bias term of this Node is set + * @param ub A pointer to the location where the upper bounds for the scale and bias term of this Node is set + * @param depth How far down a given Node is from the root OperatorNode */ virtual void set_bounds(double* lb, double* ub, const int depth=1) const; /** - * @brief Set the bounds for the nl parameterization + * @brief Initialize the scale and bias terms for this Node and its children * - * @param params pointer to the parameters vector - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode */ virtual void initialize_params(double* params, const int depth = 1) const; /** * @brief Calculates the derivative of an operation with respect to the parameters for a given sample * - * @param params pointer to the parameters + * @param params A pointer to the bias and scale terms for this Node and its children * @param dfdp pointer to where the feature derivative pointers are located */ inline void param_derivative(const double* params, double* dfdp) const @@ -311,9 +306,9 @@ public: * * @param feat_list list of features already generated * @param feat feature to attempt to take the logarithm of - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. */ void generateLogNode( std::vector<node_ptr>& feat_list, diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/log/parameterized_log.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/log/parameterized_log.cpp index 110fcd5a3855a95fc2da5aa1a05190bf87bbe5a1..7d3ad1eabf02cb53440ae57d430d69298217c2e2 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/log/parameterized_log.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/log/parameterized_log.cpp @@ -222,7 +222,7 @@ void LogNode::set_test_value(const double* params, int offset, const bool for_co } allowed_op_funcs::log( - _n_test_samp, + _n_samp_test, vp_0, params[0], params[1], diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/log/parameterized_log.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/log/parameterized_log.hpp index 0482e12b31a9b9d61dc9e6b2886d5923733dcc91..ee77b803f050e15c417b9fc50c2cd314a25d9092 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/log/parameterized_log.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/log/parameterized_log.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/log/parameterized_log.hpp - * @brief Class describing the parameterized log operator + * @brief Class describing the parameterized log operator * * This class represents the parameterized unary operator -> log(alpha * A + a) * @@ -56,7 +56,7 @@ protected: using LogNode::get_latex_expr; using LogNode::matlab_fxn_expr; - std::vector<double> _params; //!< The parameters vector + std::vector<double> _params; //!< The vector containing the scale and bias terms for the Node double _sign_alpha; //!< Used to alternate between +/- 1 public: @@ -67,14 +67,13 @@ public: LogParamNode(); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature * @param l_bound (double) Minimum absolute value allowed for the feature. * @param u_bound (double) Maximum absolute value allowed for the feature. - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ LogParamNode( const node_ptr feat, @@ -85,19 +84,17 @@ public: ); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ LogParamNode(const node_ptr feat, const unsigned long int feat_ind, std::shared_ptr<NLOptimizer> optimizer); // DocString: log_param_node_init /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -107,8 +104,8 @@ public: LogParamNode(const node_ptr feat, const unsigned long int feat_ind, double const l_bound=1e-50, const double u_bound=1e50); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ node_ptr hard_copy()const; @@ -134,10 +131,10 @@ public: * @brief Get the pointer to the feature's training data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * - * @return pointer to the feature's test values + * @return A pointer to the feature's training data */ inline double* value_ptr(int offset=-1, const bool for_comp=false) const {return value_ptr(_params.data(), offset, for_comp);} @@ -145,7 +142,7 @@ public: * @brief Get the pointer to the feature's test data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * * @return pointer to the feature's test values @@ -178,33 +175,32 @@ public: inline std::string matlab_fxn_expr() const {return matlab_fxn_expr(_params.data());} /** - * @brief Set the bounds for the nl parameterization + * @brief Set the upper and lower bounds for the scale and bias term of this Node and its children * - * @param lb pointer to the lower bounds data - * @param ub pointer to the upper bounds data - * @param from_parent How many parameters are between the start of this node's parameters and its parent - * @param depth the current depth of the node on the binary expression tree + * @param lb A pointer to the location where the lower bounds for the scale and bias term of this Node is set + * @param ub A pointer to the location where the upper bounds for the scale and bias term of this Node is set + * @param depth How far down a given Node is from the root OperatorNode */ void set_bounds(double* lb, double* ub, const int depth=1) const; /** - * @brief Set the bounds for the nl parameterization + * @brief Initialize the scale and bias terms for this Node and its children * - * @param params pointer to the parameters vector - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode */ void initialize_params(double* params, const int depth = 1) const; /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ inline std::vector<double> parameters() const {return _params;} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ void get_parameters(std::shared_ptr<NLOptimizer> optimizer); @@ -225,7 +221,7 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ inline void set_parameters(const double* params) { @@ -249,9 +245,9 @@ public: * * @param feat_list list of features already generated * @param feat feature to attempt to take the logarithm of - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. * @param optimizer The optimizer used to find the parameters of the node */ void generateLogParamNode( diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/mult/multiply.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/mult/multiply.cpp index 3b982a4a28e129b1d9e1bb028092e31b3000385e..fac10bb3607a843562b5645fd16b5d2212b8e9ef 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/mult/multiply.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/mult/multiply.cpp @@ -190,7 +190,7 @@ void MultNode::set_test_value(int offset, const bool for_comp) const { offset += (offset == -1); allowed_op_funcs::mult( - _n_test_samp, + _n_samp_test, _feats[0]->test_value_ptr(2 * offset, for_comp), _feats[1]->test_value_ptr(2 * offset + 1, for_comp), 1.0, diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/mult/multiply.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/mult/multiply.hpp index 64e1cf4ae25cf9fe4811bfd0f9ea0aabe1b7f8b5..a9d4592f746512339a2c105354897a08093585e7 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/mult/multiply.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/mult/multiply.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/multiply.hpp - * @brief Class describing the multiplication operator + * @brief Class describing the multiplication operator * * This class represents the binary operator -> A * B * @@ -53,8 +53,7 @@ public: MultNode(); /** - * @brief Constructor - * @details Constructs the Node from an array of features to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * * @param feat_1 (Node) shared_ptr of the first feature to operate on (A) * @param feat_2 (Node) shared_ptr of the second feature to operate on (B) @@ -64,8 +63,7 @@ public: // DocString: mult_node_init /** - * @brief Constructor - * @details Constructs the Node from node pointer of the features to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat_1 (Node) shared_ptr of the first feature to operate on (A) * @param feat_2 (Node) shared_ptr of the second feature to operate on (B) @@ -76,8 +74,8 @@ public: MultNode(const node_ptr feat_1, const node_ptr feat_2, const unsigned long int feat_ind, const double l_bound, const double u_bound); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ virtual node_ptr hard_copy()const; @@ -133,7 +131,7 @@ public: // DocString: mult_node_rung /** - * @brief return the rung of the feature (Height of the binary expression tree + 1) + * @brief return the rung of the feature (Height of the binary expression tree - 1) * */ inline int rung(const int cur_rung=0) const {return std::max(_feats[0]->rung(cur_rung + 1), _feats[1]->rung(cur_rung + 1));} @@ -144,8 +142,7 @@ public: virtual inline NODE_TYPE type() const {return NODE_TYPE::MULT;} /** - * @brief Get the string character representation of the node for the postfix expression - * @return the string representation of the node for the postfix expression + * @brief Get the term used in the postfix expression for this Node */ inline std::string get_postfix_term() const {return "mult";} @@ -171,35 +168,34 @@ public: void check_feats(); /** - * @brief update the dictionary used to check if an Add/Sub node is valid + * @brief update the dictionary used to check if an Add/Sub/AbsDiff node is valid * * @param add_sub_leaves the dictionary used to check if an Add/Sub node is valid - * @param pl_mn if for an addition node: 1 if for a subtraction node: -1 + * @param pl_mn 1 for addition and -1 for subtraction * @param expected_abs_tot The expected absolute sum of all values in add_sub_leaves */ void update_add_sub_leaves(std::map<std::string, int>& add_sub_leaves, const int pl_mn, int& expected_abs_tot) const; /** - * @brief update the dictionary used to check if a mult/div node is valid + * @brief update the dictionary used to check if an Mult/Div node is valid * * @param div_mult_leaves the dictionary used to check if an Mult/Div node is valid - * @param fact Factor used to update leaves (power of the feature) + * @param fact amount to increment the element (a primary features) of the dictionary by * @param expected_abs_tot The expected absolute sum of all values in div_mult_leaves - * */ void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, const double fact, double& expected_abs_tot) const; #ifdef PARAMETERIZE /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ virtual std::vector<double> parameters() const {return {};} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ virtual void get_parameters(std::shared_ptr<NLOptimizer> optimizer){return;} @@ -212,36 +208,36 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ virtual void set_parameters(const double* params){return;} /** * @brief Set the value of all training samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief Set the value of all test samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_test_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief A human readable equation representing the feature * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree - * @return feature expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode + * @return A human readable equation representing the feature */ inline std::string expr(const double* params, const int depth=1) const { @@ -256,9 +252,9 @@ public: /** * @brief Get the valid LaTeX expression that represents the feature * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree - * @return the latexified expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode + * @return Get the valid LaTeX expression that represents the feature */ inline std::string get_latex_expr(const double* params, const int depth=1) const { @@ -273,8 +269,8 @@ public: /** * @brief Get the string that corresponds to the code needed to evaluate the node in matlab * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode * @return The matlab code for the feature */ inline std::string matlab_fxn_expr(const double* params, const int depth=1) const @@ -288,27 +284,26 @@ public: } /** - * @brief Set the bounds for the nl parameterization + * @brief Set the upper and lower bounds for the scale and bias term of this Node and its children * - * @param lb pointer to the lower bounds data - * @param ub pointer to the upper bounds data - * @param from_parent How many parameters are between the start of this node's parameters and its parent - * @param depth the current depth of the node on the binary expression tree + * @param lb A pointer to the location where the lower bounds for the scale and bias term of this Node is set + * @param ub A pointer to the location where the upper bounds for the scale and bias term of this Node is set + * @param depth How far down a given Node is from the root OperatorNode */ void set_bounds(double* lb, double* ub, const int depth=1) const; /** - * @brief Set the bounds for the nl parameterization + * @brief Initialize the scale and bias terms for this Node and its children * - * @param params pointer to the parameters vector - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode */ void initialize_params(double* params, const int depth = 1) const; /** * @brief Calculates the derivative of an operation with respect to the parameters for a given sample * - * @param params pointer to the parameters + * @param params A pointer to the bias and scale terms for this Node and its children * @param dfdp pointer to where the feature derivative pointers are located */ inline void param_derivative(const double* params, double* dfdp) const {std::copy_n(_feats[0]->value_ptr(params, 2), _n_samp, dfdp);} @@ -321,9 +316,9 @@ public: * @param feat_list list of features already generated * @param feat_1 The (A) feature * @param feat_2 The (B) feature - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. */ void generateMultNode(std::vector<node_ptr>& feat_list, const node_ptr feat_1, const node_ptr feat_2, unsigned long int& feat_ind, const double l_bound, const double u_bound); diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/mult/parameterized_multiply.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/mult/parameterized_multiply.cpp index 2865945417a0b8c689eb4d5973851f50aa618f39..2af7d4b81c3b1eea115acc0e37d80c357638eb94 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/mult/parameterized_multiply.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/mult/parameterized_multiply.cpp @@ -172,7 +172,7 @@ void MultNode::set_test_value(const double* params, int offset, const bool for_c } allowed_op_funcs::mult( - _n_test_samp, + _n_samp_test, vp_0, vp_1, params[0], diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/mult/parameterized_multiply.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/mult/parameterized_multiply.hpp index 521c8870da5acdbdf11f21b74632e888bfc60d81..110134997b4f251bdd19cfa0f70fc8934a00527d 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/mult/parameterized_multiply.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/mult/parameterized_multiply.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/div/parameterized_multiply.hpp - * @brief Class describing the parameterized addition operator + * @brief Class describing the parameterized addition operator * * This class represents the parameterized unary operator -> A * (alpha * B + a) * @@ -65,14 +65,14 @@ public: MultParamNode(); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * - * @param feat (Node) shared_ptr of the feature to operate on (A) + * @param feat_1 (Node) shared_ptr of the feature to operate on (A) + * @param feat_2 (Node) shared_ptr of the feature to operate on (B) * @param feat_ind (int) Index of the new feature * @param l_bound (double) Minimum absolute value allowed for the feature. * @param u_bound (double) Maximum absolute value allowed for the feature. - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ MultParamNode( const node_ptr feat_1, @@ -84,19 +84,18 @@ public: ); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * - * @param feat (Node) shared_ptr of the feature to operate on (A) + * @param feat_1 (Node) shared_ptr of the feature to operate on (A) + * @param feat_2 (Node) shared_ptr of the feature to operate on (B) * @param feat_ind (int) Index of the new feature - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ MultParamNode(const node_ptr feat_1, const node_ptr feat_2, const unsigned long int feat_ind, std::shared_ptr<NLOptimizer> optimizer); // DocString: mult_param_node_init /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -106,8 +105,8 @@ public: MultParamNode(const node_ptr feat_1, const node_ptr feat_2, const unsigned long int feat_ind, double const l_bound=1e-50, const double u_bound=1e50); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ node_ptr hard_copy()const; @@ -133,10 +132,10 @@ public: * @brief Get the pointer to the feature's training data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * - * @return pointer to the feature's test values + * @return A pointer to the feature's training data */ inline double* value_ptr(int offset=-1, const bool for_comp=false) const {return value_ptr(_params.data(), offset, for_comp);} @@ -144,7 +143,7 @@ public: * @brief Get the pointer to the feature's test data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * * @return pointer to the feature's test values @@ -177,15 +176,15 @@ public: inline std::string matlab_fxn_expr() const {return matlab_fxn_expr(_params.data());} /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ inline std::vector<double> parameters() const {return _params;} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ void get_parameters(std::shared_ptr<NLOptimizer> optimizer); @@ -206,7 +205,7 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ inline void set_parameters(const double* params) { @@ -231,9 +230,9 @@ public: * @param feat_list list of features already generated * @param feat_1 The (A) feature * @param feat_2 The (B) feature - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. * @param optimizer The optimizer used to find the parameters of the node */ void generateMultParamNode( diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/neg_exp/negative_exponential.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/neg_exp/negative_exponential.cpp index 8a14190494c203e01ddc800becb316a2b283fa14..98573a7254606232d405c81987021cf132c792e3 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/neg_exp/negative_exponential.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/neg_exp/negative_exponential.cpp @@ -155,7 +155,7 @@ void NegExpNode::set_test_value(int offset, const bool for_comp) const { offset += (offset == -1); allowed_op_funcs::neg_exp( - _n_test_samp, + _n_samp_test, _feats[0]->test_value_ptr(2 * offset, for_comp), 1.0, 0.0, diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/neg_exp/negative_exponential.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/neg_exp/negative_exponential.hpp index a0e824806476f4cd2928e6e9b18288bc57136c2c..0abea08159f4dce62d521829ace3f7b9fde79137 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/neg_exp/negative_exponential.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/neg_exp/negative_exponential.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/negative_exponential.hpp - * @brief Class describing the negative exponential operator + * @brief Class describing the negative exponential operator * * This class represents the unary operator -> exp(-1 * A) * @@ -53,8 +53,7 @@ public: NegExpNode(); /** - * @brief Constructor - * @details Constructs the Node from an array of features to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -63,8 +62,7 @@ public: // DocString: neg_exp_node_init /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -74,8 +72,8 @@ public: NegExpNode(const node_ptr feat, const unsigned long int feat_ind, const double l_bound, const double u_bound); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ virtual node_ptr hard_copy()const; @@ -129,7 +127,7 @@ public: // DocString: neg_exp_node_rung /** - * @brief return the rung of the feature (Height of the binary expression tree + 1) + * @brief return the rung of the feature (Height of the binary expression tree - 1) * */ inline int rung(const int cur_rung=0) const {return _feats[0]->rung(cur_rung + 1);} @@ -140,8 +138,7 @@ public: virtual inline NODE_TYPE type() const {return NODE_TYPE::NEG_EXP;} /** - * @brief Get the string character representation of the node for the postfix expression - * @return the string representation of the node for the postfix expression + * @brief Get the term used in the postfix expression for this Node */ inline std::string get_postfix_term() const {return "nexp";} @@ -160,35 +157,34 @@ public: } /** - * @brief update the dictionary used to check if an Add/Sub node is valid + * @brief update the dictionary used to check if an Add/Sub/AbsDiff node is valid * * @param add_sub_leaves the dictionary used to check if an Add/Sub node is valid - * @param pl_mn if for an addition node: 1 if for a subtraction node: -1 + * @param pl_mn 1 for addition and -1 for subtraction * @param expected_abs_tot The expected absolute sum of all values in add_sub_leaves */ void update_add_sub_leaves(std::map<std::string, int>& add_sub_leaves, const int pl_mn, int& expected_abs_tot) const; /** - * @brief update the dictionary used to check if a mult/div node is valid + * @brief update the dictionary used to check if an Mult/Div node is valid * * @param div_mult_leaves the dictionary used to check if an Mult/Div node is valid - * @param fact Factor used to update leaves (power of the feature) + * @param fact amount to increment the element (a primary features) of the dictionary by * @param expected_abs_tot The expected absolute sum of all values in div_mult_leaves - * */ void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, const double fact, double& expected_abs_tot) const; #ifdef PARAMETERIZE /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ virtual std::vector<double> parameters() const {return {};} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ virtual void get_parameters(std::shared_ptr<NLOptimizer> optimizer){return;} @@ -201,35 +197,35 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ virtual void set_parameters(const double* params){return;} /** * @brief Set the value of all training samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief Set the value of all test samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_test_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief A human readable equation representing the feature * - * @param params parameter values for non-linear operations - * @return feature expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @return A human readable equation representing the feature */ inline std::string expr(const double* params, const int depth=1) const { @@ -243,9 +239,9 @@ public: /** * @brief Get the valid LaTeX expression that represents the feature * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree - * @return the latexified expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode + * @return Get the valid LaTeX expression that represents the feature */ inline std::string get_latex_expr(const double* params, const int depth=1) const { @@ -259,8 +255,8 @@ public: /** * @brief Get the string that corresponds to the code needed to evaluate the node in matlab * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode * @return The matlab code for the feature */ inline std::string matlab_fxn_expr(const double* params, const int depth=1) const @@ -273,27 +269,26 @@ public: } /** - * @brief Set the bounds for the nl parameterization + * @brief Set the upper and lower bounds for the scale and bias term of this Node and its children * - * @param lb pointer to the lower bounds data - * @param ub pointer to the upper bounds data - * @param from_parent How many parameters are between the start of this node's parameters and its parent - * @param depth the current depth of the node on the binary expression tree + * @param lb A pointer to the location where the lower bounds for the scale and bias term of this Node is set + * @param ub A pointer to the location where the upper bounds for the scale and bias term of this Node is set + * @param depth How far down a given Node is from the root OperatorNode */ void set_bounds(double* lb, double* ub, const int depth=1) const; /** - * @brief Set the bounds for the nl parameterization + * @brief Initialize the scale and bias terms for this Node and its children * - * @param params pointer to the parameters vector - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode */ void initialize_params(double* params, const int depth = 1) const; /** * @brief Calculates the derivative of an operation with respect to the parameters for a given sample * - * @param params pointer to the parameters + * @param params A pointer to the bias and scale terms for this Node and its children * @param dfdp pointer to where the feature derivative pointers are located */ inline void param_derivative(const double* params, double* dfdp) const @@ -309,9 +304,9 @@ public: * * @param feat_list list of features already generated * @param feat feature to attempt to take the negative exponential of - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. */ void generateNegExpNode( std::vector<node_ptr>& feat_list, diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/neg_exp/parameterized_negative_exponential.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/neg_exp/parameterized_negative_exponential.cpp index 12beb08fe3b1eeec921489a72c7e33d0a8e319f9..678307c5abc09ba2bc5c2ea816d3eb9e9004f421 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/neg_exp/parameterized_negative_exponential.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/neg_exp/parameterized_negative_exponential.cpp @@ -184,7 +184,7 @@ void NegExpNode::set_test_value(const double* params, int offset, const bool for } allowed_op_funcs::neg_exp( - _n_test_samp, + _n_samp_test, vp_0, params[0], params[1], diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/neg_exp/parameterized_negative_exponential.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/neg_exp/parameterized_negative_exponential.hpp index 9fbe705a2ae7688629dc4f461a57f43fa17c8906..830a49565d8bfc6a9e8da570e946de75a0c4a870 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/neg_exp/parameterized_negative_exponential.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/neg_exp/parameterized_negative_exponential.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/neg_exp/parameterized_negative_exponetial.hpp - * @brief Class describing the parameterized neg_exp operator + * @brief Class describing the parameterized neg_exp operator * * This class represents the parameterized unary operator -> exp(-alpha * A + a) * @@ -55,7 +55,7 @@ protected: using NegExpNode::get_latex_expr; using NegExpNode::matlab_fxn_expr; - std::vector<double> _params; //!< The parameters vector + std::vector<double> _params; //!< The vector containing the scale and bias terms for the Node public: /** @@ -65,14 +65,13 @@ public: NegExpParamNode(); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature * @param l_bound (double) Minimum absolute value allowed for the feature. * @param u_bound (double) Maximum absolute value allowed for the feature. - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ NegExpParamNode( const node_ptr feat, @@ -83,19 +82,17 @@ public: ); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ NegExpParamNode(const node_ptr feat, const unsigned long int feat_ind, std::shared_ptr<NLOptimizer> optimizer); // DocString: neg_exp_param_node_init /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -105,8 +102,8 @@ public: NegExpParamNode(const node_ptr feat, const unsigned long int feat_ind, double const l_bound=1e-50, const double u_bound=1e50); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ node_ptr hard_copy()const; @@ -140,10 +137,10 @@ public: * @brief Get the pointer to the feature's training data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * - * @return pointer to the feature's test values + * @return A pointer to the feature's training data */ inline double* value_ptr(int offset=-1, const bool for_comp=false) const {return value_ptr(_params.data(), offset, for_comp);} @@ -151,7 +148,7 @@ public: * @brief Get the pointer to the feature's test data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * * @return pointer to the feature's test values @@ -176,15 +173,15 @@ public: inline std::string get_latex_expr() const {return get_latex_expr(_params.data());} /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ inline std::vector<double> parameters() const {return _params;} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ void get_parameters(std::shared_ptr<NLOptimizer> optimizer); @@ -205,7 +202,7 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ inline void set_parameters(const double* params) { @@ -229,9 +226,9 @@ public: * * @param feat_list list of features already generated * @param feat feature to attempt to take the negative exponential of - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. * @param optimizer The optimizer used to find the parameters of the node */ void generateNegExpParamNode( diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sin/parameterized_sin.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sin/parameterized_sin.cpp index 0e2190eac2e2fdb5234aff9e50a3a03e2ed94f74..b782a9c6796652787fecaca807d894e147037bae 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sin/parameterized_sin.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sin/parameterized_sin.cpp @@ -172,7 +172,7 @@ void SinNode::set_test_value(const double* params, int offset, const bool for_co } allowed_op_funcs::sin( - _n_test_samp, + _n_samp_test, vp_0, params[0], params[1], diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sin/parameterized_sin.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sin/parameterized_sin.hpp index 9b3b79ca55f4139d239b9adc288a68096fec232e..b2558cbaf1ae1a423dd7d81c2e06255975b92c7e 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sin/parameterized_sin.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sin/parameterized_sin.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/sin/parameterized_sin.hpp - * @brief Class describing the parameterized sin operator + * @brief Class describing the parameterized sin operator * * This class represents the parameterized unary operator -> sin(alpha * A + a) * @@ -55,7 +55,7 @@ protected: using SinNode::get_latex_expr; using SinNode::matlab_fxn_expr; - std::vector<double> _params; //!< The parameters vector + std::vector<double> _params; //!< The vector containing the scale and bias terms for the Node public: /** @@ -65,14 +65,13 @@ public: SinParamNode(); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature * @param l_bound (double) Minimum absolute value allowed for the feature. * @param u_bound (double) Maximum absolute value allowed for the feature. - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ SinParamNode( const node_ptr feat, @@ -83,19 +82,17 @@ public: ); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ SinParamNode(const node_ptr feat, const unsigned long int feat_ind, std::shared_ptr<NLOptimizer> optimizer); // DocString: sin_param_node_init /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -105,8 +102,8 @@ public: SinParamNode(const node_ptr feat, const unsigned long int feat_ind, double const l_bound=1e-50, const double u_bound=1e50); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ node_ptr hard_copy()const; @@ -132,10 +129,10 @@ public: * @brief Get the pointer to the feature's training data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * - * @return pointer to the feature's test values + * @return A pointer to the feature's training data */ inline double* value_ptr(int offset=-1, const bool for_comp=false) const {return value_ptr(_params.data(), offset, for_comp);} @@ -143,7 +140,7 @@ public: * @brief Get the pointer to the feature's test data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * * @return pointer to the feature's test values @@ -176,15 +173,15 @@ public: inline std::string matlab_fxn_expr() const {return matlab_fxn_expr(_params.data());} /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ inline std::vector<double> parameters() const {return _params;} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ void get_parameters(std::shared_ptr<NLOptimizer> optimizer); @@ -205,7 +202,7 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ inline void set_parameters(const double* params) { @@ -229,9 +226,9 @@ public: * * @param feat_list list of features already generated * @param feat feature to attempt to take the sine of - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. * @param optimizer The optimizer used to find the parameters of the node */ void generateSinParamNode( diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sin/sin.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sin/sin.cpp index db351a356e02e8e1765b1c5dc05f18a5131e9b37..67749f03d912dadf0c1e03932a3dc9f543f25a2c 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sin/sin.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sin/sin.cpp @@ -133,7 +133,7 @@ void SinNode::set_test_value(int offset, const bool for_comp) const { offset += (offset == -1); allowed_op_funcs::sin( - _n_test_samp, + _n_samp_test, _feats[0]->test_value_ptr(2 * offset, for_comp), 1.0, 0.0, diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sin/sin.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sin/sin.hpp index 4dbe38f495cd4299a2aeaa7f719202adbddb1d92..f790fd55159f3f8941fc875de63f27291e049923 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sin/sin.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sin/sin.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/sin.hpp - * @brief Class describing the sine operator + * @brief Class describing the sine operator * * This class represents the unary operator -> sin(A) * @@ -53,8 +53,7 @@ public: SinNode(); /** - * @brief Constructor - * @details Constructs the Node from an array of features to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -63,8 +62,7 @@ public: // DocString: sin_node_init /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -74,8 +72,8 @@ public: SinNode(const node_ptr feat, const unsigned long int feat_ind, const double l_bound, const double u_bound); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ virtual node_ptr hard_copy()const; @@ -129,7 +127,7 @@ public: // DocString: sin_node_rung /** - * @brief return the rung of the feature (Height of the binary expression tree + 1) + * @brief return the rung of the feature (Height of the binary expression tree - 1) * */ inline int rung(const int cur_rung=0) const {return _feats[0]->rung(cur_rung + 1);} @@ -140,8 +138,7 @@ public: virtual inline NODE_TYPE type() const {return NODE_TYPE::SIN;} /** - * @brief Get the string character representation of the node for the postfix expression - * @return the string representation of the node for the postfix expression + * @brief Get the term used in the postfix expression for this Node */ inline std::string get_postfix_term() const {return "sin";} @@ -160,35 +157,34 @@ public: } /** - * @brief update the dictionary used to check if an Add/Sub node is valid + * @brief update the dictionary used to check if an Add/Sub/AbsDiff node is valid * * @param add_sub_leaves the dictionary used to check if an Add/Sub node is valid - * @param pl_mn if for an addition node: 1 if for a subtraction node: -1 + * @param pl_mn 1 for addition and -1 for subtraction * @param expected_abs_tot The expected absolute sum of all values in add_sub_leaves */ void update_add_sub_leaves(std::map<std::string, int>& add_sub_leaves, const int pl_mn, int& expected_abs_tot) const; /** - * @brief update the dictionary used to check if a mult/div node is valid + * @brief update the dictionary used to check if an Mult/Div node is valid * * @param div_mult_leaves the dictionary used to check if an Mult/Div node is valid - * @param fact Factor used to update leaves (power of the feature) + * @param fact amount to increment the element (a primary features) of the dictionary by * @param expected_abs_tot The expected absolute sum of all values in div_mult_leaves - * */ void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, const double fact, double& expected_abs_tot) const; #ifdef PARAMETERIZE /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ virtual std::vector<double> parameters() const {return {};} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ virtual void get_parameters(std::shared_ptr<NLOptimizer> optimizer){return;} @@ -201,35 +197,35 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ virtual void set_parameters(const double* params){return;} /** * @brief Set the value of all training samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief Set the value of all test samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_test_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief A human readable equation representing the feature * - * @param params parameter values for non-linear operations - * @return feature expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @return A human readable equation representing the feature */ inline std::string expr(const double* params, const int depth=1) const { @@ -244,9 +240,9 @@ public: /** * @brief Get the valid LaTeX expression that represents the feature * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree - * @return the latexified expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode + * @return Get the valid LaTeX expression that represents the feature */ inline std::string get_latex_expr(const double* params, const int depth=1) const { @@ -261,8 +257,8 @@ public: /** * @brief Get the string that corresponds to the code needed to evaluate the node in matlab * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode * @return The matlab code for the feature */ inline std::string matlab_fxn_expr(const double* params, const int depth=1) const @@ -276,27 +272,26 @@ public: } /** - * @brief Set the bounds for the nl parameterization + * @brief Set the upper and lower bounds for the scale and bias term of this Node and its children * - * @param lb pointer to the lower bounds data - * @param ub pointer to the upper bounds data - * @param from_parent How many parameters are between the start of this node's parameters and its parent - * @param depth the current depth of the node on the binary expression tree + * @param lb A pointer to the location where the lower bounds for the scale and bias term of this Node is set + * @param ub A pointer to the location where the upper bounds for the scale and bias term of this Node is set + * @param depth How far down a given Node is from the root OperatorNode */ void set_bounds(double* lb, double* ub, const int depth=1) const; /** - * @brief Set the bounds for the nl parameterization + * @brief Initialize the scale and bias terms for this Node and its children * - * @param params pointer to the parameters vector - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode */ void initialize_params(double* params, const int depth = 1) const; /** * @brief Calculates the derivative of an operation with respect to the parameters for a given sample * - * @param params pointer to the parameters + * @param params A pointer to the bias and scale terms for this Node and its children * @param dfdp pointer to where the feature derivative pointers are located */ inline void param_derivative(const double* params, double* dfdp) const @@ -312,9 +307,9 @@ public: * * @param feat_list list of features already generated * @param feat feature to attempt to take the sine of - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. */ void generateSinNode( std::vector<node_ptr>& feat_list, diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/six_pow/parameterized_sixth_power.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/six_pow/parameterized_sixth_power.cpp index dc0330676f1ae2dd417730e7a2688a3005c3fb57..164c84cbfc57f77c52ecda36153dfe89c6caa773 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/six_pow/parameterized_sixth_power.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/six_pow/parameterized_sixth_power.cpp @@ -187,7 +187,7 @@ void SixPowNode::set_test_value(const double* params, int offset, const bool for } allowed_op_funcs::sixth_pow( - _n_test_samp, + _n_samp_test, vp_0, params[0], params[1], diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/six_pow/parameterized_sixth_power.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/six_pow/parameterized_sixth_power.hpp index 1bc58f05f9b323298dc9690af329e65de2e94bc2..94228b00730aa7c17c05fdabae3b696d9170b882 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/six_pow/parameterized_sixth_power.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/six_pow/parameterized_sixth_power.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/six_pow/parameterized_sixth_pow.hpp - * @brief Class describing the parameterized sixth power operator + * @brief Class describing the parameterized sixth power operator * * This class represents the parameterized unary operator -> (alpha * A + a)^6 * @@ -55,7 +55,7 @@ protected: using SixPowNode::get_latex_expr; using SixPowNode::matlab_fxn_expr; - std::vector<double> _params; //!< The parameters vector + std::vector<double> _params; //!< The vector containing the scale and bias terms for the Node public: /** @@ -65,14 +65,13 @@ public: SixPowParamNode(); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature * @param l_bound (double) Minimum absolute value allowed for the feature. * @param u_bound (double) Maximum absolute value allowed for the feature. - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ SixPowParamNode( const node_ptr feat, @@ -83,19 +82,17 @@ public: ); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ SixPowParamNode(const node_ptr feat, const unsigned long int feat_ind, std::shared_ptr<NLOptimizer> optimizer); // DocString: six_pow_param_node_init /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -105,8 +102,8 @@ public: SixPowParamNode(const node_ptr feat, const unsigned long int feat_ind, double const l_bound=1e-50, const double u_bound=1e50); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ node_ptr hard_copy()const; @@ -132,10 +129,10 @@ public: * @brief Get the pointer to the feature's training data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * - * @return pointer to the feature's test values + * @return A pointer to the feature's training data */ inline double* value_ptr(int offset=-1, const bool for_comp=false) const {return value_ptr(_params.data(), offset, for_comp);} @@ -143,7 +140,7 @@ public: * @brief Get the pointer to the feature's test data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * * @return pointer to the feature's test values @@ -176,15 +173,15 @@ public: inline std::string matlab_fxn_expr() const {return matlab_fxn_expr(_params.data());} /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ inline std::vector<double> parameters() const {return _params;} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ void get_parameters(std::shared_ptr<NLOptimizer> optimizer); @@ -205,7 +202,7 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ inline void set_parameters(const double* params) { @@ -229,9 +226,9 @@ public: * * @param feat_list list of features already generated * @param feat feature to attempt to take the sixth power of - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. * @param optimizer The optimizer used to find the parameters of the node */ void generateSixPowParamNode( diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/six_pow/sixth_power.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/six_pow/sixth_power.cpp index 5293033e5b5f7526a8e52bc092e34aefd07b8253..503ccf65b4cfa9abd52145f83146984e16ffa3cd 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/six_pow/sixth_power.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/six_pow/sixth_power.cpp @@ -152,7 +152,7 @@ void SixPowNode::set_test_value(int offset, const bool for_comp) const { offset += (offset == -1); allowed_op_funcs::sixth_pow( - _n_test_samp, + _n_samp_test, _feats[0]->test_value_ptr(2 * offset, for_comp), 1.0, 0.0, diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/six_pow/sixth_power.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/six_pow/sixth_power.hpp index 2342a5c5bad713d5262dc5741a9165fe3c816f98..c0d85f625c4f4e5b7b606eae3b5feffc86d29e6f 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/six_pow/sixth_power.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/six_pow/sixth_power.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/sixth_power.hpp - * @brief Class describing the sixth power operator + * @brief Class describing the sixth power operator * * This class represents the unary operator -> (A)^6 * @@ -53,8 +53,7 @@ public: SixPowNode(); /** - * @brief Constructor - * @details Constructs the Node from an array of features to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -63,8 +62,7 @@ public: // DocString: six_pow_node_init /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -74,8 +72,8 @@ public: SixPowNode(const node_ptr feat, const unsigned long int feat_ind, const double l_bound, const double u_bound); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ virtual node_ptr hard_copy()const; @@ -129,7 +127,7 @@ public: // DocString: six_pow_node_rung /** - * @brief return the rung of the feature (Height of the binary expression tree + 1) + * @brief return the rung of the feature (Height of the binary expression tree - 1) * */ inline int rung(const int cur_rung=0) const {return _feats[0]->rung(cur_rung + 1);} @@ -140,8 +138,7 @@ public: virtual inline NODE_TYPE type() const {return NODE_TYPE::SIX_POW;} /** - * @brief Get the string character representation of the node for the postfix expression - * @return the string representation of the node for the postfix expression + * @brief Get the term used in the postfix expression for this Node */ inline std::string get_postfix_term() const {return "sp";} @@ -160,35 +157,34 @@ public: } /** - * @brief update the dictionary used to check if an Add/Sub node is valid + * @brief update the dictionary used to check if an Add/Sub/AbsDiff node is valid * * @param add_sub_leaves the dictionary used to check if an Add/Sub node is valid - * @param pl_mn if for an addition node: 1 if for a subtraction node: -1 + * @param pl_mn 1 for addition and -1 for subtraction * @param expected_abs_tot The expected absolute sum of all values in add_sub_leaves */ void update_add_sub_leaves(std::map<std::string, int>& add_sub_leaves, const int pl_mn, int& expected_abs_tot) const; /** - * @brief update the dictionary used to check if a mult/div node is valid + * @brief update the dictionary used to check if an Mult/Div node is valid * * @param div_mult_leaves the dictionary used to check if an Mult/Div node is valid - * @param fact Factor used to update leaves (power of the feature) + * @param fact amount to increment the element (a primary features) of the dictionary by * @param expected_abs_tot The expected absolute sum of all values in div_mult_leaves - * */ void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, const double fact, double& expected_abs_tot) const; #ifdef PARAMETERIZE /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ virtual std::vector<double> parameters() const {return {};} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ virtual void get_parameters(std::shared_ptr<NLOptimizer> optimizer){return;} @@ -201,36 +197,36 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ virtual void set_parameters(const double* params){return;} /** * @brief Set the value of all training samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief Set the value of all test samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_test_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief A human readable equation representing the feature * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree - * @return feature expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode + * @return A human readable equation representing the feature */ inline std::string expr(const double* params, const int depth=1) const { @@ -244,9 +240,9 @@ public: /** * @brief Get the valid LaTeX expression that represents the feature * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree - * @return the latexified expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode + * @return Get the valid LaTeX expression that represents the feature */ inline std::string get_latex_expr(const double* params, const int depth=1) const { @@ -260,8 +256,8 @@ public: /** * @brief Get the string that corresponds to the code needed to evaluate the node in matlab * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode * @return The matlab code for the feature */ inline std::string matlab_fxn_expr(const double* params, const int depth=1) const @@ -274,27 +270,26 @@ public: } /** - * @brief Set the bounds for the nl parameterization + * @brief Set the upper and lower bounds for the scale and bias term of this Node and its children * - * @param lb pointer to the lower bounds data - * @param ub pointer to the upper bounds data - * @param from_parent How many parameters are between the start of this node's parameters and its parent - * @param depth the current depth of the node on the binary expression tree + * @param lb A pointer to the location where the lower bounds for the scale and bias term of this Node is set + * @param ub A pointer to the location where the upper bounds for the scale and bias term of this Node is set + * @param depth How far down a given Node is from the root OperatorNode */ void set_bounds(double* lb, double* ub, const int depth=1) const; /** - * @brief Set the bounds for the nl parameterization + * @brief Initialize the scale and bias terms for this Node and its children * - * @param params pointer to the parameters vector - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode */ void initialize_params(double* params, const int depth = 1) const; /** * @brief Calculates the derivative of an operation with respect to the parameters for a given sample * - * @param params pointer to the parameters + * @param params A pointer to the bias and scale terms for this Node and its children * @param dfdp pointer to where the feature derivative pointers are located */ inline void param_derivative(const double* params, double* dfdp) const @@ -310,9 +305,9 @@ public: * * @param feat_list list of features already generated * @param feat feature to attempt to take the sixth power of - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. */ void generateSixPowNode( std::vector<node_ptr>& feat_list, diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sq/parameterized_square.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sq/parameterized_square.cpp index 1c0b4be23fee10a1e4e229835838db3b2bed2917..8bfe1d78d0ff58bad413247ce4f5f6ad71c291f0 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sq/parameterized_square.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sq/parameterized_square.cpp @@ -178,7 +178,7 @@ void SqNode::set_test_value(const double* params, int offset, const bool for_com } allowed_op_funcs::sq( - _n_test_samp, + _n_samp_test, vp_0, params[0], params[1], diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sq/parameterized_square.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sq/parameterized_square.hpp index 5f8c0e5c2ebcceead7ba962b4520dd982fcf7ec6..ee609023ef10b048107b93528f5d280f3dd87f77 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sq/parameterized_square.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sq/parameterized_square.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/sq/parameterized_square.hpp - * @brief Class describing the parameterized square operator + * @brief Class describing the parameterized square operator * * This class represents the parameterized unary operator -> (alpha * A + a)^2 * @@ -55,7 +55,7 @@ protected: using SqNode::get_latex_expr; using SqNode::matlab_fxn_expr; - std::vector<double> _params; //!< The parameters vector + std::vector<double> _params; //!< The vector containing the scale and bias terms for the Node public: /** @@ -65,14 +65,13 @@ public: SqParamNode(); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature * @param l_bound (double) Minimum absolute value allowed for the feature. * @param u_bound (double) Maximum absolute value allowed for the feature. - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ SqParamNode( const node_ptr feat, @@ -83,19 +82,17 @@ public: ); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ SqParamNode(const node_ptr feat, const unsigned long int feat_ind, std::shared_ptr<NLOptimizer> optimizer); // DocString: sq_param_node_init /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -105,8 +102,8 @@ public: SqParamNode(const node_ptr feat, const unsigned long int feat_ind, double const l_bound=1e-50, const double u_bound=1e50); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ node_ptr hard_copy()const; @@ -132,10 +129,10 @@ public: * @brief Get the pointer to the feature's training data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * - * @return pointer to the feature's test values + * @return A pointer to the feature's training data */ inline double* value_ptr(int offset=-1, const bool for_comp=false) const {return value_ptr(_params.data(), offset, for_comp);} @@ -143,7 +140,7 @@ public: * @brief Get the pointer to the feature's test data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * * @return pointer to the feature's test values @@ -176,15 +173,15 @@ public: inline std::string matlab_fxn_expr() const {return matlab_fxn_expr(_params.data());} /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ inline std::vector<double> parameters() const {return _params;} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ void get_parameters(std::shared_ptr<NLOptimizer> optimizer); @@ -205,7 +202,7 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ inline void set_parameters(const double* params) { @@ -229,9 +226,9 @@ public: * * @param feat_list list of features already generated * @param feat feature to attempt to take the square of - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. * @param optimizer The optimizer used to find the parameters of the node */ void generateSqParamNode( diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sq/square.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sq/square.cpp index 5ffa0b365a33e0d6b5bfcaf9ce69e30fea786e15..3ed4aa33bcc582397788bdb96d5169d7d13989e6 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sq/square.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sq/square.cpp @@ -142,7 +142,7 @@ void SqNode::set_test_value(int offset, const bool for_comp) const { offset += (offset == -1); allowed_op_funcs::sq( - _n_test_samp, + _n_samp_test, _feats[0]->test_value_ptr(2 * offset, for_comp), 1.0, 0.0, diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sq/square.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sq/square.hpp index 09ba6495ab18bd3056bc5ff6907429e3ecc00c70..011bea6fee17e50b851e4074fd3a941a7c5b4dbf 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sq/square.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sq/square.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/square.hpp - * @brief Class describing the square operator + * @brief Class describing the square operator * * This class represents the unary operator -> (A)^2 * @@ -52,8 +52,7 @@ public: SqNode(); /** - * @brief Constructor - * @details Constructs the Node from an array of features to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -62,8 +61,7 @@ public: // DocString: sq_node_init /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -73,8 +71,8 @@ public: SqNode(const node_ptr feat, const unsigned long int feat_ind, const double l_bound, const double u_bound); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ virtual node_ptr hard_copy()const; @@ -128,7 +126,7 @@ public: // DocString: sq_node_rung /** - * @brief return the rung of the feature (Height of the binary expression tree + 1) + * @brief return the rung of the feature (Height of the binary expression tree - 1) * */ inline int rung(const int cur_rung=0) const {return _feats[0]->rung(cur_rung + 1);} @@ -139,8 +137,7 @@ public: virtual inline NODE_TYPE type() const {return NODE_TYPE::SQ;} /** - * @brief Get the string character representation of the node for the postfix expression - * @return the string representation of the node for the postfix expression + * @brief Get the term used in the postfix expression for this Node */ inline std::string get_postfix_term() const {return "sq";} @@ -159,35 +156,34 @@ public: } /** - * @brief update the dictionary used to check if an Add/Sub node is valid + * @brief update the dictionary used to check if an Add/Sub/AbsDiff node is valid * * @param add_sub_leaves the dictionary used to check if an Add/Sub node is valid - * @param pl_mn if for an addition node: 1 if for a subtraction node: -1 + * @param pl_mn 1 for addition and -1 for subtraction * @param expected_abs_tot The expected absolute sum of all values in add_sub_leaves */ void update_add_sub_leaves(std::map<std::string, int>& add_sub_leaves, const int pl_mn, int& expected_abs_tot) const; /** - * @brief update the dictionary used to check if a mult/div node is valid + * @brief update the dictionary used to check if an Mult/Div node is valid * * @param div_mult_leaves the dictionary used to check if an Mult/Div node is valid - * @param fact Factor used to update leaves (power of the feature) + * @param fact amount to increment the element (a primary features) of the dictionary by * @param expected_abs_tot The expected absolute sum of all values in div_mult_leaves - * */ void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, const double fact, double& expected_abs_tot) const; #ifdef PARAMETERIZE /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ virtual std::vector<double> parameters() const {return {};} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ virtual void get_parameters(std::shared_ptr<NLOptimizer> optimizer){return;} @@ -200,36 +196,36 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ virtual void set_parameters(const double* params){return;} /** * @brief Set the value of all training samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief Set the value of all test samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_test_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief A human readable equation representing the feature * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree - * @return feature expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode + * @return A human readable equation representing the feature */ inline std::string expr(const double* params, const int depth=1) const { @@ -243,9 +239,9 @@ public: /** * @brief Get the valid LaTeX expression that represents the feature * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree - * @return the latexified expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode + * @return Get the valid LaTeX expression that represents the feature */ inline std::string get_latex_expr(const double* params, const int depth=1) const { @@ -259,8 +255,8 @@ public: /** * @brief Get the string that corresponds to the code needed to evaluate the node in matlab * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode * @return The matlab code for the feature */ inline std::string matlab_fxn_expr(const double* params, const int depth=1) const @@ -273,27 +269,26 @@ public: } /** - * @brief Set the bounds for the nl parameterization + * @brief Set the upper and lower bounds for the scale and bias term of this Node and its children * - * @param lb pointer to the lower bounds data - * @param ub pointer to the upper bounds data - * @param from_parent How many parameters are between the start of this node's parameters and its parent - * @param depth the current depth of the node on the binary expression tree + * @param lb A pointer to the location where the lower bounds for the scale and bias term of this Node is set + * @param ub A pointer to the location where the upper bounds for the scale and bias term of this Node is set + * @param depth How far down a given Node is from the root OperatorNode */ void set_bounds(double* lb, double* ub, const int depth=1) const; /** - * @brief Set the bounds for the nl parameterization + * @brief Initialize the scale and bias terms for this Node and its children * - * @param params pointer to the parameters vector - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode */ void initialize_params(double* params, const int depth = 1) const; /** * @brief Calculates the derivative of an operation with respect to the parameters for a given sample * - * @param params pointer to the parameters + * @param params A pointer to the bias and scale terms for this Node and its children * @param dfdp pointer to where the feature derivative pointers are located */ inline void param_derivative(const double* params, double* dfdp) const @@ -309,9 +304,9 @@ public: * * @param feat_list list of features already generated * @param feat feature to attempt to take the square of - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. */ void generateSqNode( std::vector<node_ptr>& feat_list, diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sqrt/parameterized_square_root.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sqrt/parameterized_square_root.cpp index 0a2bb3f48437b46369d9f5b5ebf0a1f9075a19d4..8f7f1fca02be820f23f2e531599a304d8a201a60 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sqrt/parameterized_square_root.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sqrt/parameterized_square_root.cpp @@ -204,7 +204,7 @@ void SqrtNode::set_test_value(const double* params, int offset, const bool for_c } allowed_op_funcs::sqrt( - _n_test_samp, + _n_samp_test, vp_0, params[0], params[1], diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sqrt/parameterized_square_root.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sqrt/parameterized_square_root.hpp index b31f596c337e75b3cfe73d8e899537bac4eeee05..429bdc24c8369d0b2cbfd7d5433007be1a41d60a 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sqrt/parameterized_square_root.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sqrt/parameterized_square_root.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/sqrt/parameterized_square_root.hpp - * @brief Class describing the parameterized square root operator + * @brief Class describing the parameterized square root operator * * This class represents the parameterized unary operator -> sqrt(alpha * A + a) * @@ -56,7 +56,7 @@ protected: using SqrtNode::get_latex_expr; using SqrtNode::matlab_fxn_expr; - std::vector<double> _params; //!< The parameters vector + std::vector<double> _params; //!< The vector containing the scale and bias terms for the Node double _sign_alpha; //!< 1 if alpha is positive, -1 if alpha is negative public: @@ -67,14 +67,13 @@ public: SqrtParamNode(); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature * @param l_bound (double) Minimum absolute value allowed for the feature. * @param u_bound (double) Maximum absolute value allowed for the feature. - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ SqrtParamNode( const node_ptr feat, @@ -85,19 +84,17 @@ public: ); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ SqrtParamNode(const node_ptr feat, const unsigned long int feat_ind, std::shared_ptr<NLOptimizer> optimizer); // DocString: sqrt_param_node_init /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -107,8 +104,8 @@ public: SqrtParamNode(const node_ptr feat, const unsigned long int feat_ind, double const l_bound=1e-50, const double u_bound=1e50); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ node_ptr hard_copy()const; @@ -134,10 +131,10 @@ public: * @brief Get the pointer to the feature's training data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * - * @return pointer to the feature's test values + * @return A pointer to the feature's training data */ inline double* value_ptr(int offset=-1, const bool for_comp=false) const {return value_ptr(_params.data(), offset, for_comp);} @@ -145,7 +142,7 @@ public: * @brief Get the pointer to the feature's test data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * * @return pointer to the feature's test values @@ -178,15 +175,15 @@ public: inline std::string matlab_fxn_expr() const {return matlab_fxn_expr(_params.data());} /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ inline std::vector<double> parameters() const {return _params;} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ void get_parameters(std::shared_ptr<NLOptimizer> optimizer); @@ -207,7 +204,7 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ inline void set_parameters(const double* params) { @@ -215,20 +212,19 @@ public: } /** - * @brief Set the bounds for the nl parameterization + * @brief Set the upper and lower bounds for the scale and bias term of this Node and its children * - * @param lb pointer to the lower bounds data - * @param ub pointer to the upper bounds data - * @param from_parent How many parameters are between the start of this node's parameters and its parent - * @param depth the current depth of the node on the binary expression tree + * @param lb A pointer to the location where the lower bounds for the scale and bias term of this Node is set + * @param ub A pointer to the location where the upper bounds for the scale and bias term of this Node is set + * @param depth How far down a given Node is from the root OperatorNode */ void set_bounds(double* lb, double* ub, const int depth=1) const; /** - * @brief Set the bounds for the nl parameterization + * @brief Initialize the scale and bias terms for this Node and its children * - * @param params pointer to the parameters vector - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode */ void initialize_params(double* params, const int depth = 1) const; @@ -249,9 +245,9 @@ public: * * @param feat_list list of features already generated * @param feat feature to attempt to take the square root of - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. * @param optimizer The optimizer used to find the parameters of the node */ void generateSqrtParamNode( diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sqrt/square_root.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sqrt/square_root.cpp index 9c076cee87dcb2d8aaf5c9c9d0fd67bb09f4a9be..03da01cd0d81bb27e23778a532be59af3a0cbf3c 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sqrt/square_root.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sqrt/square_root.cpp @@ -151,7 +151,7 @@ void SqrtNode::set_test_value(int offset, const bool for_comp) const { offset += (offset == -1); allowed_op_funcs::sqrt( - _n_test_samp, + _n_samp_test, _feats[0]->test_value_ptr(2 * offset, for_comp), 1.0, 0.0, diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sqrt/square_root.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sqrt/square_root.hpp index a130bd9668f4acbe11650a3c4b88e8580fcb16e7..10a747e329f2560f266af9ee7b31fbbce3af790d 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sqrt/square_root.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sqrt/square_root.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/square_root.hpp - * @brief Class describing the square root operator + * @brief Class describing the square root operator * * This class represents the unary operator -> (A)^(1/2) * @@ -53,8 +53,7 @@ public: SqrtNode(); /** - * @brief Constructor - * @details Constructs the Node from an array of features to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -63,8 +62,7 @@ public: // DocString: sqrt_node_init /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat (Node) shared_ptr of the feature to operate on (A) * @param feat_ind (int) Index of the new feature @@ -74,8 +72,8 @@ public: SqrtNode(const node_ptr feat, const unsigned long int feat_ind, const double l_bound, const double u_bound); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ virtual node_ptr hard_copy()const; @@ -129,7 +127,7 @@ public: // DocString: sqrt_node_rung /** - * @brief return the rung of the feature (Height of the binary expression tree + 1) + * @brief return the rung of the feature (Height of the binary expression tree - 1) * */ inline int rung(const int cur_rung=0) const {return _feats[0]->rung(cur_rung + 1);} @@ -140,8 +138,7 @@ public: virtual inline NODE_TYPE type() const {return NODE_TYPE::SQRT;} /** - * @brief Get the string character representation of the node for the postfix expression - * @return the string representation of the node for the postfix expression + * @brief Get the term used in the postfix expression for this Node */ inline std::string get_postfix_term() const {return "sqrt";} @@ -160,35 +157,34 @@ public: } /** - * @brief update the dictionary used to check if an Add/Sub node is valid + * @brief update the dictionary used to check if an Add/Sub/AbsDiff node is valid * * @param add_sub_leaves the dictionary used to check if an Add/Sub node is valid - * @param pl_mn if for an addition node: 1 if for a subtraction node: -1 + * @param pl_mn 1 for addition and -1 for subtraction * @param expected_abs_tot The expected absolute sum of all values in add_sub_leaves */ void update_add_sub_leaves(std::map<std::string, int>& add_sub_leaves, const int pl_mn, int& expected_abs_tot) const; /** - * @brief update the dictionary used to check if a mult/div node is valid + * @brief update the dictionary used to check if an Mult/Div node is valid * * @param div_mult_leaves the dictionary used to check if an Mult/Div node is valid - * @param fact Factor used to update leaves (power of the feature) + * @param fact amount to increment the element (a primary features) of the dictionary by * @param expected_abs_tot The expected absolute sum of all values in div_mult_leaves - * */ void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, const double fact, double& expected_abs_tot) const; #ifdef PARAMETERIZE /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ virtual std::vector<double> parameters() const {return {};} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ virtual void get_parameters(std::shared_ptr<NLOptimizer> optimizer){return;} @@ -201,35 +197,35 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ virtual void set_parameters(const double* params){return;} /** * @brief Set the value of all training samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief Set the value of all test samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_test_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief A human readable equation representing the feature * - * @param params parameter values for non-linear operations - * @return feature expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @return A human readable equation representing the feature */ inline std::string expr(const double* params, const int depth=1) const { @@ -244,9 +240,9 @@ public: /** * @brief Get the valid LaTeX expression that represents the feature * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree - * @return the latexified expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode + * @return Get the valid LaTeX expression that represents the feature */ inline std::string get_latex_expr(const double* params, const int depth=1) const { @@ -261,8 +257,8 @@ public: /** * @brief Get the string that corresponds to the code needed to evaluate the node in matlab * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode * @return The matlab code for the feature */ inline std::string matlab_fxn_expr(const double* params, const int depth=1) const @@ -276,27 +272,26 @@ public: } /** - * @brief Set the bounds for the nl parameterization + * @brief Set the upper and lower bounds for the scale and bias term of this Node and its children * - * @param lb pointer to the lower bounds data - * @param ub pointer to the upper bounds data - * @param from_parent How many parameters are between the start of this node's parameters and its parent - * @param depth the current depth of the node on the binary expression tree + * @param lb A pointer to the location where the lower bounds for the scale and bias term of this Node is set + * @param ub A pointer to the location where the upper bounds for the scale and bias term of this Node is set + * @param depth How far down a given Node is from the root OperatorNode */ virtual void set_bounds(double* lb, double* ub, const int depth=1) const; /** - * @brief Set the bounds for the nl parameterization + * @brief Initialize the scale and bias terms for this Node and its children * - * @param params pointer to the parameters vector - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode */ virtual void initialize_params(double* params, const int depth = 1) const; /** * @brief Calculates the derivative of an operation with respect to the parameters for a given sample * - * @param params pointer to the parameters + * @param params A pointer to the bias and scale terms for this Node and its children * @param dfdp pointer to where the feature derivative pointers are located */ inline void param_derivative(const double* params, double* dfdp) const @@ -312,9 +307,9 @@ public: * * @param feat_list list of features already generated * @param feat feature to attempt to take the square root of - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. */ void generateSqrtNode( std::vector<node_ptr>& feat_list, diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sub/parameterized_subtract.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sub/parameterized_subtract.cpp index 9e5ab703b73a62f8ccac443ce3469acc84cce9e7..c94afde4bd897bab835cdf91a3c7190ae01645e1 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sub/parameterized_subtract.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sub/parameterized_subtract.cpp @@ -172,7 +172,7 @@ void SubNode::set_test_value(const double* params, int offset, const bool for_co vp_1 = _feats[1]->test_value_ptr(2 * offset + 1, for_comp); } allowed_op_funcs::sub( - _n_test_samp, + _n_samp_test, vp_0, vp_1, params[0], diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sub/parameterized_subtract.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sub/parameterized_subtract.hpp index 04cc6f2bf47f55b8c3094531a0974f61004edb8a..216cbac11ee8ba2e00030d80e7e5871926b1febd 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sub/parameterized_subtract.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sub/parameterized_subtract.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/sub/parameterized_subtract.hpp - * @brief Class describing the parameterized addition operator + * @brief Class describing the parameterized addition operator * * This class represents the parameterized unary operator -> A - (alpha * B + a) * @@ -65,15 +65,14 @@ public: SubParamNode(); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * - * @param feat_1 shared_ptr of the feature to operate on (A) - * @param feat_2 shared_ptr of the feature to operate on (B) + * @param feat_1 (Node) shared_ptr of the feature to operate on (A) + * @param feat_2 (Node) shared_ptr of the feature to operate on (B) * @param feat_ind (int) Index of the new feature * @param l_bound (double) Minimum absolute value allowed for the feature. * @param u_bound (double) Maximum absolute value allowed for the feature. - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ SubParamNode( const node_ptr feat_1, @@ -85,23 +84,21 @@ public: ); /** - * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * - * @param feat_1 shared_ptr of the feature to operate on (A) - * @param feat_2 shared_ptr of the feature to operate on (B) + * @param feat_1 (Node) shared_ptr of the feature to operate on (A) + * @param feat_2 (Node) shared_ptr of the feature to operate on (B) * @param feat_ind (int) Index of the new feature - * @param optimizer The optimizer to find the optimal parameters for the features + * @param optimizer (NLOptimizer) The optimizer to find the optimal parameters for the features */ SubParamNode(const node_ptr feat_1, const node_ptr feat_2, const unsigned long int feat_ind, std::shared_ptr<NLOptimizer> optimizer); // DocString: sub_param_node_init /** * @brief Constructor - * @details Constructs the Node from node pointer of the feature to operate on * - * @param feat_1 shared_ptr of the feature to operate on (A) - * @param feat_2 shared_ptr of the feature to operate on (B) + * @param feat_1 (Node) shared_ptr of the feature to operate on (A) + * @param feat_2 (Node) shared_ptr of the feature to operate on (B) * @param feat_ind (int) Index of the new feature * @param l_bound (double) Minimum absolute value allowed for the feature. * @param u_bound (double) Maximum absolute value allowed for the feature. @@ -109,8 +106,8 @@ public: SubParamNode(const node_ptr feat_1, const node_ptr feat_2, const unsigned long int feat_ind, double const l_bound=1e-50, const double u_bound=1e50); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ node_ptr hard_copy()const; @@ -136,10 +133,10 @@ public: * @brief Get the pointer to the feature's training data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * - * @return pointer to the feature's test values + * @return A pointer to the feature's training data */ inline double* value_ptr(int offset=-1, const bool for_comp=false) const {return value_ptr(_params.data(), offset, for_comp);} @@ -147,7 +144,7 @@ public: * @brief Get the pointer to the feature's test data * @details If the feature is not already stored in memory, then calculate the feature and return the pointer to the data * - * @param offset(int) the integer value to offset the location in the temporary storage array + * @param offset (int) the integer value to offset the location in the temporary storage array * @param for_comp (bool) If true then the evaluation is used for comparing features * * @return pointer to the feature's test values @@ -180,15 +177,15 @@ public: inline std::string matlab_fxn_expr() const {return matlab_fxn_expr(_params.data());} /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ inline std::vector<double> parameters() const {return _params;} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ void get_parameters(std::shared_ptr<NLOptimizer> optimizer); @@ -209,7 +206,7 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ inline void set_parameters(const double* params) { @@ -234,9 +231,9 @@ public: * @param feat_list list of features already generated * @param feat_1 The (A) feature * @param feat_2 The (B) feature - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. * @param optimizer The optimizer used to find the parameters of the node */ void generateSubParamNode( diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sub/subtract.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sub/subtract.cpp index 2a39757c771bc190eed7476ef96b9e2fbc41d104..e9a97a34dfda440e90057cfbb717ca7edf4ffbce 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sub/subtract.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sub/subtract.cpp @@ -181,7 +181,7 @@ void SubNode::set_test_value(int offset, const bool for_comp) const { offset += (offset == -1); allowed_op_funcs::sub( - _n_test_samp, + _n_samp_test, _feats[0]->test_value_ptr(2 * offset, for_comp), _feats[1]->test_value_ptr(2 * offset + 1, for_comp), 1.0, diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sub/subtract.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sub/subtract.hpp index e0a1ce5a2fc96fec4dbf6988e9e5513c89f814d8..90315e047b55f8b430e4386740e692fa7c52a6ad 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sub/subtract.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sub/subtract.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_operator_nodes/subtract.hpp - * @brief Class describing the subtraction operator + * @brief Class describing the subtraction operator * * This class represents the binary operator -> A - B * @@ -54,8 +54,7 @@ public: SubNode(); /** - * @brief Constructor - * @details Constructs the Node from an array of features to operate on + * @brief Constructor excluding bounds on the maximum absolute value of the Node * * @param feat_1 (Node) shared_ptr of the first feature to operate on (A) * @param feat_2 (Node) shared_ptr of the second feature to operate on (B) @@ -65,8 +64,7 @@ public: // DocString: sub_node_init /** - * @brief Constructor - * @details Constructs the Node from node pointer of the features to operate on + * @brief Constructor including bounds on the maximum absolute value of the Node * * @param feat_1 (Node) shared_ptr of the first feature to operate on (A) * @param feat_2 (Node) shared_ptr of the second feature to operate on (B) @@ -77,8 +75,8 @@ public: SubNode(const node_ptr feat_1, const node_ptr feat_2, const unsigned long int feat_ind, const double l_bound, const double u_bound); /** - * @brief Makes a hard copy node (all items in _feats are a new shared_ptr) - * @return A shared_ptr of a copy of this node with all members hard copied + * @brief Makes a hard copy node (All members of the Node are independent of the original one) + * @return A shared_ptr to the copied node */ virtual node_ptr hard_copy()const; @@ -134,7 +132,7 @@ public: // DocString: sub_node_rung /** - * @brief return the rung of the feature (Height of the binary expression tree + 1) + * @brief return the rung of the feature (Height of the binary expression tree - 1) * */ inline int rung(const int cur_rung=0) const {return std::max(_feats[0]->rung(cur_rung + 1), _feats[1]->rung(cur_rung + 1));} @@ -145,8 +143,7 @@ public: virtual inline NODE_TYPE type() const {return NODE_TYPE::SUB;} /** - * @brief Get the string character representation of the node for the postfix expression - * @return the string representation of the node for the postfix expression + * @brief Get the term used in the postfix expression for this Node */ inline std::string get_postfix_term() const {return "sub";} @@ -172,35 +169,34 @@ public: void check_feats(); /** - * @brief update the dictionary used to check if an Add/Sub node is valid + * @brief update the dictionary used to check if an Add/Sub/AbsDiff node is valid * * @param add_sub_leaves the dictionary used to check if an Add/Sub node is valid - * @param pl_mn if for an addition node: 1 if for a subtraction node: -1 + * @param pl_mn 1 for addition and -1 for subtraction * @param expected_abs_tot The expected absolute sum of all values in add_sub_leaves */ void update_add_sub_leaves(std::map<std::string, int>& add_sub_leaves, const int pl_mn, int& expected_abs_tot) const; /** - * @brief update the dictionary used to check if a mult/div node is valid + * @brief update the dictionary used to check if an Mult/Div node is valid * * @param div_mult_leaves the dictionary used to check if an Mult/Div node is valid - * @param fact Factor used to update leaves (power of the feature) + * @param fact amount to increment the element (a primary features) of the dictionary by * @param expected_abs_tot The expected absolute sum of all values in div_mult_leaves - * */ void update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, const double fact, double& expected_abs_tot) const; #ifdef PARAMETERIZE /** - * @brief The parameters used for introducing more non linearity in the operators + * @brief The parameters used for including individual scale and bias terms to each operator in the Node */ virtual std::vector<double> parameters() const {return {};} /** - * @brief Solve the non-linear optimization to set the parameters - * @details Fits the data points from _feats->value_ptr and prop to get the parameters for the feature + * @brief Optimize the scale and bias terms for each operation in the Node. + * @details Use optimizer to find the scale and bias terms that minimizes the associated loss function * - * @param optimizer The optimizer used to find the best scale and shift parameters + * @param optimizer The optimizer used to evaluate the loss function for each optimization and find the optimal parameters */ virtual void get_parameters(std::shared_ptr<NLOptimizer> optimizer){return;} @@ -213,36 +209,36 @@ public: /** * @brief Set the non-linear parameters - * @param params The new parameters of the node + * @param params The new scale and bias terms of this node */ virtual void set_parameters(const double* params){return;} /** * @brief Set the value of all training samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief Set the value of all test samples for the feature inside the central data storage array * - * @param params pointer to the non-linear parameter values + * @param params A pointer to the bias and scale terms for this Node and its children * @param offset (int) Where the current node is in the binary expression tree relative to other nodes at the same depth * @param for_comp (bool) If true then the evaluation is used for comparing features - * @param depth the max depth of paramterization (in the binary expression tree) + * @param depth (int) How far down a given Node is from the root OperatorNode */ void set_test_value(const double* params, int offset=-1, const bool for_comp=false, const int depth=1) const; /** * @brief A human readable equation representing the feature * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree - * @return feature expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode + * @return A human readable equation representing the feature */ inline std::string expr(const double* params, const int depth=1) const { @@ -257,9 +253,9 @@ public: /** * @brief Get the valid LaTeX expression that represents the feature * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree - * @return the latexified expression + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode + * @return Get the valid LaTeX expression that represents the feature */ inline std::string get_latex_expr(const double* params, const int depth=1) const { @@ -274,8 +270,8 @@ public: /** * @brief Get the string that corresponds to the code needed to evaluate the node in matlab * - * @param params parameter values for non-linear operations - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode * @return The matlab code for the feature */ inline std::string matlab_fxn_expr(const double* params, const int depth=1) const @@ -289,27 +285,26 @@ public: } /** - * @brief Set the bounds for the nl parameterization + * @brief Set the upper and lower bounds for the scale and bias term of this Node and its children * - * @param lb pointer to the lower bounds data - * @param ub pointer to the upper bounds data - * @param from_parent How many parameters are between the start of this node's parameters and its parent - * @param depth the current depth of the node on the binary expression tree + * @param lb A pointer to the location where the lower bounds for the scale and bias term of this Node is set + * @param ub A pointer to the location where the upper bounds for the scale and bias term of this Node is set + * @param depth How far down a given Node is from the root OperatorNode */ void set_bounds(double* lb, double* ub, const int depth=1) const; /** - * @brief Set the bounds for the nl parameterization + * @brief Initialize the scale and bias terms for this Node and its children * - * @param params pointer to the parameters vector - * @param depth the current depth of the node on the binary expression tree + * @param params A pointer to the bias and scale terms for this Node and its children + * @param depth How far down a given Node is from the root OperatorNode */ void initialize_params(double* params, const int depth = 1) const; /** * @brief Calculates the derivative of an operation with respect to the parameters for a given sample * - * @param params pointer to the parameters + * @param params A pointer to the bias and scale terms for this Node and its children * @param dfdp pointer to where the feature derivative pointers are located */ inline void param_derivative(const double* params, double* dfdp) const {std::fill_n(dfdp, _n_samp, -1.0);} @@ -322,9 +317,9 @@ public: * @param feat_list list of features already generated * @param feat_1 The (A) feature * @param feat_2 The (B) feature - * @param feat_ind The index of the last generated feature - * @param l_bound lower bound for the maximum feature value - * @param u_bound upper bound for the maximum feature value + * @param feat_ind Index of the new feature + * @param l_bound Minimum absolute value allowed for the feature. + * @param u_bound Maximum absolute value allowed for the feature. */ void generateSubNode(std::vector<node_ptr>& feat_list, const node_ptr feat_1, const node_ptr feat_2, unsigned long int& feat_ind, const double l_bound, const double u_bound); diff --git a/src/feature_creation/node/operator_nodes/allowed_ops.hpp b/src/feature_creation/node/operator_nodes/allowed_ops.hpp index 1415ea7f1a9e8916b42edc47eef8b2c29f78c0f3..fab3fff6aa6c3c43866d82d8438aad3077ab6161 100644 --- a/src/feature_creation/node/operator_nodes/allowed_ops.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_ops.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/allowed_ops.hpp - * @brief Definition of the map that converts the string representation of an operation to the correct OperatorNode constructor + * @brief Definition of the map that converts the string representation of an operation to the correct OperatorNode constructor * * @author Thomas A. R. Purcell (tpurcell) * @bug No known bugs. diff --git a/src/feature_creation/node/operator_nodes/functions.hpp b/src/feature_creation/node/operator_nodes/functions.hpp index fc394bb47d26181a9586cda6a3f5f720d4e89a8c..46a55d4064cc9f981eefcdc6f020271aaba6263d 100644 --- a/src/feature_creation/node/operator_nodes/functions.hpp +++ b/src/feature_creation/node/operator_nodes/functions.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/operator_nodes/functions.hpp - * @brief Definition of all allowed functions OperatorNodes can have + * @brief Definition of all allowed functions OperatorNodes can have * * @author Thomas A. R. Purcell (tpurcell) * @bug No known bugs. diff --git a/src/feature_creation/node/utils.hpp b/src/feature_creation/node/utils.hpp index 4ee003e83746c9faf5342c09fb0b2ab96f2ca401..032b56524e2dda1a0142d445c024ea9ea18d28ed 100644 --- a/src/feature_creation/node/utils.hpp +++ b/src/feature_creation/node/utils.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/utils.hpp - * @brief utility functions to build node_ptrs from strings + * @brief utility functions to build node_ptrs from strings * * @author Thomas A. R. Purcell (tpurcell) * @bug No known bugs. @@ -28,12 +28,12 @@ namespace str2node { /** - * @brief Convert a postfix expression into a node_ptr + * @brief Convert a postfix expression of a feature into a node_ptr * @details Creates a stack to iteratively generate the feature represented by the expression * * @param postfix_expr The postfix expression of the feature node - * @param phi_0 The initial feature set - * @param feat_ind The desired feature index + * @param phi_0 The primary feature space + * @param feat_ind The index of the new feature * @return The feature node described by the postfix expression */ node_ptr postfix2node(const std::string postfix_expr, const std::vector<node_ptr>& phi_0, unsigned long int& feat_ind); @@ -50,7 +50,7 @@ node_ptr postfix2node(const std::string postfix_expr, const std::vector<node_ptr std::vector<node_ptr> phi_selected_from_file(const std::string filename, const std::vector<node_ptr> phi_0); /** - * @brief Convert a text file into the feature space + * @brief Convert a text file containing postfix expressions of features into the feature space * @details Read in the file to get the postfix expressions and regenerate the features using phi_0 * * @param filename The name of the file storing all the features diff --git a/src/feature_creation/node/value_storage/nodes_value_containers.hpp b/src/feature_creation/node/value_storage/nodes_value_containers.hpp index 07131e6e92bfc364ac2bb98d83186d05f373c07b..31a3b990e5f159cf9d69ce083b7d6bd63f303b1c 100644 --- a/src/feature_creation/node/value_storage/nodes_value_containers.hpp +++ b/src/feature_creation/node/value_storage/nodes_value_containers.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/node/value_storage/node_value_containers.hpp - * @brief Centeral storage area for all descriptor matrix data + * @brief Centeral storage area for all descriptor matrix data * * This file contains definitions where all descriptor/feature data is stored permanently or in temporary storage arrays * All Nodes's (except ModelNodes) value_ptr/test_value_ptrs point to data here. @@ -42,40 +42,45 @@ namespace py = boost::python; namespace node_value_arrs { - extern std::vector<double> TEMP_STORAGE_ARR; //!< Array to temporarily store feature training data - extern std::vector<double> VALUES_ARR; //!< Training data of the stored features - extern std::vector<double> TEMP_STORAGE_TEST_ARR; //!< Array to temporarily store feature test data - extern std::vector<double> TEST_VALUES_ARR; //!< Value of the stored features test data - extern std::vector<double> D_MATRIX; //!< The descriptor matrix - extern std::vector<double> PARAM_STORAGE_ARR; //!< Array to store parameterized feature values - extern std::vector<double> PARAM_STORAGE_TEST_ARR; //!< Array to store parameterized feature values for the test set - - extern std::vector<int> TEMP_STORAGE_REG; //!< Register to see which feature is stored in each slot for the training data - extern std::vector<int> TEMP_STORAGE_TEST_REG; //!< Register to see which feature is stored in each slot for the test data + extern std::vector<double> VALUES_ARR; //!< The central storage location for the values of the training data for each feature with a rung <= N_RUNGS_STORED + extern std::vector<double> TEST_VALUES_ARR; //!< The central storage location for the values of the test data for each feature with a rung <= N_RUNGS_STORED + + extern std::vector<double> TEMP_STORAGE_ARR; //!< The vector used to temporarily store the values of each feature with a rung > N_RUNGS_STORED (These are calculated on the fly when the values are required) + extern std::vector<double> TEMP_STORAGE_TEST_ARR; //!< The vector used to temporarily store the values of each feature with a rung > N_RUNGS_STORED (These are calculated on the fly when the values are required) + extern std::vector<int> TEMP_STORAGE_REG; //!< Register that maps the slots in TEMP_STORAGE_ARR to the index of the feature whose data is currently stored there (reset by setting all elements of this vector to -1) + extern std::vector<int> TEMP_STORAGE_TEST_REG; //!< Register that maps the slots in TEMP_STORAGE_TEST_ARR to the index of the feature whose data is currently stored there (reset by setting all elements of this vector to -1) + + extern std::vector<double> PARAM_STORAGE_ARR; //!< The vector used to temporarily store the values of each feature that has free-parameters (These are calculated on the fly when the values are required) + extern std::vector<double> PARAM_STORAGE_TEST_ARR; //!< The vector used to temporarily store the values of each feature that has free-parameters (These are calculated on the fly when the values are required) + + extern std::vector<double> D_MATRIX; //!< The descriptor matrix (Central storage for the selected feature space) + extern std::vector<int> TASK_SZ_TRAIN; //!< Number of training samples per task extern std::vector<int> TASK_SZ_TEST; //!< Number of test sample per task - extern int N_SELECTED; //!< Number of features selected - extern int N_SAMPLES; //!< Number of training samples for each feature - extern int N_SAMPLES_TEST; //!< Number of test samples for each feature - extern int N_PRIMARY_FEATURES; //!< Number of primary features with stored values + extern int N_SELECTED; //!< Number of selected features + + extern int N_SAMPLES; //!< Number of training samples for each feature (Sum of all elements in TASK_SZ_TRAIN) + extern int N_SAMPLES_TEST; //!< Number of test samples for each feature (Sum of all elements in TASK_SZ_TEST) + + extern int N_PRIMARY_FEATURES; //!< Number of primary features extern int N_STORE_FEATURES; //!< Number of features with stored values - extern int N_RUNGS_STORED; //!< Number of rungs with values stored - extern int MAX_N_THREADS; //!< Get the maximum number of threads possible - extern int N_OP_SLOTS; //!< The number of possible operator slots - extern int N_PARAM_OP_SLOTS; //!< The maximum number of possible operator slots + extern int N_RUNGS_STORED; //!< Maximum rung for permanently storing a features value extern int MAX_RUNG; //!< The maximum rung for all features + extern int MAX_N_THREADS; //!< Get the maximum number of threads possible for a calculation + extern int N_OP_SLOTS; //!< The number of possible nodes of the binary expression tree that maybe calculated on the fly + extern int N_PARAM_OP_SLOTS; //!< The number of possible non-leaf nodes of the binary expression tree + /** - * @brief Initialize the node value arrays - * @details Using the size of the initial feature space constructor the storage arrays + * @brief Initialize all central storage vectors/descriptive variables * - * @param n_samples Number of training samples for each feature - * @param n_samples_test Number of test samples for each feature - * @param n_primary_feat Number of primary features - * @param max_rung Largest rung of a feature + * @param n_samples The number of training samples for each feature (Sum of all elements in TASK_SZ_TRAIN) + * @param n_samples_test The number of test samples for each feature (Sum of all elements in TASK_SZ_TEST) + * @param n_primary_feat The number of primary features + * @param max_rung The maximum rung for all features * @param set_test_task_sz If True reset the task_sz vectors - * @param use_params If True set up parameter storage + * @param use_params If True set up parameterized feature storage as well */ void initialize_values_arr( const int n_samples, @@ -88,13 +93,12 @@ namespace node_value_arrs // DocString: node_vals_init_no_ts /** - * @brief Initialize the node value arrays - * @details Using the size of the initial feature space constructor the storage arrays + * @brief Initialize all central storage vectors/descriptive variables * - * @param n_samples Number of training samples for each feature - * @param n_samples_test Number of test samples for each feature - * @param n_primary_feat Number of primary features - * @param max_rung Largest rung of a feature + * @param n_samples The number of training samples for each feature (Sum of all elements in TASK_SZ_TRAIN) + * @param n_samples_test The number of test samples for each feature (Sum of all elements in TASK_SZ_TEST) + * @param n_primary_feat The number of primary features + * @param max_rung The maximum rung for all features */ inline void initialize_values_arr( const int n_samples, @@ -107,14 +111,13 @@ namespace node_value_arrs } /** - * @brief Initialize the node value arrays - * @details Using the size of the initial feature space constructor the storage arrays + * @brief Initialize all central storage vectors/descriptive variables * - * @param task_sz_train Number of training samples per task - * @param task_sz_test Number of test sample per task - * @param n_primary_feat Number of primary features - * @param max_rung Largest rung of a feature - * @param use_params If True set up parameter storage + * @param task_sz_train The number of training samples per task + * @param task_sz_test The number of test sample per task + * @param n_primary_feat The number of primary features + * @param max_rung The maximum rung for all features + * @param use_params If True set up parameterized feature storage as well */ void initialize_values_arr( const std::vector<int> task_sz_train, @@ -125,31 +128,29 @@ namespace node_value_arrs ); /** - * @brief Resize the node value arrays - * @details Using the updated number of features increase the size of the storage arrays + * @brief Resize the central storage array given a new number of features and the current rung of the features * - * @param n_dims Number of dimensions to store - * @param n_feat number of features to store - * @param use_temp If true keep the temporary_storage + * @param n_rung The current rung of the generated features + * @param n_feat The new number of features to store */ void resize_values_arr(const int n_dims, const int n_feat); + // DocString: node_vals_init_param /** * @brief Initialize the parameter storage array */ + void initialize_param_storage(); - // DocString: node_vlas_init_d_mat + // DocString: node_vals_init_d_mat /** * @brief Initialize the descriptor matrix - * @details Initialize an empty descriptor matrix * */ void initialize_d_matrix_arr(); /** - * @brief Resize the descriptor matrix - * @details Using the number of newly selected features increase the size of the descriptor matrix + * @brief Resize the descriptor matrix for the new number of selected features * * @param n_select Number of features to select */ @@ -173,7 +174,7 @@ namespace node_value_arrs * @brief Get the operator slot associated with a given rung/offset * * @param rung Rung of the feature - * @param offset Offset used to prevent overwrites + * @param offset Offset used to prevent overwrites (determines where in the binary expression tree this operator is) * @param for_comp If true get a slot dedicated to comparing features * * @return The operator slot to use @@ -187,7 +188,7 @@ namespace node_value_arrs * @brief Get the parameter operator slot associated with a given rung/offset * * @param rung Rung of the feature - * @param offset Offset used to prevent overwrites + * @param offset Offset used to prevent overwrites (determines where in the binary expression tree this operator is) * @param for_comp If true get a slot dedicated to comparing features * * @return The operator slot to use @@ -232,7 +233,7 @@ namespace node_value_arrs * * @param ind The Node's arr_ind * @param rung Rung of the feature - * @param offset Offset used to prevent overwrites + * @param offset Offset used to prevent overwrites (determines where in the binary expression tree this operator is) * @param for_comp If true get a slot dedicated to comparing features * * @return The register element for a given feature index and offset @@ -251,7 +252,7 @@ namespace node_value_arrs * * @param ind The Node's arr_ind * @param rung Rung of the feature - * @param offset Offset used to prevent overwrites + * @param offset Offset used to prevent overwrites (determines where in the binary expression tree this operator is) * @param for_comp If true get a slot dedicated to comparing features * * @return The register element for a given feature index and offset @@ -268,7 +269,7 @@ namespace node_value_arrs /** * @brief Access element of the permanent training data storage array * - * @param feature_ind The _arr_ind of Node to get the training data of + * @param feature_ind The _feat_ind of Node to get the training data of * * @return pointer to the Node's training data */ @@ -277,7 +278,7 @@ namespace node_value_arrs /** * @brief Access element of the permanent test data storage array * - * @param feature_ind The _arr_ind of Node to get the test data of + * @param feature_ind The _feat_ind of Node to get the test data of * * @return pointer to the Node's test data */ @@ -305,7 +306,7 @@ namespace node_value_arrs * @brief Access the param storage array * * @param rung Rung of the feature - * @param offset(int) the offset for temporary storage access + * @param offset Offset used to prevent overwrites (determines where in the binary expression tree this operator is) * @param for_comp If true get a slot dedicated to comparing features * @return pointer to the correct element of the PARAM_STORAGE_ARR */ @@ -324,7 +325,7 @@ namespace node_value_arrs * @brief Access the param storage array for the test set * * @param rung Rung of the feature - * @param offset(int) the offset for temporary storage access + * @param offset Offset used to prevent overwrites (determines where in the binary expression tree this operator is) * @param for_comp If true get a slot dedicated to comparing features * @return pointer to the correct element of the PARAM_STORAGE_ARR */ @@ -345,7 +346,7 @@ namespace node_value_arrs * @param arr_ind Nodes _arr_ind * @param feat_ind Nodes _feat_ind * @param rung Rung of the feature - * @param offset(int) the offset for temporary storage access + * @param offset Offset used to prevent overwrites (determines where in the binary expression tree this operator is) * @param for_comp If true get a slot dedicated to comparing features * * @return The value pointer @@ -364,7 +365,7 @@ namespace node_value_arrs * @param arr_ind Nodes _arr_ind * @param feat_ind Nodes _feat_ind * @param rung Rung of the feature - * @param offset(int) the offset for temporary storage access + * @param offset Offset used to prevent overwrites (determines where in the binary expression tree this operator is) * @param for_comp If true get a slot dedicated to comparing features * * @return The value pointer @@ -413,10 +414,10 @@ namespace node_value_arrs * @brief Initialize the node value arrays * @details Using the size of the initial feature space constructor the storage arrays * - * @param task_sz_train Number of training samples per task - * @param task_sz_test Number of test sample per task - * @param n_primary_feat Number of primary features - * @param max_rung Largest rung of a feature + * @param task_sz_train (list) The number of training samples per task + * @param task_sz_test (list) The number of test sample per task + * @param n_primary_feat (int) The number of primary features + * @param max_rung (int) The maximum rung for all features */ inline void initialize_values_arr( py::list task_sz_train, @@ -439,10 +440,10 @@ namespace node_value_arrs * @brief Initialize the node value arrays * @details Using the size of the initial feature space constructor the storage arrays * - * @param task_sz_train Number of training samples per task - * @param task_sz_test Number of test sample per task - * @param n_primary_feat Number of primary features - * @param max_rung Largest rung of a feature + * @param task_sz_train (np.ndarray) The number of training samples per task + * @param task_sz_test (np.ndarray) The number of test sample per task + * @param n_primary_feat (int) The number of primary features + * @param max_rung (int) The maximum rung for all features */ inline void initialize_values_arr( np::ndarray task_sz_train, diff --git a/src/feature_creation/units/Unit.hpp b/src/feature_creation/units/Unit.hpp index 1f5459b6d3695f96b0ba85df8a48861e7ba168e9..bae27a85893791b2e7046d25cedeca72c69b189d 100644 --- a/src/feature_creation/units/Unit.hpp +++ b/src/feature_creation/units/Unit.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/unit/Unit.hpp - * @brief A representation of the units for each feature + * @brief A representation of the units for each feature * * A dictionary representation of the unit for a features (key = unit, value = power) * @@ -51,7 +51,7 @@ private: ar & _dct; } protected: - std::map<std::string, double> _dct; //!< the dictionary describing the units <unit string, unit power> + std::map<std::string, double> _dct; //!< The dictionary representation of the unit <unit string, unit power> public: // DocString: unit_base_const @@ -71,7 +71,7 @@ public: // DocString: unit_init_str /** - * @brief Construct the unit based on a string + * @brief Construct the unit based on a string representation of the unit * @details Take a string representation of a unit, and build the Unit * * @param unit_str The string to build the unit diff --git a/src/inputs/InputParser.cpp b/src/inputs/InputParser.cpp index 831074639186f108e4f2c7bff0ebf4e8d5cea064..4d894742f81cbe54271b6162ae0aafe379421542 100644 --- a/src/inputs/InputParser.cpp +++ b/src/inputs/InputParser.cpp @@ -28,7 +28,7 @@ InputParser::InputParser(pt::ptree IP, std::string fn, std::shared_ptr<MPI_Inter _n_dim(IP.get<int>("desc_dim")), _n_sis_select(IP.get<int>("n_sis_select")), _max_rung(IP.get<int>("max_rung")), - _max_store_rung(IP.get<int>("n_rung_store", _max_rung - 1)), + _n_rung_store(IP.get<int>("n_rung_store", _max_rung - 1)), _n_rung_generate(IP.get<int>("n_rung_generate", 0)), _n_samp(0), _n_residuals(IP.get<int>("n_residual", 1)), @@ -254,7 +254,7 @@ void InputParser::generate_feature_space( int cur_line = 0; int n_train_samp = 0; - int n_test_samp = 0; + int n_samp_test = 0; while (std::getline(data_stream, line)) { @@ -273,7 +273,7 @@ void InputParser::generate_feature_space( // This data point is in the validation dataset // Find where the row should be in the data structure - n_test_samp = 0; + n_samp_test = 0; for(auto& task : tasks) { int task_ind = std::find(task.second.begin(), task.second.end(), cur_line) - task.second.begin(); @@ -281,7 +281,7 @@ void InputParser::generate_feature_space( { if(std::any_of(_leave_out_inds.begin(), _leave_out_inds.end(), [&ii, &task](int ind){return ind == task.second[ii];})) { - ++n_test_samp; + ++n_samp_test; } } @@ -296,7 +296,7 @@ void InputParser::generate_feature_space( { if(ii - 1 != taskind) { - test_data[ii - 1][n_test_samp] = std::stod(split_line[ii]); + test_data[ii - 1][n_samp_test] = std::stod(split_line[ii]); } } } @@ -415,7 +415,7 @@ void InputParser::generate_feature_space( _calc_type, _max_rung, _n_sis_select, - _max_store_rung, + _n_rung_store, _n_rung_generate, _cross_cor_max, _l_bound, @@ -433,7 +433,7 @@ void InputParser::generate_feature_space( _calc_type, _max_rung, _n_sis_select, - _max_store_rung, + _n_rung_store, _n_rung_generate, _cross_cor_max, _l_bound, diff --git a/src/inputs/InputParser.hpp b/src/inputs/InputParser.hpp index b49901465e7f9b98833aa3574e46e0c7aca3d29c..f24f08083e9afc23165bad722ef2f2e995d75fe0 100644 --- a/src/inputs/InputParser.hpp +++ b/src/inputs/InputParser.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file inputs/InputParser.hpp - * @brief Define the class that parses the input file + * @brief Define the class that parses the input file * * This class parses and stores the parameters in the input file * @@ -46,46 +46,47 @@ class InputParser { public: - const std::vector<std::string> _param_opset; //!< 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> _opset; //!< List of all operators for feature combination - std::vector<double> _prop_train; //!< The values of the property in the training set - std::vector<double> _prop_test; //!< The values of the property in the test set + const std::vector<std::string> _param_opset; //!< Vector containing all allowed operators strings for operators with free parameters + std::vector<std::string> _opset; //!< Vector containing all allowed operators strings + std::vector<double> _prop_train; //!< The value of the property to evaluate the loss function against for the training set + std::vector<double> _prop_test; //!< The value of the property to evaluate the loss function against for the test set - std::vector<int> _leave_out_inds; //!< Indexes from the initial data file to use as a test set - std::vector<int> _task_sizes_train; //!< Number of samples in each task's training data - std::vector<int> _task_sizes_test; //!< //!< Number of samples in each task's test data + std::vector<int> _leave_out_inds; //!< List of indexes from the initial data file in the test set + std::vector<int> _task_sizes_train; //!< Number of training samples per task + std::vector<int> _task_sizes_test; //!< Number of testing samples per task - Unit _prop_unit; //!< The Unit for the property + Unit _prop_unit; //!< The Unit of the property const std::string _filename; //!< Name of the input file const std::string _data_file; //!< Name of the data file const std::string _prop_key; //!< Key used to find the property column in the data file - std::string _prop_label; //!< label used to describe the property + std::string _prop_label; //!< The label of the property const std::string _task_key; //!< Key used to find the task column in the data file - const std::string _calc_type; //!< Type of projection operator to use + const std::string _calc_type; //!< The type of LossFunction to use when projecting the features onto a property std::shared_ptr<FeatureSpace> _feat_space; //!< shared_ptr to the FeatureSpace generated from the data file and the input file double _cross_cor_max; //!< Maximum cross-correlation used for selecting features - double _l_bound; //!< Minimum absolute value allowed for the feature. - double _u_bound; //!< Maximum absolute value allowed for the feature. + double _l_bound; //!< The lower bound for the maximum absolute value of the features + double _u_bound; //!< The upper bound for the maximum absolute value of the features - const int _n_dim; //!< Number of dimensions to calculate + const int _n_dim; //!< The maximum number of features allowed in the linear model const int _max_rung; //!< Maximum rung for the feature creation - const int _max_store_rung; //!< Total rungs stored in memory - const int _n_rung_generate; //!< Total number of rungs to generate on the fly - const int _n_sis_select; //!< //!< Number of features to select for each dimensions - int _n_samp; //!< //!< Number of samples (training data) + const int _n_rung_store; //!< The number of rungs to calculate and store the value of the features for all samples + const int _n_rung_generate; //!< Either 0 or 1, and is the number of rungs to generate on the fly during SIS + const int _n_sis_select; //!< Number of features to select during each SIS iteration + int _n_samp; //!< Number of samples in the training set const int _n_residuals; //!< Number of residuals to pass to the next sis model - const int _n_models_store; //!< Number of models to store - const int _max_param_depth; //!< Max depth to parameterize a feature (default=_max_rung) + const int _n_models_store; //!< The number of models to output to files + const int _max_param_depth; //!< The maximum depth in the binary expression tree to set non-linear optimization const int _nlopt_seed; //!< The seed used for the nlOpt library - const bool _fix_intercept; //!< If true force intercept to be 0.0 + const bool _fix_intercept; //!< If true the bias term is fixed at 0 const bool _global_param_opt; //!< True if global optimization is requested for non-linear optimization of parameters (Can break reproducibility) - const bool _reparam_residual; //!< True if reparameterize features using the residuals + const bool _reparam_residual; //!< If True then reparameterize features using the residuals of each model + /** - * @brief Constructor + * @brief Constructor of the InputParser * * @param IP Property tree generated from json file * @param fn filename for the input file @@ -94,13 +95,12 @@ public: InputParser(pt::ptree IP, std::string fn, std::shared_ptr<MPI_Interface> comm); /** - * @brief Accessor function to _feat_space + * @brief The generated FeatureSpace */ inline std::shared_ptr<FeatureSpace> feat_space() const {return _feat_space;} /** * @brief Generate the feature space from input files and parameters - * @details [long description] * * @param comm MPI communicator for the calculation * @param headers column headers for all columns in the data file (expr of the Nodes) @@ -112,8 +112,7 @@ public: std::shared_ptr<MPI_Interface> comm, std::vector<std::string> headers, std::vector<Unit> units, - std::map<std::string, - std::vector<int>> tasks, + std::map<std::string, std::vector<int>> tasks, int taskind ); }; diff --git a/src/loss_function/LossFunction.hpp b/src/loss_function/LossFunction.hpp index f2d67918b2893cc1e60433b7dcaa89452829c9c9..13f0a4034a1d25cb4d06b4c5812b94a6287d9cd1 100644 --- a/src/loss_function/LossFunction.hpp +++ b/src/loss_function/LossFunction.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file loss_function/LossFunction.hpp - * @brief A class used to calculate the projection score and l0-regularization error + * @brief A class used to calculate the projection score and l0-regularization error * * @author Thomas A. R. Purcell (tpurcell) * @bug No known bugs. @@ -36,7 +36,7 @@ protected: std::vector<double> _error_train; //!< The error vector for the training set std::vector<double> _error_test; //!< The error vector for the test set - std::vector<double> _coefs; //!< Coefficients for the model + std::vector<double> _coefs; //!< Coefficients for the linear model const std::vector<int> _task_sizes_train; //!< Number of training samples per task const std::vector<int> _task_sizes_test; //!< Number of testing samples per task @@ -44,10 +44,10 @@ protected: const int _n_samp; //!< Number of samples in the training set const int _n_samp_test; //!< Number of samples in the test set int _n_project_prop; //!< Number of properties to project over - int _n_feat; - int _n_dim; + int _n_feat; //!< Number features in the linear model + int _n_dim; //!< Total number of constants to fit (scale and bias terms) const int _n_task; //!< Number of tasks - const bool _fix_intercept; + const bool _fix_intercept; //!< If true then the bias term is fixed at 0 public: /** @@ -142,50 +142,161 @@ public: */ virtual void reset_projection_prop(const std::vector<std::vector<model_node_ptr>>& models) = 0; + /** + * @brief The type of LossFunction + */ virtual LOSS_TYPE type() const = 0; + + /** + * @brief Coefficients for the linear model + */ std::vector<double> coefs() const{return _coefs;}; + /** + * @brief Number of training samples per task + */ inline std::vector<int> task_sizes_train() const {return _task_sizes_train;} + + /** + * @brief Number of testing samples per task + */ inline std::vector<int> task_sizes_test() const {return _task_sizes_test;} + /** + * @brief The value of the property to evaluate the loss function against for the training set + */ inline const std::vector<double>& prop_train() const {return _prop_train;} + + /** + * @brief The value of the property to evaluate the loss function against for the test set + */ inline const std::vector<double>& prop_test() const {return _prop_test;} + /** + * @brief The estimated value of the property to evaluate the loss function against for the training set + */ inline const std::vector<double>& prop_train_est() const {return _prop_train_est;} + + /** + * @brief The estimated value of the property to evaluate the loss function against for the test set + */ inline const std::vector<double>& prop_test_est() const {return _prop_test_est;} + /** + * @brief The property vector used for projection + */ inline const std::vector<double>& prop_project() const {return _projection_prop;} + /** + * @brief Copy of the value of the property to evaluate the loss function against for the training set + */ inline const std::vector<double> prop_train_copy() const {return _prop_train;} + + /** + * @brief Copy of the value of the property to evaluate the loss function against for the test set + */ inline const std::vector<double> prop_test_copy() const {return _prop_test;} + /** + * @brief Copy of the estimated value of the property to evaluate the loss function against for the training set + */ inline const std::vector<double> prop_train_est_copy() const {return _prop_train_est;} + + /** + * @brief Copy of the estimated value of the property to evaluate the loss function against for the test set + */ inline const std::vector<double> prop_test_est_copy() const {return _prop_test_est;} + /** + * @brief Copy of the property vector used for projection + */ inline const std::vector<double> prop_project_copy() const {return _projection_prop;} + /** + * @brief Pointer to the head of the value of the property to evaluate the loss function against for the training set + */ inline const double* prop_pointer() const {return _prop_train.data();} + + /** + * @brief Pointer to the head of the value of the property to evaluate the loss function against for the test set + */ inline const double* prop_test_pointer() const {return _prop_test.data();} + /** + * @brief Pointer to the head of the estimated value of the property to evaluate the loss function against for the training set + */ inline const double* prop_est_pointer() const {return _prop_train_est.data();} + + /** + * @brief Pointer to the head of the estimated value of the property to evaluate the loss function against for the test set + */ inline const double* prop_test_est_pointer() const {return _prop_test_est.data();} + /** + * @brief Pointer to the head of the property vector used for projection + */ inline const double* prop_project_pointer() const {return _projection_prop.data();} + /** + * @brief The error vector for the training set + */ inline const std::vector<double>& error_train() const {return _error_train;} + + /** + * @brief The error vector for the test set + */ inline const std::vector<double>& error_test() const {return _error_test;} + /** + * @brief Copy of the error vector for the training set + */ inline const std::vector<double> error_train_copy() const {return _error_train;} + + /** + * @brief Copy of the error vector for the test set + */ inline const std::vector<double> error_test_copy() const {return _error_test;} + /** + * @brief If true, then the bias term is fixed at 0 + */ inline bool fix_intercept() const {return _fix_intercept;} + + /** + * @brief Number features in the linear model + */ inline int n_feat() const {return _n_feat;} + + /** + * @brief Total number of constants to fit (scale and bias terms) + */ inline int n_dim() const {return _n_dim;} + + /** + * @brief Number of samples in the training setCoefficients for the linear model + */ inline int n_samp() const {return _n_samp;} + + /** + * @brief Number of samples in the test setCoefficients for the linear model + */ inline int n_samp_test() const {return _n_samp_test;} + + /** + * @brief Number of tasks + */ inline int n_task() const {return _n_task;} + + /** + * @brief Set the number of features and linear model constants to those for the new n_feat + * + * @param n_feat The updated number of features for the model + */ virtual inline void set_nfeat(int n_feat){_n_feat = n_feat; _n_dim = n_feat + (!_fix_intercept);} + /** + * @brief The number of classes in the calculation + */ virtual inline int n_class(){return 0;} }; diff --git a/src/loss_function/LossFunctionConvexHull.cpp b/src/loss_function/LossFunctionConvexHull.cpp index 432b475e9a3692fa746035e3400232a3c1618f53..12a7b743ce5516a01b26336cc95e226ddf2d358a 100644 --- a/src/loss_function/LossFunctionConvexHull.cpp +++ b/src/loss_function/LossFunctionConvexHull.cpp @@ -160,7 +160,7 @@ void LossFunctionConvexHull::setup_lp() std::copy_n(n_samp_per_class.begin() + tt * _n_class, _n_class, samp_per_class.begin()); task_start += _task_sizes_train[tt]; - std::vector<int> n_test_samp_per_class(n_samp_per_class.size(), 0); + std::vector<int> n_samp_test_per_class(n_samp_per_class.size(), 0); if(_task_sizes_test[tt] > 0) { inds.resize(_task_sizes_test[tt]); @@ -174,13 +174,13 @@ void LossFunctionConvexHull::setup_lp() _test_sample_inds_to_sorted_dmat_inds[inds[ii]] = ii + task_start_test; if(_prop_test[inds[ii]] != _prop_test[inds[ii - 1]]) { - n_test_samp_per_class[ + n_samp_test_per_class[ rep_class[_prop_test[inds[ii - 1]]] ] = ii - cls_start; cls_start = ii; } } - n_test_samp_per_class[rep_class[_prop_test[inds.back()]]] = inds.size() - cls_start; + n_samp_test_per_class[rep_class[_prop_test[inds.back()]]] = inds.size() - cls_start; task_start_test += _task_sizes_test[tt]; } @@ -191,8 +191,8 @@ void LossFunctionConvexHull::setup_lp() _n_feat, std::accumulate(n_samp_per_class.begin(), n_samp_per_class.end(), 0), _width, - n_test_samp_per_class, - std::accumulate(n_test_samp_per_class.begin(), n_test_samp_per_class.end(), 0) + n_samp_test_per_class, + std::accumulate(n_samp_test_per_class.begin(), n_samp_test_per_class.end(), 0) ); _lp.push_back(lp); } diff --git a/src/loss_function/LossFunctionConvexHull.hpp b/src/loss_function/LossFunctionConvexHull.hpp index 84932a98ae57a53d6df8c6855e21e20b41d95035..061acfe609f21b0da53fa39beca9d7d4e7b5a871 100644 --- a/src/loss_function/LossFunctionConvexHull.hpp +++ b/src/loss_function/LossFunctionConvexHull.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file loss_function/LossFunctionConvexHull.hpp - * @brief A class used to calculate the projection score and l0-regularization error + * @brief A class used to calculate the projection score and l0-regularization error * * @author Thomas A. R. Purcell (tpurcell) * @bug No known bugs. @@ -32,14 +32,14 @@ class LossFunctionConvexHull: public LossFunction { protected: - std::vector<ConvexHull1D> _convex_hull; - std::vector<LPWrapper> _lp; - std::vector<double> _scores; + std::vector<ConvexHull1D> _convex_hull; //!< Vector to the convex hull objects for projection + std::vector<LPWrapper> _lp; //!< Vector for calculating the LP-optimization + std::vector<double> _scores; //!< The scores for each of the projection properties std::map<int, int> _sample_inds_to_sorted_dmat_inds; //!< map from input sample inds to the SORTED_D_MATRIX_INDS std::map<int, int> _test_sample_inds_to_sorted_dmat_inds; //!< map from input sample inds to the SORTED_D_MATRIX_INDS - const double _width; - int _n_class; + const double _width; //!< The width used as the tolerance for the LP optimization + int _n_class; //!< Number of classes in the property public: @@ -90,8 +90,7 @@ public: LossFunctionConvexHull& operator= (LossFunctionConvexHull&& o) = default; /** - * @brief Setup the _lp objects - * @details This is used for calculating the LossFunction + * @brief Initialize the LPWrappers used for calculating the loss function */ void setup_lp(); @@ -133,17 +132,27 @@ public: virtual double test_loss(const std::vector<model_node_ptr>& feats); /** - * @brief Set the model list from the previous generation - * @details [long description] + * @brief Reset the the property used for projection * - * @param model_list [description] + * @param model_list The models used to update the projection property */ void reset_projection_prop(const std::vector<std::vector<model_node_ptr>>& models); + /** + * @brief The type of LossFunction + */ inline LOSS_TYPE type() const {return LOSS_TYPE::CONVEX_HULL;} + /** + * @brief Set the number of features and linear model constants to those for the new n_feat + * + * @param n_feat The updated number of features for the model + */ void set_nfeat(int n_feat); + /** + * @brief The number of classes in the calculation + */ inline int n_class(){return _n_class;} }; diff --git a/src/loss_function/LossFunctionLogPearsonRMSE.hpp b/src/loss_function/LossFunctionLogPearsonRMSE.hpp index c5f111c85e1ec066160f3cc96a215856c42ac695..1d1d6f4cf59d1bba4dc97d04fed5f6d397d92bce 100644 --- a/src/loss_function/LossFunctionLogPearsonRMSE.hpp +++ b/src/loss_function/LossFunctionLogPearsonRMSE.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file loss_function/LossFunctionLogPearsonRMSE.hpp - * @brief A class used to calculate the projection score and l0-regularization error + * @brief A class used to calculate the projection score and l0-regularization error * * @author Thomas A. R. Purcell (tpurcell) * @bug No known bugs. @@ -26,7 +26,7 @@ class LossFunctionLogPearsonRMSE: public LossFunctionPearsonRMSE { protected: - std::vector<double> _log_feat; + std::vector<double> _log_feat; //!< A feature to store the log of the Features' data public: @@ -86,43 +86,53 @@ public: double project(const node_ptr& feat); /** - * @brief Set the _a matrix + * @brief Set the A matrix used for solving the least squares regression * - * @param inds Indexes to access the central storage area + * @param inds A vector storing the _d_mat_ind of the features to pull data from the Descriptor Matrix storage array + * @param taskind The task for used for the least squares regression + * @param start The offset needed from the head of the feature's training data to where the task starts */ void set_a(const std::vector<int>& inds, int taskind, int start); /** - * @brief Set the _a matrix + * @brief Set the A matrix used for solving the least squares regression * * @param feats The features used to evaluate the loss function + * @param taskind The task for used for the least squares regression + * @param start The offset needed from the head of the feature's training data to where the task starts */ void set_a(const std::vector<model_node_ptr>& feats, int taskind, int start); /** - * @brief Set the error and return the RMSE + * @brief Set the error vector * * @param inds Indexes to access the central storage area - * @return The RMSE of the model + * @param taskind The task for used for the least squares regression + * @param start The offset needed from the head of the feature's training data to where the task starts */ void set_prop_train_est(const std::vector<int>& inds, int taskind, int start); /** - * @brief Set the error and return the RMSE + * @brief Set the error * - * @param feats The features used to evaluate the loss function for the test set - * @return The test RMSE of the feature + * @param feats The features used to evaluate the loss function + * @param taskind The task for used for the least squares regression + * @param start The offset needed from the head of the feature's training data to where the task starts */ void set_prop_train_est(const std::vector<model_node_ptr>& feats, int taskind, int start); /** - * @brief Set the error and return the RMSE + * @brief Set the test error and return the RMSE * - * @param feats The features used to evaluate the loss function - * @return The RMSE of the model + * @param feats The features used to evaluate the loss function for the test data + * @param taskind The task for used for the least squares regression + * @param start The offset needed from the head of the feature's test data to where the task starts */ void set_prop_test_est(const std::vector<model_node_ptr>& feats, int taskind, int start); + /** + * @brief The type of LossFunction + */ inline LOSS_TYPE type() const {return LOSS_TYPE::LOG_PEARSON_RMSE;} }; diff --git a/src/loss_function/LossFunctionPearsonRMSE.hpp b/src/loss_function/LossFunctionPearsonRMSE.hpp index fb5340f3620302238cc86501e368e47f429640f4..dc35023ca27d70492aa33ec635bcf6c6c8cf242b 100644 --- a/src/loss_function/LossFunctionPearsonRMSE.hpp +++ b/src/loss_function/LossFunctionPearsonRMSE.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file loss_function/LossFunctionPearsonRMSE.hpp - * @brief A class used to calculate the projection score and l0-regularization error + * @brief A class used to calculate the projection score and l0-regularization error * * @author Thomas A. R. Purcell (tpurcell) * @bug No known bugs. @@ -134,59 +134,76 @@ public: void set_opt_lwork(); /** - * @brief Set the _a matrix + * @brief Set the A matrix used for solving the least squares regression * - * @param inds Indexes to access the central storage area + * @param inds A vector storing the _d_mat_ind of the features to pull data from the Descriptor Matrix storage array + * @param taskind The task for used for the least squares regression + * @param start The offset needed from the head of the feature's training data to where the task starts */ virtual void set_a(const std::vector<int>& inds, int taskind, int start); /** - * @brief Set the _a matrix + * @brief Set the A matrix used for solving the least squares regression * * @param feats The features used to evaluate the loss function + * @param taskind The task for used for the least squares regression + * @param start The offset needed from the head of the feature's training data to where the task starts */ virtual void set_a(const std::vector<model_node_ptr>& feats, int taskind, int start); /** - * @brief Set the error and return the RMSE + * @brief Set the error vector * * @param inds Indexes to access the central storage area - * @return The RMSE of the model + * @param taskind The task for used for the least squares regression + * @param start The offset needed from the head of the feature's training data to where the task starts */ virtual void set_prop_train_est(const std::vector<int>& inds, int taskind, int start); /** - * @brief Set the error and return the RMSE + * @brief Set the error * * @param feats The features used to evaluate the loss function - * @return The RMSE of the model + * @param taskind The task for used for the least squares regression + * @param start The offset needed from the head of the feature's training data to where the task starts */ virtual void set_prop_train_est(const std::vector<model_node_ptr>& feats, int taskind, int start); - /** - * @brief Set the error and return the RMSE + /** + * @brief Set the test error and return the RMSE * - * @param feats The features used to evaluate the loss function for the test set - * @return The test RMSE of the feature + * @param feats The features used to evaluate the loss function for the test data + * @param taskind The task for used for the least squares regression + * @param start The offset needed from the head of the feature's test data to where the task starts */ virtual void set_prop_test_est(const std::vector<model_node_ptr>& feats, int taskind, int start); /** * @brief Perform least squares regression * + * @param taskind The task for used for the least squares regression + * @param start The offset needed from the head of the feature's test data to where the task starts * @return info The final info value from dgels */ int least_squares(int taskind, int start); /** - * @brief Set the model list from the previous generation - * @details [long description] + * @brief Reset the the property used for projection * - * @param model_list [description] + * @param model_list The models used to update the projection property */ void reset_projection_prop(const std::vector<std::vector<model_node_ptr>>& models); + /** + * @brief The type of LossFunction + */ virtual inline LOSS_TYPE type() const {return LOSS_TYPE::PEARSON_RMSE;} + + /** + * @brief Set the number of features and linear model constants to those for the new n_feat + * + * @param n_feat The updated number of features for the model + */ void set_nfeat(int n_feat); }; diff --git a/src/loss_function/utils.hpp b/src/loss_function/utils.hpp index 3359719e47d83bc3daab42ec6cb1890b01e31bdb..80da1d57edf93be100e426b6ab7506878b25a1fd 100644 --- a/src/loss_function/utils.hpp +++ b/src/loss_function/utils.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file loss_function/utils.hpp - * @brief utilities for generating loss_functions + * @brief utilities for generating loss_functions * * @author Thomas A. R. Purcell (tpurcell) * @bug No known bugs. @@ -27,6 +27,17 @@ namespace loss_function_util { +/** + * Create a shared_ptr to a new LossFunction + * + * @param type The type of LossFunction to create + * @param prop_train The value of the property to evaluate the loss function against for the training set + * @param prop_test The value of the property to evaluate the loss function against for the test set + * @param task_sizes_train Number of training samples per task + * @param task_sizes_test Number of testing samples per task + * @param fix_intercept If true then the bias term is fixed at 0 + * @return A shared_ptr to the newly created LossFunction + */ std::shared_ptr<LossFunction> get_loss_function( std::string type, std::vector<double> prop_train, @@ -36,6 +47,12 @@ std::shared_ptr<LossFunction> get_loss_function( bool fix_intercept = false ); +/** + * @brief Make a copy of a LossFunction and return a shared_ptr to it + * + * @param loss A shared_ptr to the LossFunction to be copied + * @return The shared_ptr to the copied LossFunction + */ std::shared_ptr<LossFunction> copy(std::shared_ptr<LossFunction> loss); }; diff --git a/src/mpi_interface/MPI_Interface.hpp b/src/mpi_interface/MPI_Interface.hpp index c7f8f2a852616e2bf58192f529632b856b4c6c7c..9f607f1a7eaec332a3947c06091fe8ca29d42f89 100644 --- a/src/mpi_interface/MPI_Interface.hpp +++ b/src/mpi_interface/MPI_Interface.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file mpi_interface/MPI_Interface.hpp - * @brief Define MPI interface for the calculation + * @brief Define MPI interface for the calculation * * This class modifies the boost mpi::communicator for easier communication * @@ -27,7 +27,6 @@ namespace mpi = boost::mpi; -// Augment the boost mpi communicator class with some other useful data /** * @brief Augment the boost MPI communicator class with some other useful data * @details MPI communicator used to transfer data throughout the cell. diff --git a/src/mpi_interface/MPI_ops.hpp b/src/mpi_interface/MPI_ops.hpp index 5144ff184be30e3ddfcd9f6c26ff5320366d129a..d5fd50b4a44c4321507150776e40c428f21e0039 100644 --- a/src/mpi_interface/MPI_ops.hpp +++ b/src/mpi_interface/MPI_ops.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file mpi_interface/MPI_Ops.hpp - * @brief Define MPI reduce all operator to facilitate a distributed sorting algorithm + * @brief Define MPI reduce all operator to facilitate a distributed sorting algorithm * * This is based off of a project from Meisam Farzalipour Tabriz at the MPCDF (mpi_topk) * diff --git a/src/nl_opt/NLOptWrapper.hpp b/src/nl_opt/NLOptWrapper.hpp index ad7738a7a8604b876b54913b119016e0c42f8de1..8a99a773933e2de00cefe2d2bd7cd4e5b495f4e7 100644 --- a/src/nl_opt/NLOptWrapper.hpp +++ b/src/nl_opt/NLOptWrapper.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file feature_creation/parameterization/NLOptWrapper.hpp - * @brief Wrapper and functions to use libnlopt to find parameterizations for features + * @brief Wrapper and functions to use libnlopt to find parameterizations for features * * @author Thomas A. R. Purcell (tpurcell) * @bug No known bugs. @@ -29,24 +29,24 @@ class NLOptimizer protected: const nlopt::func _objective; //!< Objective function to use - std::vector<double> _a; //!< vector to store the A matrix for dgels - std::vector<double> _params; //!< The working parameters vector - std::vector<double> _lb_init; //!< The lower bound for the global optimization - std::vector<double> _ub_init; //!< The upper bound for the global optimization - std::vector<double> _lb_final; //!< The lower bound for the local optimization - std::vector<double> _ub_final; //!< The upper bound for the local optimization - const std::vector<double> _prop; //!< The property to fit the functions against - std::vector<double> _prop_copy; //!< Copy of the property to keep for dgels - std::vector<double> _work; //!< work array for dgels - const std::vector<double> _zeros; //!< array of zeros to fill parameters - const std::vector<int> _task_sizes; //!< number of samples in each task + std::vector<double> _a; //!< The A matrix used for calculating the least squares solution of the problem + std::vector<double> _params; //!< The scale and bias terms for the OperatorNode + std::vector<double> _lb_init; //!< The lower bound for the scale and bias terms during the global optimization + std::vector<double> _ub_init; //!< The upper bound for the scale and bias terms during the global optimization + std::vector<double> _lb_final; //!< The lower bound for the scale and bias terms during the local optimization + std::vector<double> _ub_final; //!< The upper bound for the scale and bias terms during the local optimization + const std::vector<double> _prop; //!< The value of the property to evaluate the loss function against for the training set + std::vector<double> _prop_copy; //!< A copy of the value of the property to evaluate the loss function against for the training set + std::vector<double> _work; //!< Work vector for dgels + const std::vector<double> _zeros; //!< A vector filled with zeros to fill parameters + const std::vector<int> _task_sizes; //!< Number of training samples per task std::vector<bool> _free_param; //!< Elements are true if parameter is free - const int _n_samp; //!< total number of samples + const int _n_samp; //!< Total number of samples const int _n_rung; //!< Maximum rung of the features const int _n_prop; //!< Number of property vectors to optimize against int _max_params; //!< Maximum number of possible parameters - int _max_param_depth; //!< parameterize features to all depths of the tree + int _max_param_depth; //!< The maximum depth in the binary expression tree to set non-linear optimization nlopt::algorithm _local_opt_alg; //!< Algorithm used for local optimization @@ -54,12 +54,13 @@ public: /** * @brief Constructor * - * @param task_sizes number of samples in each task - * @param prop The property to fit the functions against + * @param task_sizes Number of training samples per task + * @param prop The value of the property to evaluate the loss function against for the training set * @param n_rung Maximum rung of the features - * @param objective The objective function to use - * @param max_param_depth maximum depth of the binary expression tress to parameterize from the root + * @param objective The objective function to use for the optimization + * @param max_param_depth The maximum depth in the binary expression tree to set non-linear optimization * @param reset_max_param_depth If true reset the maximum parameter depth + * @param local_opt_alg Algorithm used for local optimization */ NLOptimizer( const std::vector<int>& task_sizes, @@ -75,54 +76,52 @@ public: /** * @brief uses nlopt to optimize the parameters of a feature * - * @param feat pointer to the node to optimize - * @param use_grad If true use a gradient based optimizer (LD_VAR2) for local optimization - * Otherwise use a simplex based approach (LN_SBPLX) if possible + * @param feat Pointer to the node to optimize */ double optimize_feature_params(Node* feat); /** - * @brief Accessor function to the task sizes + * @brief The number of training samples per task */ inline const std::vector<int>& task_sizes() const {return _task_sizes;} /** - * @brief Accessor function to the the property vector + * @brief The value of the property to evaluate the loss function against for the training set */ inline const std::vector<double>& prop() const {return _prop;} /** - * @brief Accessor function to the pointer of the work vector's start + * @brief Work vector for dgels */ inline double* work(){return _work.data();} /** - * @brief Accessor function to the number of samples + * @brief Total number of samples */ inline int n_samp() const {return _n_samp;} /** - * @brief Accessor function to the maximum number of rungs + * @brief Maximum rung of the features */ inline int n_rung() const {return _n_rung;} /** - * @brief Accessor function to the number of property vectors + * @brief Number of property vectors to optimize against */ inline int n_prop() const {return _n_prop;} /** - * @brief Accessor function to the maximum number of possible parameters + * @brief Maximum number of possible parameters */ inline int max_params() const {return _max_params;} /** - * @brief Accessor function to the maximum parameter depth + * @brief The maximum depth in the binary expression tree to set non-linear optimization */ inline int max_param_depth() const {return _max_param_depth;} /** - * @brief Accessor function to the default local optimization algorithm + * @brief Algorithm used for local optimization */ inline nlopt::algorithm local_opt_alg () const {return _local_opt_alg;} @@ -135,19 +134,28 @@ public: inline bool free_param(int pp){return _free_param[pp];} /** - * @brief Accessor function to the convex hull optimizers (if the projection is a classification problem) + * @brief Access one of the convex hull objects for projection (If using the Classifier) + * + * @param ind The index of the _convex_hull vector to access */ virtual std::shared_ptr<ConvexHull1D> convex_hull(int ind) const = 0; + /** - * @brief Accessor function to calculate the feature gradient + * @brief Access an element of parameter gradient for non-linear optimization + * + * @param ind The index of the gradient vector to access */ virtual double* feature_gradient(int ind) = 0; + /** - * @brief Accessor function to the pointer for the residuals + * @brief Access an element of the residuals for non-linear optimization + * + * @param ind The index of the gradient vector to access */ virtual double* residuals(int ind) = 0; + /** - * @brief Accessor function to cauchy scaling factor for regression problems + * @brief The Cauchy scaling factor for regression problems */ virtual double cauchy_scaling()const = 0; @@ -160,16 +168,17 @@ public: class NLOptimizerClassification: public NLOptimizer { protected: - std::vector<std::shared_ptr<ConvexHull1D>> _convex_hull; //!< Object to perform classification + std::vector<std::shared_ptr<ConvexHull1D>> _convex_hull; //!< A vector containing the convex hull objects for projection (If using the Classifier) public: /** * @brief Constructor * - * @param task_sizes number of samples in each task - * @param prop The property to fit the functions against + * @param task_sizes Number of training samples per task + * @param prop The value of the property to evaluate the loss function against for the training set * @param n_rung Maximum rung of the features - * @param max_param_depth maximum depth of the binary expression tress to parameterize from the root + * @param max_param_depth The maximum depth in the binary expression tree to set non-linear optimization * @param reset_max_param_depth If true reset the maximum parameter depth + * @param local_opt_alg Algorithm used for local optimization */ NLOptimizerClassification( const std::vector<int>& task_sizes, @@ -179,23 +188,30 @@ public: bool reset_max_param_depth=false, const nlopt::algorithm local_opt_alg=nlopt::LN_SBPLX ); + /** - * @brief Accessor function to the convex hull optimizers (if the projection is a classification problem) + * @brief Access one of the convex hull objects for projection (If using the Classifier) + * + * @param ind The index of the _convex_hull vector to access */ inline std::shared_ptr<ConvexHull1D> convex_hull(int ind) const {return _convex_hull[ind];} /** - * @brief Accessor function to the feature gradient (always nullptr) + * @brief Access an element of parameter gradient for non-linear optimization + * + * @param ind The index of the gradient vector to access */ inline double* feature_gradient(int ind){return nullptr;} /** - * @brief Accessor function to the residuals (always nullptr) + * @brief Access an element of the residuals for non-linear optimization + * + * @param ind The index of the gradient vector to access */ inline double* residuals(int ind){return nullptr;} /** - * @brief Accessor function to the cauchy scaling factor (always nullptr) + * @brief The Cauchy scaling factor for regression problems */ inline double cauchy_scaling() const {return 0.0;} @@ -212,16 +228,19 @@ protected: std::vector<double> _residuals; //!< storage space for the residuals const double _cauchy_scaling; //!< Scaling factor for calculating the cauchy loss function public: + /** * @brief Constructor * - * @param task_sizes number of samples in each task - * @param prop The property to fit the functions against + * @param task_sizes Number of training samples per task + * @param prop The value of the property to evaluate the loss function against for the training set * @param n_rung Maximum rung of the features - * @param max_param_depth maximum depth of the binary expression tress to parameterize from the root - * @param cauchy_scaling the Cauchy scale factor used for calculating the residuals + * @param objective The objective function to use for the optimization + * @param max_param_depth The maximum depth in the binary expression tree to set non-linear optimization + * @param cauchy_scaling The Cauchy scale factor used for calculating the residuals * @param log_reg True if the optimizer is for a log regressor * @param reset_max_param_depth If true reset the maximum parameter depth + * @param local_opt_alg Algorithm used for local optimization */ NLOptimizerRegression( const std::vector<int>& task_sizes, @@ -235,22 +254,28 @@ public: ); /** - * @brief Accessor function to the convex hull optimizers (always nullptr) + * @brief Access one of the convex hull objects for projection (If using the Classifier) + * + * @param ind The index of the _convex_hull vector to access */ inline std::shared_ptr<ConvexHull1D> convex_hull(int ind) const{return nullptr;} /** - * @brief Accessor function to the feature gradient + * @brief Access an element of parameter gradient for non-linear optimization + * + * @param ind The index of the gradient vector to access */ inline double* feature_gradient(int ind){return &_feature_gradient[ind];} /** - * @brief Accessor function to the residuals + * @brief Access an element of the residuals for non-linear optimization + * + * @param ind The index of the gradient vector to access */ inline double* residuals(int ind){return &_residuals[ind];} /** - * @brief Accessor function to the cauchy scaling factor + * @brief The Cauchy scaling factor for regression problems */ inline double cauchy_scaling() const {return _cauchy_scaling;} @@ -267,12 +292,13 @@ public: /** * @brief Constructor * - * @param task_sizes number of samples in each task - * @param prop The property to fit the functions against + * @param task_sizes Number of training samples per task + * @param prop The value of the property to evaluate the loss function against for the training set * @param n_rung Maximum rung of the features - * @param max_param_depth maximum depth of the binary expression tress to parameterize from the root - * @param cauchy_scaling the Cauchy scale factor used for calculating the residuals + * @param max_param_depth The maximum depth in the binary expression tree to set non-linear optimization + * @param cauchy_scaling The Cauchy scale factor used for calculating the residuals * @param reset_max_param_depth If true reset the maximum parameter depth + * @param local_opt_alg Algorithm used for local optimization */ NLOptimizerLogRegression( const std::vector<int>& task_sizes, @@ -292,13 +318,13 @@ public: namespace nlopt_wrapper { -extern int MAX_PARAM_DEPTH; //!< The maximum parameter depth for the problem -extern int NLOPT_SEED; //!< The seed used to initialize the nlopt psuedorandom number seed -extern bool USE_GLOBAL; //!< If true then use global optimization when optimizing features +extern int MAX_PARAM_DEPTH; //!< The maximum depth in the binary expression tree to set non-linear optimization +extern int NLOPT_SEED; //!< The seed used for the nlOpt library +extern bool USE_GLOBAL; //!< True if global optimization is requested for non-linear optimization of parameters (Can break reproducibility) typedef struct { - const double* _prop; //!< pointer to the property vector + const double* _prop; //!< A pointer to the value of the property to evaluate the loss function against for the training set Node* _feat; //!< Node pointer of the feature to parameterize NLOptimizer* _optimizer; //!< Data structure to store information for the optimization } feat_data; @@ -340,12 +366,12 @@ static double objective_log_reg(unsigned int n, const double* p, double* grad, v * @brief Get an optimizer for the desired task * * @param project_type The type of projection operator to optimize the features for - * @param task_sizes number of samples in each task - * @param prop The property to fit the functions against + * @param task_sizes Number of training samples per task + * @param prop The value of the property to evaluate the loss function against for the training set * @param n_rung Maximum rung of the features - * @param max_param_depth maximum depth of the binary expression tress to parameterize from the root - * @param cauchy_scaling scaling factor used for the Cauchy loss function - * @param reset_max_param_depth If true reset the maximum parameter depth + * @param max_param_depth The maximum depth in the binary expression tree to set non-linear optimization + * @param cauchy_scaling The Cauchy scale factor used for calculating the residuals + * @param max_param_depth The maximum depth in the binary expression tree to set non-linear optimization * * @return The correct optimizer */ @@ -364,12 +390,12 @@ std::shared_ptr<NLOptimizer> get_optimizer( /** * @brief Get an optimizer for the desired task * - * @param task_sizes number of samples in each task - * @param prop The property to fit the functions against + * @param task_sizes Number of training samples per task + * @param prop The value of the property to evaluate the loss function against for the training set * @param n_rung Maximum rung of the features - * @param max_param_depth maximum depth of the binary expression tress to parameterize from the root - * @param cauchy_scaling scaling factor used for the Cauchy loss function - * @param use_global If true use global optimization + * @param max_param_depth The maximum depth in the binary expression tree to set non-linear optimization + * @param cauchy_scaling The Cauchy scale factor used for calculating the residuals + * @param use_global True if global optimization is requested for non-linear optimization of parameters (Can break reproducibility) * * @return The correct optimizer */ @@ -400,12 +426,12 @@ inline NLOptimizerRegression get_reg_optimizer( /** * @brief Get an optimizer for the desired task * - * @param task_sizes number of samples in each task - * @param prop The property to fit the functions against + * @param task_sizes Number of training samples per task + * @param prop The value of the property to evaluate the loss function against for the training set * @param n_rung Maximum rung of the features - * @param max_param_depth maximum depth of the binary expression tress to parameterize from the root - * @param cauchy_scaling scaling factor used for the Cauchy loss function - * @param use_global If true use global optimization + * @param max_param_depth The maximum depth in the binary expression tree to set non-linear optimization + * @param cauchy_scaling The Cauchy scale factor used for calculating the residuals + * @param use_global True if global optimization is requested for non-linear optimization of parameters (Can break reproducibility) * * @return The correct optimizer */ @@ -436,12 +462,12 @@ inline NLOptimizerRegression get_reg_optimizer( /** * @brief Get an optimizer for the desired task * - * @param task_sizes number of samples in each task - * @param prop The property to fit the functions against + * @param task_sizes Number of training samples per task + * @param prop The value of the property to evaluate the loss function against for the training set * @param n_rung Maximum rung of the features - * @param max_param_depth maximum depth of the binary expression tress to parameterize from the root - * @param cauchy_scaling scaling factor used for the Cauchy loss function - * @param use_global If true use global optimization + * @param max_param_depth The maximum depth in the binary expression tree to set non-linear optimization + * @param cauchy_scaling The Cauchy scale factor used for calculating the residuals + * @param use_global True if global optimization is requested for non-linear optimization of parameters (Can break reproducibility) * * @return The correct optimizer */ @@ -472,12 +498,12 @@ inline NLOptimizerRegression get_reg_optimizer( /** * @brief Get an optimizer for the desired task * - * @param task_sizes number of samples in each task - * @param prop The property to fit the functions against + * @param task_sizes Number of training samples per task + * @param prop The value of the property to evaluate the loss function against for the training set * @param n_rung Maximum rung of the features - * @param max_param_depth maximum depth of the binary expression tress to parameterize from the root - * @param cauchy_scaling scaling factor used for the Cauchy loss function - * @param use_global If true use global optimization + * @param max_param_depth The maximum depth in the binary expression tree to set non-linear optimization + * @param cauchy_scaling The Cauchy scale factor used for calculating the residuals + * @param use_global True if global optimization is requested for non-linear optimization of parameters (Can break reproducibility) * * @return The correct optimizer */ @@ -508,12 +534,12 @@ inline NLOptimizerRegression get_reg_optimizer( /** * @brief Get an optimizer for the desired task * - * @param task_sizes number of samples in each task - * @param prop The property to fit the functions against + * @param task_sizes Number of training samples per task + * @param prop The value of the property to evaluate the loss function against for the training set * @param n_rung Maximum rung of the features - * @param max_param_depth maximum depth of the binary expression tress to parameterize from the root - * @param scaling factor used for the Cauchy loss function - * @param use_global If true use global optimization + * @param max_param_depth The maximum depth in the binary expression tree to set non-linear optimization + * @param cauchy_scaling The Cauchy scale factor used for calculating the residuals + * @param use_global True if global optimization is requested for non-linear optimization of parameters (Can break reproducibility) * * @return The correct optimizer */ @@ -543,12 +569,12 @@ inline NLOptimizerLogRegression get_log_reg_optimizer( /** * @brief Get an optimizer for the desired task * - * @param task_sizes number of samples in each task - * @param prop The property to fit the functions against + * @param task_sizes Number of training samples per task + * @param prop The value of the property to evaluate the loss function against for the training set * @param n_rung Maximum rung of the features - * @param max_param_depth maximum depth of the binary expression tress to parameterize from the root - * @param scaling factor used for the Cauchy loss function - * @param use_global If true use global optimization + * @param max_param_depth The maximum depth in the binary expression tree to set non-linear optimization + * @param cauchy_scaling The Cauchy scale factor used for calculating the residuals + * @param use_global True if global optimization is requested for non-linear optimization of parameters (Can break reproducibility) * * @return The correct optimizer */ @@ -578,12 +604,12 @@ inline NLOptimizerLogRegression get_log_reg_optimizer( /** * @brief Get an optimizer for the desired task * - * @param task_sizes number of samples in each task - * @param prop The property to fit the functions against + * @param task_sizes Number of training samples per task + * @param prop The value of the property to evaluate the loss function against for the training set * @param n_rung Maximum rung of the features - * @param max_param_depth maximum depth of the binary expression tress to parameterize from the root - * @param scaling factor used for the Cauchy loss function - * @param use_global If true use global optimization + * @param max_param_depth The maximum depth in the binary expression tree to set non-linear optimization + * @param cauchy_scaling The Cauchy scale factor used for calculating the residuals + * @param use_global True if global optimization is requested for non-linear optimization of parameters (Can break reproducibility) * * @return The correct optimizer */ @@ -613,12 +639,12 @@ inline NLOptimizerLogRegression get_log_reg_optimizer( /** * @brief Get an optimizer for the desired task * - * @param task_sizes number of samples in each task - * @param prop The property to fit the functions against + * @param task_sizes Number of training samples per task + * @param prop The value of the property to evaluate the loss function against for the training set * @param n_rung Maximum rung of the features - * @param max_param_depth maximum depth of the binary expression tress to parameterize from the root - * @param scaling factor used for the Cauchy loss function - * @param use_global If true use global optimization + * @param max_param_depth The maximum depth in the binary expression tree to set non-linear optimization + * @param cauchy_scaling The Cauchy scale factor used for calculating the residuals + * @param use_global True if global optimization is requested for non-linear optimization of parameters (Can break reproducibility) * * @return The correct optimizer */ @@ -648,11 +674,11 @@ inline NLOptimizerLogRegression get_log_reg_optimizer( /** * @brief Get an optimizer for the desired task * - * @param task_sizes number of samples in each task - * @param prop The property to fit the functions against + * @param task_sizes Number of training samples per task + * @param prop The value of the property to evaluate the loss function against for the training set * @param n_rung Maximum rung of the features - * @param max_param_depth maximum depth of the binary expression tress to parameterize from the root - * @param use_global If true use global optimization + * @param max_param_depth The maximum depth in the binary expression tree to set non-linear optimization + * @param use_global True if global optimization is requested for non-linear optimization of parameters (Can break reproducibility) * * @return The correct optimizer */ @@ -680,11 +706,11 @@ inline NLOptimizerClassification get_class_optimizer( /** * @brief Get an optimizer for the desired task * - * @param task_sizes number of samples in each task - * @param prop The property to fit the functions against + * @param task_sizes Number of training samples per task + * @param prop The value of the property to evaluate the loss function against for the training set * @param n_rung Maximum rung of the features - * @param max_param_depth maximum depth of the binary expression tress to parameterize from the root - * @param use_global If true use global optimization + * @param max_param_depth The maximum depth in the binary expression tree to set non-linear optimization + * @param use_global True if global optimization is requested for non-linear optimization of parameters (Can break reproducibility) * * @return The correct optimizer */ @@ -712,11 +738,11 @@ inline NLOptimizerClassification get_class_optimizer( /** * @brief Get an optimizer for the desired task * - * @param task_sizes number of samples in each task - * @param prop The property to fit the functions against + * @param task_sizes Number of training samples per task + * @param prop The value of the property to evaluate the loss function against for the training set * @param n_rung Maximum rung of the features - * @param max_param_depth maximum depth of the binary expression tress to parameterize from the root - * @param use_global If true use global optimization + * @param max_param_depth The maximum depth in the binary expression tree to set non-linear optimization + * @param use_global True if global optimization is requested for non-linear optimization of parameters (Can break reproducibility) * * @return The correct optimizer */ @@ -744,11 +770,11 @@ inline NLOptimizerClassification get_class_optimizer( /** * @brief Get an optimizer for the desired task * - * @param task_sizes number of samples in each task - * @param prop The property to fit the functions against + * @param task_sizes Number of training samples per task + * @param prop The value of the property to evaluate the loss function against for the training set * @param n_rung Maximum rung of the features - * @param max_param_depth maximum depth of the binary expression tress to parameterize from the root - * @param use_global If true use global optimization + * @param max_param_depth The maximum depth in the binary expression tree to set non-linear optimization + * @param use_global True if global optimization is requested for non-linear optimization of parameters (Can break reproducibility) * * @return The correct optimizer */ diff --git a/src/python/py_binding_cpp_def/bindings_docstring_keyed.cpp b/src/python/py_binding_cpp_def/bindings_docstring_keyed.cpp index bc07614d092b61d825d5cca2608c7f84e790af44..f65a77a8b7d66cef0ca5bfcfc7d86df0da71b727 100644 --- a/src/python/py_binding_cpp_def/bindings_docstring_keyed.cpp +++ b/src/python/py_binding_cpp_def/bindings_docstring_keyed.cpp @@ -164,9 +164,9 @@ void sisso::feature_creation::registerFeatureSpace() arg("allowed_param_ops"), arg("prop"), arg("project_type")="regression", - arg("max_phi")=1, + arg("max_rung")=1, arg("n_sis_select")=1, - arg("max_store_rung")=-1, + arg("n_rung_store")=-1, arg("n_rung_generate")=0, arg("cross_corr_max")=1.0, arg("min_abs_feat_val")=1e-50, @@ -186,9 +186,9 @@ void sisso::feature_creation::registerFeatureSpace() arg("allowed_param_ops"), arg("prop"), arg("project_type")="regression", - arg("max_phi")=1, + arg("max_rung")=1, arg("n_sis_select")=1, - arg("max_store_rung")=-1, + arg("n_rung_store")=-1, arg("n_rung_generate")=0, arg("cross_corr_max")=1.0, arg("min_abs_feat_val")=1e-50, @@ -240,11 +240,11 @@ void sisso::feature_creation::registerFeatureSpace() .add_property("scores", &FeatureSpace::scores_py, "@DocString_feat_space_scores_py@") .add_property("task_sizes", &FeatureSpace::task_sizes_py, "@DocString_feat_space_task_sizes_py@") .add_property("allowed_ops", &FeatureSpace::allowed_ops_py, "@DocString_feat_space_allowed_ops_py@") - .add_property("start_gen", &FeatureSpace::start_gen_py, "@DocString_feat_space_start_gen_py@") + .add_property("start_rung", &FeatureSpace::start_rung_py, "@DocString_feat_space_start_rung_py@") .add_property("feature_space_file", &FeatureSpace::feature_space_file, "@DocString_feat_space_feature_space_file@") .add_property("l_bound", &FeatureSpace::l_bound, "@DocString_feat_space_l_bound@") .add_property("u_bound", &FeatureSpace::u_bound, "@DocString_feat_space_u_bound@") - .add_property("max_phi", &FeatureSpace::max_phi, "@DocString_feat_space_max_phi@") + .add_property("max_rung", &FeatureSpace::max_rung, "@DocString_feat_space_max_rung@") .add_property("n_sis_select", &FeatureSpace::n_sis_select, "@DocString_feat_space_n_sis_select@") .add_property("n_samp", &FeatureSpace::n_samp, "@DocString_feat_space_n_samp@") .add_property("n_feat", &FeatureSpace::n_feat, "@DocString_feat_space_n_feat@") @@ -261,9 +261,9 @@ void sisso::feature_creation::registerFeatureSpace() arg("allowed_ops"), arg("prop"), arg("project_type")="regression", - arg("max_phi")=1, + arg("max_rung")=1, arg("n_sis_select")=1, - arg("max_store_rung")=-1, + arg("n_rung_store")=-1, arg("n_rung_generate")=0, arg("cross_corr_max")=1.0, arg("min_abs_feat_val")=1e-50, @@ -281,9 +281,9 @@ void sisso::feature_creation::registerFeatureSpace() arg("allowed_ops"), arg("prop"), arg("project_type")="regression", - arg("max_phi")=1, + arg("max_rung")=1, arg("n_sis_select")=1, - arg("max_store_rung")=-1, + arg("n_rung_store")=-1, arg("n_rung_generate")=0, arg("cross_corr_max")=1.0, arg("min_abs_feat_val")=1e-50, @@ -334,11 +334,11 @@ void sisso::feature_creation::registerFeatureSpace() .add_property("scores", &FeatureSpace::scores_py, "@DocString_feat_space_scores_py@") .add_property("task_sizes", &FeatureSpace::task_sizes_py, "@DocString_feat_space_task_sizes_py@") .add_property("allowed_ops", &FeatureSpace::allowed_ops_py, "@DocString_feat_space_allowed_ops_py@") - .add_property("start_gen", &FeatureSpace::start_gen_py, "@DocString_feat_space_start_gen_py@") + .add_property("start_rung", &FeatureSpace::start_rung_py, "@DocString_feat_space_start_rung_py@") .add_property("feature_space_file", &FeatureSpace::feature_space_file, "@DocString_feat_space_feature_space_file@") .add_property("l_bound", &FeatureSpace::l_bound, "@DocString_feat_space_l_bound@") .add_property("u_bound", &FeatureSpace::u_bound, "@DocString_feat_space_u_bound@") - .add_property("max_phi", &FeatureSpace::max_phi, "@DocString_feat_space_max_phi@") + .add_property("max_rung", &FeatureSpace::max_rung, "@DocString_feat_space_max_rung@") .add_property("n_sis_select", &FeatureSpace::n_sis_select, "@DocString_feat_space_n_sis_select@") .add_property("n_samp", &FeatureSpace::n_samp, "@DocString_feat_space_n_samp@") .add_property("n_feat", &FeatureSpace::n_feat, "@DocString_feat_space_n_feat@") @@ -395,7 +395,7 @@ void sisso::feature_creation::registerUnit() class_<sisso::feature_creation::node::NodeWrap, boost::noncopyable>("Node", no_init) .add_property("n_samp", &Node::n_samp, "@DocString_node_n_samp@") - .add_property("n_test_samp", &Node::n_test_samp, "@DocString_node_n_test_samp@") + .add_property("n_samp_test", &Node::n_samp_test, "@DocString_node_n_samp_test@") .add_property("feat_ind", &Node::feat_ind, "@DocString_node_feat_ind@") .add_property("arr_ind", &Node::arr_ind, "@DocString_node_arr_ind@") .add_property("selected", &Node::selected, &Node::set_selected, "@DocString_node_selected@") @@ -425,7 +425,7 @@ void sisso::feature_creation::registerUnit() void (Node::*reindex_2)(unsigned long int, unsigned long int) = &Node::reindex; class_<sisso::feature_creation::node::NodeWrap, boost::noncopyable>("Node", no_init) .add_property("n_samp", &Node::n_samp, "@DocString_node_n_samp@") - .add_property("n_test_samp", &Node::n_test_samp, "@DocString_node_n_test_samp@") + .add_property("n_samp_test", &Node::n_samp_test, "@DocString_node_n_samp_test@") .add_property("feat_ind", &Node::feat_ind, "@DocString_node_feat_ind@") .add_property("arr_ind", &Node::arr_ind, "@DocString_node_arr_ind@") .add_property("selected", &Node::selected, &Node::set_selected, "@DocString_node_set_selected@") @@ -494,13 +494,13 @@ void sisso::feature_creation::node::registerModelNode() class_<ModelNode, bases<FeatureNode>>( "ModelNode", init<int, int, std::string, std::string, std::string, std::string, py::list, py::list, py::list, Unit>( - (arg("self"), arg("feat_ind"), arg("rung"), arg("expr"), arg("latex_expr"), arg("expr_postfix"), arg("matlab_fxn_expr"), arg("value"), arg("test_value"), arg("x_in_expr_list"), arg("unit")), + (arg("self"), arg("feat_ind"), arg("rung"), arg("expr"), arg("latex_expr"), arg("postfix_expr"), arg("matlab_fxn_expr"), arg("value"), arg("test_value"), arg("x_in_expr_list"), arg("unit")), "@DocString_model_node_init_list@" ) ) .def( init<int, int, std::string, std::string, std::string, std::string, np::ndarray, np::ndarray, py::list, Unit>( - (arg("self"), arg("feat_ind"), arg("rung"), arg("expr"), arg("latex_expr"), arg("expr_postfix"), arg("matlab_fxn_expr"), arg("value"), arg("test_value"), arg("x_in_expr_list"), arg("unit")), + (arg("self"), arg("feat_ind"), arg("rung"), arg("expr"), arg("latex_expr"), arg("postfix_expr"), arg("matlab_fxn_expr"), arg("value"), arg("test_value"), arg("x_in_expr_list"), arg("unit")), "@DocString_model_node_init_arr@" ) ) diff --git a/src/python/py_binding_cpp_def/bindings_docstring_keyed.hpp b/src/python/py_binding_cpp_def/bindings_docstring_keyed.hpp index fcddf2d010a143f52281262901edfc7f58a17040..a927e79778186d86aa14f01e1e335b6633f2aefa 100644 --- a/src/python/py_binding_cpp_def/bindings_docstring_keyed.hpp +++ b/src/python/py_binding_cpp_def/bindings_docstring_keyed.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file python/bindings.hpp - * @brief Definitions to convert C++ classes into python classes + * @brief Definitions to convert C++ classes into python classes * * @author Thomas A. R. Purcell (tpurcell) * @bug No known bugs. @@ -536,7 +536,7 @@ namespace sisso { struct SISSO_DI_Wrap : SISSO_DI, py::wrapper<SISSO_DI> { - inline void l0_norm(){this->get_override("l0_norm")();} + inline void l0_regularization(){this->get_override("l0_regularization")();} inline void fit(){this->get_override("fit")();} }; diff --git a/src/python/py_binding_cpp_def/conversion_utils.hpp b/src/python/py_binding_cpp_def/conversion_utils.hpp index 97ec51edcc3aa7b85e7a4779cdeeb76c3a074361..68087c9a50c9543b40305a02ccb8085f0581d7e0 100644 --- a/src/python/py_binding_cpp_def/conversion_utils.hpp +++ b/src/python/py_binding_cpp_def/conversion_utils.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file python/py_binding_cpp_def/conversion_utils.hpp - * @brief A set of functions to convert std::vectors to and from python objects + * @brief A set of functions to convert std::vectors to and from python objects * * @author Thomas A. R. Purcell (tpurcell) * @bug No known bugs. diff --git a/src/python/py_binding_cpp_def/feature_creation/FeatureNode.cpp b/src/python/py_binding_cpp_def/feature_creation/FeatureNode.cpp index 274a29eb01d97542aff3606b0d24115dab2dc7e2..54950b8f247f5a629975dfb6cb4cd7777994e840 100644 --- a/src/python/py_binding_cpp_def/feature_creation/FeatureNode.cpp +++ b/src/python/py_binding_cpp_def/feature_creation/FeatureNode.cpp @@ -23,14 +23,14 @@ FeatureNode::FeatureNode(unsigned long int feat_ind, std::string expr, np::ndarr // Automatically resize the storage arrays if(node_value_arrs::N_STORE_FEATURES == 0) { - node_value_arrs::initialize_values_arr(_n_samp, _n_test_samp, 1, 0); + node_value_arrs::initialize_values_arr(_n_samp, _n_samp_test, 1, 0); } - else if((_n_samp != node_value_arrs::N_SAMPLES) || (_n_test_samp != node_value_arrs::N_SAMPLES_TEST)) + else if((_n_samp != node_value_arrs::N_SAMPLES) || (_n_samp_test != node_value_arrs::N_SAMPLES_TEST)) { throw std::logic_error( "Number of samples in current feature is not the same as the others, (" + std::to_string(_n_samp) + - " and " + std::to_string(_n_test_samp) + + " and " + std::to_string(_n_samp_test) + " vs. " + std::to_string(node_value_arrs::N_SAMPLES) + " and " + @@ -57,15 +57,15 @@ FeatureNode::FeatureNode(unsigned long int feat_ind, std::string expr, py::list // Automatically resize the storage arrays if(node_value_arrs::N_STORE_FEATURES == 0) { - node_value_arrs::initialize_values_arr(_n_samp, _n_test_samp, 1, 0); + node_value_arrs::initialize_values_arr(_n_samp, _n_samp_test, 1, 0); } - else if((_n_samp != node_value_arrs::N_SAMPLES) || (_n_test_samp != node_value_arrs::N_SAMPLES_TEST)) + else if((_n_samp != node_value_arrs::N_SAMPLES) || (_n_samp_test != node_value_arrs::N_SAMPLES_TEST)) { throw std::logic_error( "Number of samples in current feature is not the same as the others, (" + std::to_string(_n_samp) + " and " + - std::to_string(_n_test_samp) + + std::to_string(_n_samp_test) + " vs. " + std::to_string(node_value_arrs::N_SAMPLES) + " and " + diff --git a/src/python/py_binding_cpp_def/feature_creation/FeatureSpace.cpp b/src/python/py_binding_cpp_def/feature_creation/FeatureSpace.cpp index 42487f9a6e6608b44f3ebab44d6de240894d4e44..0888272a1f547b32d7645f54d0171ef6899e11ba 100644 --- a/src/python/py_binding_cpp_def/feature_creation/FeatureSpace.cpp +++ b/src/python/py_binding_cpp_def/feature_creation/FeatureSpace.cpp @@ -20,9 +20,9 @@ FeatureSpace::FeatureSpace( py::list allowed_param_ops, py::list prop, std::string project_type, - int max_phi, + int max_rung, int n_sis_select, - int max_store_rung, + int n_rung_store, int n_rung_generate, double cross_corr_max, double min_abs_feat_val, @@ -33,13 +33,13 @@ FeatureSpace::FeatureSpace( _phi(python_conv_utils::shared_ptr_vec_from_list<Node, FeatureNode>(phi_0)), _phi_0(_phi), _end_no_params(1, 0), - _start_gen_reparam(1, 0), + _start_rung_reparam(1, 0), _allowed_param_ops(python_conv_utils::from_list<std::string>(allowed_param_ops)), _allowed_ops(python_conv_utils::from_list<std::string>(allowed_ops)), _prop(python_conv_utils::from_list<double>(prop)), _scores(py::len(phi_0), 0.0), _task_sizes(node_value_arrs::TASK_SZ_TRAIN), - _start_gen(1, 0), + _start_rung(1, 0), _feature_space_file("feature_space/selected_features.txt"), _feature_space_summary_file("feature_space/SIS_summary.txt"), _project_type(project_type), @@ -47,10 +47,10 @@ FeatureSpace::FeatureSpace( _cross_cor_max(cross_corr_max), _l_bound(min_abs_feat_val), _u_bound(max_abs_feat_val), - _max_phi(max_phi), + _max_rung(max_rung), _n_sis_select(n_sis_select), _n_feat(py::len(phi_0)), - _n_rung_store(max_store_rung), + _n_rung_store(n_rung_store), _n_rung_generate(n_rung_generate), _n_samp(_phi[0]->n_samp()), _max_param_depth(max_param_depth), @@ -65,9 +65,9 @@ FeatureSpace::FeatureSpace( py::list allowed_param_ops, np::ndarray prop, std::string project_type, - int max_phi, + int max_rung, int n_sis_select, - int max_store_rung, + int n_rung_store, int n_rung_generate, double cross_corr_max, double min_abs_feat_val, @@ -78,13 +78,13 @@ FeatureSpace::FeatureSpace( _phi(python_conv_utils::shared_ptr_vec_from_list<Node, FeatureNode>(phi_0)), _phi_0(_phi), _end_no_params(1, 0), - _start_gen_reparam(1, 0), + _start_rung_reparam(1, 0), _allowed_param_ops(python_conv_utils::from_list<std::string>(allowed_param_ops)), _allowed_ops(python_conv_utils::from_list<std::string>(allowed_ops)), _prop(python_conv_utils::from_ndarray<double>(prop)), _scores(py::len(phi_0), 0.0), _task_sizes(node_value_arrs::TASK_SZ_TRAIN), - _start_gen(1, 0), + _start_rung(1, 0), _feature_space_file("feature_space/selected_features.txt"), _feature_space_summary_file("feature_space/SIS_summary.txt"), _project_type(project_type), @@ -92,10 +92,10 @@ FeatureSpace::FeatureSpace( _cross_cor_max(cross_corr_max), _l_bound(min_abs_feat_val), _u_bound(max_abs_feat_val), - _max_phi(max_phi), + _max_rung(max_rung), _n_sis_select(n_sis_select), _n_feat(py::len(phi_0)), - _n_rung_store(max_store_rung), + _n_rung_store(n_rung_store), _n_rung_generate(n_rung_generate), _n_samp(_phi[0]->n_samp()), _max_param_depth(max_param_depth), @@ -109,9 +109,9 @@ FeatureSpace::FeatureSpace( py::list allowed_ops, py::list prop, std::string project_type, - int max_phi, + int max_rung, int n_sis_select, - int max_store_rung, + int n_rung_store, int n_rung_generate, double cross_corr_max, double min_abs_feat_val, @@ -123,7 +123,7 @@ FeatureSpace::FeatureSpace( _prop(python_conv_utils::from_list<double>(prop)), _scores(py::len(phi_0), 0.0), _task_sizes(node_value_arrs::TASK_SZ_TRAIN), - _start_gen(1, 0), + _start_rung(1, 0), _feature_space_file("feature_space/selected_features.txt"), _feature_space_summary_file("feature_space/SIS_summary.txt"), _project_type(project_type), @@ -131,10 +131,10 @@ FeatureSpace::FeatureSpace( _cross_cor_max(cross_corr_max), _l_bound(min_abs_feat_val), _u_bound(max_abs_feat_val), - _max_phi(max_phi), + _max_rung(max_rung), _n_sis_select(n_sis_select), _n_feat(py::len(phi_0)), - _n_rung_store(max_store_rung), + _n_rung_store(n_rung_store), _n_rung_generate(n_rung_generate), _n_samp(_phi[0]->n_samp()), _max_param_depth(0), @@ -148,9 +148,9 @@ FeatureSpace::FeatureSpace( py::list allowed_ops, np::ndarray prop, std::string project_type, - int max_phi, + int max_rung, int n_sis_select, - int max_store_rung, + int n_rung_store, int n_rung_generate, double cross_corr_max, double min_abs_feat_val, @@ -162,7 +162,7 @@ FeatureSpace::FeatureSpace( _prop(python_conv_utils::from_ndarray<double>(prop)), _scores(py::len(phi_0), 0.0), _task_sizes(node_value_arrs::TASK_SZ_TRAIN), - _start_gen(1, 0), + _start_rung(1, 0), _feature_space_file("feature_space/selected_features.txt"), _feature_space_summary_file("feature_space/SIS_summary.txt"), _project_type(project_type), @@ -170,10 +170,10 @@ FeatureSpace::FeatureSpace( _cross_cor_max(cross_corr_max), _l_bound(min_abs_feat_val), _u_bound(max_abs_feat_val), - _max_phi(max_phi), + _max_rung(max_rung), _n_sis_select(n_sis_select), _n_feat(py::len(phi_0)), - _n_rung_store(max_store_rung), + _n_rung_store(n_rung_store), _n_rung_generate(n_rung_generate), _n_samp(_phi[0]->n_samp()), _max_param_depth(0), @@ -194,7 +194,7 @@ FeatureSpace::FeatureSpace( _phi_0(python_conv_utils::shared_ptr_vec_from_list<Node, FeatureNode>(phi_0)), _prop(python_conv_utils::from_ndarray<double>(prop)), _scores(py::len(phi_0), 0.0), - _start_gen(1, 0), + _start_rung(1, 0), _task_sizes(python_conv_utils::from_list<int>(task_sizes)), _feature_space_file("feature_space/selected_features.txt"), _feature_space_summary_file("feature_space/SIS_summary.txt"), @@ -252,8 +252,8 @@ FeatureSpace::FeatureSpace( } std::vector<int> rung_inds = util_funcs::argsort<int>(rungs); - _max_phi = *std::max_element(rungs.begin(), rungs.end()); - node_value_arrs::MAX_RUNG = _max_phi; + _max_rung = *std::max_element(rungs.begin(), rungs.end()); + node_value_arrs::MAX_RUNG = _max_rung; _phi[0] = phi_temp[rung_inds[0]]; for(int ff = 1; ff < _n_feat; ++ff) @@ -261,13 +261,13 @@ FeatureSpace::FeatureSpace( _phi[ff] = phi_temp[rung_inds[ff]]; if(_phi[ff]->rung() != _phi[ff - 1]->rung()) { - _start_gen.push_back(ff); + _start_rung.push_back(ff); } } #ifdef PARAMETERIZE - _start_gen_reparam = {0}; + _start_rung_reparam = {0}; _end_no_params = {0}; - for(int rr = 1; rr < _max_phi; ++rr) + for(int rr = 1; rr < _max_rung; ++rr) { nlopt_wrapper::MAX_PARAM_DEPTH = rr; bool is_correct = true; @@ -292,33 +292,33 @@ FeatureSpace::FeatureSpace( } node_value_arrs::initialize_param_storage(); - for(int rr = 1; rr <= _max_phi; ++rr) + for(int rr = 1; rr <= _max_rung; ++rr) { - int n_feat_in_rung = (rr < _max_phi ?_start_gen[rr + 1] : _phi.size()) - _start_gen[rr]; + int n_feat_in_rung = (rr < _max_rung ?_start_rung[rr + 1] : _phi.size()) - _start_rung[rr]; // Reorder features based on the number of parameters they have (none goes first) std::vector<int> feat_n_params(n_feat_in_rung); std::transform( - _phi.begin() + _start_gen[rr], - _phi.begin() + _start_gen[rr] + n_feat_in_rung, + _phi.begin() + _start_rung[rr], + _phi.begin() + _start_rung[rr] + n_feat_in_rung, feat_n_params.begin(), [](node_ptr feat){return feat->n_params();} ); std::vector<int> inds = util_funcs::argsort<int>(feat_n_params); std::vector<node_ptr>phi_copy(n_feat_in_rung); - std::copy_n(_phi.begin() + _start_gen.back(), n_feat_in_rung, phi_copy.begin()); + std::copy_n(_phi.begin() + _start_rung.back(), n_feat_in_rung, phi_copy.begin()); std::transform( inds.begin(), inds.end(), - _phi.begin() + _start_gen[rr], + _phi.begin() + _start_rung[rr], [&phi_copy](int ind){return phi_copy[ind];} ); // Reindex the features to match the sorted order - int cur_ind = _start_gen.back(); + int cur_ind = _start_rung.back(); std::for_each( - _phi.begin() + _start_gen.back(), - _phi.begin() + _start_gen.back() + n_feat_in_rung, + _phi.begin() + _start_rung.back(), + _phi.begin() + _start_rung.back() + n_feat_in_rung, [&cur_ind](node_ptr feat){feat->reindex(cur_ind); ++cur_ind;} ); @@ -343,7 +343,7 @@ FeatureSpace::FeatureSpace( _phi_0(python_conv_utils::shared_ptr_vec_from_list<Node, FeatureNode>(phi_0)), _prop(python_conv_utils::from_list<double>(prop)), _scores(py::len(phi_0), 0.0), - _start_gen(1, 0), + _start_rung(1, 0), _task_sizes(python_conv_utils::from_list<int>(task_sizes)), _feature_space_file("feature_space/selected_features.txt"), _feature_space_summary_file("feature_space/SIS_summary.txt"), @@ -400,8 +400,8 @@ FeatureSpace::FeatureSpace( } std::vector<int> rung_inds = util_funcs::argsort<int>(rungs); - _max_phi = *std::max_element(rungs.begin(), rungs.end()); - node_value_arrs::MAX_RUNG = _max_phi; + _max_rung = *std::max_element(rungs.begin(), rungs.end()); + node_value_arrs::MAX_RUNG = _max_rung; _phi[0] = phi_temp[rung_inds[0]]; for(int ff = 1; ff < _n_feat; ++ff) @@ -409,13 +409,13 @@ FeatureSpace::FeatureSpace( _phi[ff] = phi_temp[rung_inds[ff]]; if(_phi[ff]->rung() != _phi[ff - 1]->rung()) { - _start_gen.push_back(ff); + _start_rung.push_back(ff); } } #ifdef PARAMETERIZE - _start_gen_reparam = {0}; + _start_rung_reparam = {0}; _end_no_params = {0}; - for(int rr = 1; rr < _max_phi; ++rr) + for(int rr = 1; rr < _max_rung; ++rr) { nlopt_wrapper::MAX_PARAM_DEPTH = rr; bool is_correct = true; @@ -440,33 +440,33 @@ FeatureSpace::FeatureSpace( } node_value_arrs::initialize_param_storage(); - for(int rr = 1; rr <= _max_phi; ++rr) + for(int rr = 1; rr <= _max_rung; ++rr) { - int n_feat_in_rung = (rr < _max_phi ?_start_gen[rr + 1] : _phi.size()) - _start_gen[rr]; + int n_feat_in_rung = (rr < _max_rung ?_start_rung[rr + 1] : _phi.size()) - _start_rung[rr]; // Reorder features based on the number of parameters they have (none goes first) std::vector<int> feat_n_params(n_feat_in_rung); std::transform( - _phi.begin() + _start_gen[rr], - _phi.begin() + _start_gen[rr] + n_feat_in_rung, + _phi.begin() + _start_rung[rr], + _phi.begin() + _start_rung[rr] + n_feat_in_rung, feat_n_params.begin(), [](node_ptr feat){return feat->n_params();} ); std::vector<int> inds = util_funcs::argsort<int>(feat_n_params); std::vector<node_ptr>phi_copy(n_feat_in_rung); - std::copy_n(_phi.begin() + _start_gen.back(), n_feat_in_rung, phi_copy.begin()); + std::copy_n(_phi.begin() + _start_rung.back(), n_feat_in_rung, phi_copy.begin()); std::transform( inds.begin(), inds.end(), - _phi.begin() + _start_gen[rr], + _phi.begin() + _start_rung[rr], [&phi_copy](int ind){return phi_copy[ind];} ); // Reindex the features to match the sorted order - int cur_ind = _start_gen.back(); + int cur_ind = _start_rung.back(); std::for_each( - _phi.begin() + _start_gen.back(), - _phi.begin() + _start_gen.back() + n_feat_in_rung, + _phi.begin() + _start_rung.back(), + _phi.begin() + _start_rung.back() + n_feat_in_rung, [&cur_ind](node_ptr feat){feat->reindex(cur_ind); ++cur_ind;} ); diff --git a/src/python/py_binding_cpp_def/feature_creation/ModelNode.cpp b/src/python/py_binding_cpp_def/feature_creation/ModelNode.cpp index 5077c2ee01ac5e2a5df316905f2d054fdcdb94ad..531036d67479546397f36e42b7118ccf209f2521 100644 --- a/src/python/py_binding_cpp_def/feature_creation/ModelNode.cpp +++ b/src/python/py_binding_cpp_def/feature_creation/ModelNode.cpp @@ -18,7 +18,7 @@ ModelNode::ModelNode( const unsigned long int rung, const std::string expr, const std::string latex_expr, - const std::string expr_postfix, + const std::string postfix_expr, const std::string matlab_fxn_expr, const np::ndarray value, const np::ndarray test_value, @@ -30,7 +30,7 @@ ModelNode( rung, expr, latex_expr, - expr_postfix, + postfix_expr, matlab_fxn_expr, python_conv_utils::from_ndarray<double>(value), python_conv_utils::from_ndarray<double>(test_value), @@ -44,7 +44,7 @@ ModelNode::ModelNode( const unsigned long int rung, const std::string expr, const std::string latex_expr, - const std::string expr_postfix, + const std::string postfix_expr, const std::string matlab_fxn_expr, const py::list value, const py::list test_value, @@ -56,7 +56,7 @@ ModelNode( rung, expr, latex_expr, - expr_postfix, + postfix_expr, matlab_fxn_expr, python_conv_utils::from_list<double>(value), python_conv_utils::from_list<double>(test_value), diff --git a/src/python/py_binding_cpp_def/feature_creation/node_utils.hpp b/src/python/py_binding_cpp_def/feature_creation/node_utils.hpp index f0eacc42ea1afab075b30dc4698f5a3e46cfb8d4..bf78fc2afbbf68544180cc6190f703537b1e6899 100644 --- a/src/python/py_binding_cpp_def/feature_creation/node_utils.hpp +++ b/src/python/py_binding_cpp_def/feature_creation/node_utils.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file python/feature_creation/node_utils.hpp - * @brief python binding functions for node utilities + * @brief python binding functions for node utilities * * @author Thomas A. R. Purcell (tpurcell) * @bug No known bugs. diff --git a/src/utils/compare_features.hpp b/src/utils/compare_features.hpp index db95c3aec967ef6f5e010bc4a2ddfdd27a726f7e..5672ad262385059e349283e5de438052a1a8e9e2 100644 --- a/src/utils/compare_features.hpp +++ b/src/utils/compare_features.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file utils/compare_features.hpp - * @brief A set of functions to project features onto a second vector + * @brief A set of functions to project features onto a second vector * * @author Thomas A. R. Purcell (tpurcell) * @bug No known bugs. @@ -28,18 +28,18 @@ typedef std::tuple<node_ptr, double> node_sc_pair; namespace comp_feats { - extern std::vector<double> CORR_CHECK; //!< vector for storing cross_corelation values + extern std::vector<double> CORR_CHECK; //!< Vector for storing cross_corelation values extern std::vector<double> RANK; //!< Global variable used to store the rank variables for Spearman correlation extern std::vector<int> INDEX; //!< Global variable used to store the sorting indexes for Spearman correlation /** * @brief Set the is_valid and is_valid_feat_list functions for SIS * - * @param project_type Type of projection to perform - * @param max_corr Maximum cross-correlation value - * @param n_samp number of samples in the training set - * @param is_valid The _is_valid function from the feature_space - * @param is_valid_feat_list The _is_valid_feat_list function from the feature_space + * @param project_type The type of LossFunction to use when projecting the features onto a property + * @param max_corr Maximum cross-correlation used for selecting features + * @param n_samp Number of samples in the training set + * @param is_valid Function used to determine of a feature is too correlated to previously selected features + * @param is_valid_feat_list Function used to determine of a feature is too correlated to previously selected features within a given list */ void set_is_valid_fxn( const std::string project_type, @@ -52,13 +52,13 @@ namespace comp_feats /** * @brief Checks the feature to see if it is still valid against previously selected features (using the Pearson correlation coefficient with a maximum cross-correlation of 1.0) * - * @param val_ptr pointer to value array of the current feature - * @param n_samp number of samples in the training set - * @param cross_cor_max The maximum cross correlation of the featues - * @param scores_sel the scores of the previously selected features + * @param val_ptr Pointer to value array of the current feature + * @param n_samp Number of samples in the training set + * @param cross_cor_max Maximum cross-correlation used for selecting features + * @param scores_sel The projection scores for the selected feature * @param cur_score The score of the current candidate feature - * @param end_sel index of the feature to stop checking - * @param start_sel index of the feature to stop checking + * @param end_sel The index of the feature to stop checking + * @param start_sel The index of the feature to start checking * * @return True if the feature is still valid */ @@ -75,18 +75,18 @@ namespace comp_feats /** * @brief Checks the feature to see if it is still valid against previously selected features (using the Pearson correlation coefficient with a maximum cross-correlation of 1.0) * - * @param val_ptr pointer to value array of the current feature - * @param n_samp number of samples in the training set - * @param cross_cor_max The maximum cross correlation of the featues - * @param selected list of previously selected features - * @param scores_sel the scores of the previously selected features + * @param val_ptr Pointer to value array of the current feature + * @param n_samp Number of samples in the training set + * @param cross_cor_max Maximum cross-correlation used for selecting features + * @param selected The list of previously selected features + * @param scores_sel The projection scores for the selected feature * @param cur_score The score of the current candidate feature * * @return True if the feature is still valid */ bool valid_feature_against_selected_pearson_max_corr_1_feat_list( - const double* - const val_ptr, int n_samp, + const double* val_ptr, + const int n_samp, const double cross_cor_max, const std::vector<node_ptr>& selected, const std::vector<double>& scores_sel, @@ -96,11 +96,10 @@ namespace comp_feats /** * @brief Checks the feature to see if it is still valid against previously selected features (using the Pearson correlation coefficient with a maximum cross-correlation of 1.0) * - * @param val_ptr pointer to value array of the current feature - * @param n_samp number of samples per feature - * @param cross_cor_max maximum cross correlation for the featues - * @param start pointer to the first feature to compare against - * @param end pointer to the final feature to compare against + * @param val_ptr Pointer to value array of the current feature + * @param n_samp Number of samples in the training set + * @param cross_cor_max Maximum cross-correlation used for selecting features + * @param out_vec The output vector for the MPI reduce all operator * @param cur_score The score of the current candidate feature * * @return True if the feature is still valid @@ -116,13 +115,13 @@ namespace comp_feats /** * @brief Checks the feature to see if it is still valid against previously selected features (using the Pearson correlation coefficient) * - * @param val_ptr pointer to value array of the current feature - * @param n_samp number of samples in the training set - * @param cross_cor_max The maximum cross correlation of the featues - * @param scores_sel the scores of the previously selected features (not used, but passed to keep consistency) - * @param cur_score The score of the current candidate feature (not used, but passed to keep consistency) - * @param end_sel index of the feature to stop checking - * @param start_sel index of the feature to stop checking + * @param val_ptr Pointer to value array of the current feature + * @param n_samp Number of samples in the training set + * @param cross_cor_max Maximum cross-correlation used for selecting features + * @param scores_sel The projection scores for the selected feature + * @param cur_score The score of the current candidate feature + * @param end_sel The index of the feature to stop checking + * @param start_sel The index of the feature to start checking * * @return True if the feature is still valid */ @@ -139,12 +138,12 @@ namespace comp_feats /** * @brief Checks the feature to see if it is still valid against previously selected features (using the Pearson correlation coefficient) * - * @param val_ptr pointer to value array of the current feature - * @param n_samp number of samples in the training set - * @param cross_cor_max The maximum cross correlation of the featues - * @param selected list of previously selected features - * @param scores_sel the scores of the previously selected features (not used, but passed to keep consistency) - * @param cur_score The score of the current candidate feature (not used, but passed to keep consistency) + * @param val_ptr Pointer to value array of the current feature + * @param n_samp Number of samples in the training set + * @param cross_cor_max Maximum cross-correlation used for selecting features + * @param selected The list of previously selected features + * @param scores_sel The projection scores for the selected feature + * @param cur_score The score of the current candidate feature * * @return True if the feature is still valid */ @@ -160,12 +159,11 @@ namespace comp_feats /** * @brief Checks the feature to see if it is still valid against previously selected features (using the Pearson correlation coefficient) * - * @param val_ptr pointer to value array of the current feature - * @param n_samp number of samples per feature - * @param cross_cor_max maximum cross correlation for the featues - * @param start pointer to the first feature to compare against - * @param end pointer to the final feature to compare against - * @param cur_score The score of the current candidate feature (not used, but passed to keep consistency) + * @param val_ptr Pointer to value array of the current feature + * @param n_samp Number of samples in the training set + * @param cross_cor_max Maximum cross-correlation used for selecting features + * @param out_vec The output vector for the MPI reduce all operator + * @param cur_score The score of the current candidate feature * * @return True if the feature is still valid */ @@ -180,13 +178,13 @@ namespace comp_feats /** * @brief Checks the feature to see if it is still valid against previously selected features (using the rank correlation coefficient with a maximum cross-correlation of 1.0) * - * @param val_ptr pointer to value array of the current feature - * @param n_samp number of samples in the training set - * @param cross_cor_max The maximum cross correlation of the featues - * @param scores_sel the scores of the previously selected features + * @param val_ptr Pointer to value array of the current feature + * @param n_samp Number of samples in the training set + * @param cross_cor_max Maximum cross-correlation used for selecting features + * @param scores_sel The projection scores for the selected feature * @param cur_score The score of the current candidate feature - * @param end_sel index of the feature to stop checking - * @param start_sel index of the feature to stop checking + * @param end_sel The index of the feature to stop checking + * @param start_sel The index of the feature to start checking * * @return True if the feature is still valid */ @@ -203,11 +201,11 @@ namespace comp_feats /** * @brief Checks the feature to see if it is still valid against previously selected features (using the rank correlation coefficient with a maximum cross-correlation of 1.0) * - * @param val_ptr pointer to value array of the current feature - * @param n_samp number of samples in the training set - * @param cross_cor_max The maximum cross correlation of the featues - * @param selected list of previously selected features - * @param scores_sel the scores of the previously selected features + * @param val_ptr Pointer to value array of the current feature + * @param n_samp Number of samples in the training set + * @param cross_cor_max Maximum cross-correlation used for selecting features + * @param selected The list of previously selected features + * @param scores_sel The projection scores for the selected feature * @param cur_score The score of the current candidate feature * * @return True if the feature is still valid @@ -224,11 +222,10 @@ namespace comp_feats /** * @brief Checks the feature to see if it is still valid against previously selected features (using the rank correlation coefficient with a maximum cross-correlation of 1.0) * - * @param val_ptr pointer to value array of the current feature - * @param n_samp number of samples per feature - * @param cross_cor_max maximum cross correlation for the featues - * @param start pointer to the first feature to compare against - * @param end pointer to the final feature to compare against + * @param val_ptr Pointer to value array of the current feature + * @param n_samp Number of samples in the training set + * @param cross_cor_max Maximum cross-correlation used for selecting features + * @param out_vec The output vector for the MPI reduce all operator * @param cur_score The score of the current candidate feature * * @return True if the feature is still valid @@ -244,13 +241,13 @@ namespace comp_feats /** * @brief Checks the feature to see if it is still valid against previously selected features (using the rank correlation coefficient) * - * @param val_ptr pointer to value array of the current feature - * @param n_samp number of samples in the training set - * @param cross_cor_max The maximum cross correlation of the featues - * @param scores_sel the scores of the previously selected features (not used, but passed to keep consistency) - * @param cur_score The score of the current candidate feature (not used, but passed to keep consistency) - * @param end_sel index of the feature to stop checking - * @param start_sel index of the feature to stop checking + * @param val_ptr Pointer to value array of the current feature + * @param n_samp Number of samples in the training set + * @param cross_cor_max Maximum cross-correlation used for selecting features + * @param scores_sel The projection scores for the selected feature + * @param cur_score The score of the current candidate feature + * @param end_sel The index of the feature to stop checking + * @param start_sel The index of the feature to start checking * * @return True if the feature is still valid */ @@ -267,12 +264,12 @@ namespace comp_feats /** * @brief Checks the feature to see if it is still valid against previously selected features (using the rank correlation coefficient) * - * @param val_ptr pointer to value array of the current feature - * @param n_samp number of samples in the training set - * @param cross_cor_max The maximum cross correlation of the featues - * @param selected list of previously selected features - * @param scores_sel the scores of the previously selected features (not used, but passed to keep consistency) - * @param cur_score The score of the current candidate feature (not used, but passed to keep consistency) + * @param val_ptr Pointer to value array of the current feature + * @param n_samp Number of samples in the training set + * @param cross_cor_max Maximum cross-correlation used for selecting features + * @param selected The list of previously selected features + * @param scores_sel The projection scores for the selected feature + * @param cur_score The score of the current candidate feature * * @return True if the feature is still valid */ @@ -288,12 +285,11 @@ namespace comp_feats /** * @brief Checks the feature to see if it is still valid against previously selected features (using the rank correlation coefficient) * - * @param val_ptr pointer to value array of the current feature - * @param n_samp number of samples per feature - * @param cross_cor_max maximum cross correlation for the featues - * @param start pointer to the first feature to compare against - * @param end pointer to the final feature to compare against - * @param cur_score The score of the current candidate feature (not used, but passed to keep consistency) + * @param val_ptr Pointer to value array of the current feature + * @param n_samp Number of samples in the training set + * @param cross_cor_max Maximum cross-correlation used for selecting features + * @param out_vec The output vector for the MPI reduce all operator + * @param cur_score The score of the current candidate feature * * @return True if the feature is still valid */ diff --git a/src/utils/enum.hpp b/src/utils/enum.hpp index 105f454e9f19e784f8edc32bdcf5cb03631b3170..f158331c32b884071779c88f6cd8d2b195ecb1e6 100644 --- a/src/utils/enum.hpp +++ b/src/utils/enum.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file utils/enum.hpp - * @brief Define node type enum + * @brief Define node type enum * * @author Thomas A. R. Purcell (tpurcell) * @bug No known bugs. diff --git a/src/utils/math_funcs.hpp b/src/utils/math_funcs.hpp index ef3947093d490b2a71a383768481dc3dcf0e879b..b2c8346c7aafc837ac8c4d6bceeff3ca59f97790 100644 --- a/src/utils/math_funcs.hpp +++ b/src/utils/math_funcs.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file utils/math_funcs.hpp - * @brief A set of functions to get standardized mathematical operations on + * @brief A set of functions to get standardized mathematical operations on * * @author Thomas A. R. Purcell (tpurcell) * @bug No known bugs. @@ -35,7 +35,7 @@ namespace util_funcs * @brief Get the sign of a number * * @param number The number to get the sign of - * @return -1 for negative, 0 for 0 and 1 for positive + * @return -1 for negative, 0 for 0, and 1 for positive */ template<typename T> inline T sign(T number){return (number > T(0)) - (number < T(0));}; @@ -44,7 +44,7 @@ namespace util_funcs * @brief Round a number to arbitrary precision * * @param num The number to round - * @param n The precision + * @param n The number of decimal digits after the decimal point * * @return The rounded number */ @@ -58,7 +58,7 @@ namespace util_funcs * @brief Round a number to arbitrary precision * * @param num The number to round - * @param n The precision + * @param n The number of binary digits after the decimal point * * @return The rounded number */ @@ -80,9 +80,9 @@ namespace util_funcs /** * @brief Find the mean of of a vector * - * @param start pointer to the start of the vector - * @param size the size of the vector - * @return the mean of the vector + * @param start A pointer to the head of the vector + * @param size The size of the vector + * @return The mean of the vector */ template<typename T> inline double mean(const T* start, int size){return static_cast<double>(std::accumulate(start, start + size, 0.0)) / static_cast<double>(size);}; @@ -91,7 +91,7 @@ namespace util_funcs * @brief Find the standard deviation of a vector * * @param vec The vector to calculate the stand deviation of. - * @return the standard deviation + * @return The standard deviation */ inline double stand_dev(const std::vector<double>& vec) { @@ -103,9 +103,9 @@ namespace util_funcs /** * @brief Find the standard deviation of a vector * - * @param start start pointer to the start of the vector - * @param size size the size of the vector - * @return The standard deviation of thwe vector + * @param start A pointer to the head of the vector + * @param size The size of the vector + * @return The standard deviation of the vector */ inline double stand_dev(const double* start, const int size) { @@ -129,12 +129,12 @@ namespace util_funcs ); }; /** - * @brief [brief description] + * @brief Find the standard deviation of a vector - * @param start start pointer to the start of the vector - * @param size size the size of the vector + * @param start A pointer to the head of the vector + * @param size The size of the vector * @param vec_mean The mean of the vector - * @return The standard deviation of thwe vector + * @return The standard deviation of the vector */ inline double stand_dev(const double* start, const int size, const double vec_mean) { @@ -144,7 +144,7 @@ namespace util_funcs /** * @brief Find the norm of a vector * - * @param vec The vector to calculate the stand deviation of. + * @param vec The vector to calculate the norm of. * @return the norm of the vector */ inline double norm(const std::vector<double>& vec) @@ -155,8 +155,8 @@ namespace util_funcs /** * @brief Find the norm of a vector - * @param start start pointer to the start of the vector - * @param size size the size of the vector + * @param start A pointer to the head of the vector + * @param size The size of the vector * @return The norm of the vector */ inline double norm(const double* start, const int size) @@ -167,9 +167,9 @@ namespace util_funcs /** * @brief The Pearson correlation for two vectors * - * @param a the pointer to the head of the first vector - * @param b the pointer to the head of the second vector - * @param size the size of the vector + * @param a The pointer to the head of the first vector + * @param b The pointer to the head of the second vector + * @param size The size of the vector * @return The correlation coefficient between vector a and vector b */ inline double r(const double* a, const double* b, const int size) @@ -187,11 +187,11 @@ namespace util_funcs /** * @brief The Pearson correlation for two vectors * - * @param a the pointer to the head of the first vector - * @param b the pointer to the head of the second vector - * @param size the size of the vector - * @param mean_a the mean of the a vector - * @param std_a the standard deviation of the a vector + * @param a The pointer to the head of the first vector + * @param b The pointer to the head of the second vector + * @param size The size of the vector + * @param mean_a The mean of the a vector + * @param std_a The standard deviation of the a vector * @return The correlation coefficient between vector a and vector b */ inline double r(const double* a, const double* b, const int size, const double mean_a, const double std_a) @@ -208,13 +208,13 @@ namespace util_funcs /** * @brief The Pearson correlation for two vectors * - * @param a the pointer to the head of the first vector - * @param b the pointer to the head of the second vector - * @param size the size of the vector - * @param mean_a the mean of the a vector - * @param std_a the standard deviation of the a vector - * @param mean_b the mean of the b vector - * @param std_b the standard deviation of the b vector + * @param a The pointer to the head of the first vector + * @param b The pointer to the head of the second vector + * @param size The size of the vector + * @param mean_a The mean of the a vector + * @param std_a The standard deviation of the a vector + * @param mean_b The mean of the b vector + * @param std_b The standard deviation of the b vector * @return The correlation coefficient between vector a and vector b */ inline double r(const double* a, const double* b, const int size, const double mean_a, const double std_a, const double mean_b, const double std_b) @@ -230,9 +230,9 @@ namespace util_funcs /** * @brief The Pearson correlation for two vectors * - * @param a the pointer to the head of the first vector - * @param b the pointer to the head of the second vector - * @param sizes the sizes of the tasks to calculate the correlation on + * @param a The pointer to the head of the first vector + * @param b The pointer to the head of the second vector + * @param sizes The sizes of the tasks to calculate the correlation on * @return The average Pearson correlations */ double r(const double* a, const double* b, const std::vector<int>& sizes); @@ -240,11 +240,11 @@ namespace util_funcs /** * @brief The Pearson correlation for two vectors * - * @param a the pointer to the head of the first vector - * @param b the pointer to the head of the second vector - * @param sizes the sizes of the tasks to calculate the correlation on - * @param mean_a the mean of the a vector for each task - * @param std_a the standard deviation of the a vector for each task + * @param a The pointer to the head of the first vector + * @param b The pointer to the head of the second vector + * @param sizes The sizes of the tasks to calculate the correlation on + * @param mean_a The mean of the a vector for each task + * @param std_a The standard deviation of the a vector for each task * @return The average Pearson correlations */ double r(const double* a, const double* b, const std::vector<int>& sizes, const std::vector<double>& mean_a, const std::vector<double>& std_a); @@ -252,13 +252,13 @@ namespace util_funcs /** * @brief The Pearson correlation for two vectors * - * @param a the pointer to the head of the first vector - * @param b the pointer to the head of the second vector - * @param sizes the sizes of the tasks to calculate the correlation on - * @param mean_a the mean of the a vector for each task - * @param std_a the standard deviation of the a vector for each task - * @param mean_b the mean of the b vector for each task - * @param std_b the standard deviation of the b vector for each task + * @param a The pointer to the head of the first vector + * @param b The pointer to the head of the second vector + * @param sizes The sizes of the tasks to calculate the correlation on + * @param mean_a The mean of the a vector for each task + * @param std_a The standard deviation of the a vector for each task + * @param mean_b The mean of the b vector for each task + * @param std_b The standard deviation of the b vector for each task * @return The average Pearson correlations */ double r( @@ -274,10 +274,10 @@ namespace util_funcs /** * @brief The Pearson correlation for two vectors * - * @param a the pointer to the head of the first vector - * @param b the pointer to the head of the second vector - * @param sz the start of vector that describes the sizes of the tasks to calculate the correlation on - * @param n_tasks number of tasks to average over + * @param a The pointer to the head of the first vector + * @param b The pointer to the head of the second vector + * @param sz The start of vector that describes the sizes of the tasks to calculate the correlation on + * @param n_tasks The number of tasks to average over * @return The average Pearson correlations */ double r(const double* a, const double* b, const int* sz, const int n_tasks); @@ -285,12 +285,12 @@ namespace util_funcs /** * @brief The Pearson correlation for two vectors * - * @param a the pointer to the head of the first vector - * @param b the pointer to the head of the second vector - * @param sz the start of vector that describes the sizes of the tasks to calculate the correlation on - * @param mean_a the mean of the a vector for each task - * @param std_a the standard deviation of the a vector for each task - * @param n_tasks number of tasks to average over + * @param a The pointer to the head of the first vector + * @param b The pointer to the head of the second vector + * @param sz The start of vector that describes the sizes of the tasks to calculate the correlation on + * @param mean_a The mean of the a vector for each task + * @param std_a The standard deviation of the a vector for each task + * @param n_tasks The number of tasks to average over * @return The average Pearson correlations */ double r(const double* a, const double* b, const int* sz, const double* mean_a, const double* std_a, const int n_tasks); @@ -298,14 +298,14 @@ namespace util_funcs /** * @brief The Pearson correlation for two vectors * - * @param a the pointer to the head of the first vector - * @param b the pointer to the head of the second vector - * @param sz the start of vector that describes the sizes of the tasks to calculate the correlation on - * @param mean_a the mean of the a vector for each task - * @param std_a the standard deviation of the b vector for each task - * @param mean_b the mean of the a vector for each task - * @param std_b the standard deviation of the b vector for each task - * @param n_tasks number of tasks to average over + * @param a The pointer to the head of the first vector + * @param b The pointer to the head of the second vector + * @param sz The start of vector that describes the sizes of the tasks to calculate the correlation on + * @param mean_a The mean of the a vector for each task + * @param std_a The standard deviation of the b vector for each task + * @param mean_b The mean of the a vector for each task + * @param std_b The standard deviation of the b vector for each task + * @param n_tasks The number of tasks to average over * @return The average Pearson correlations */ double r(const double* a, const double* b, const int* sz, const double* mean_a, const double* std_a, const double* mean_b, const double* std_b, const int n_tasks); @@ -313,9 +313,9 @@ namespace util_funcs /** * @brief The Pearson correlation for two vectors * - * @param a the pointer to the head of the first vector - * @param b the pointer to the head of the second vector - * @param size the size of the vector + * @param a The pointer to the head of the first vector + * @param b The pointer to the head of the second vector + * @param size The size of the vector * @return The coefficient of determination between vector a and vector b */ inline double r2(const double* a, const double* b, const int size) @@ -337,11 +337,11 @@ namespace util_funcs /** * @brief The Pearson correlation for two vectors * - * @param a the pointer to the head of the first vector - * @param b the pointer to the head of the second vector - * @param size the size of the vector - * @param mean_a the mean of the a vector - * @param std_a the standard deviation of the a vector + * @param a The pointer to the head of the first vector + * @param b The pointer to the head of the second vector + * @param size The size of the vector + * @param mean_a The mean of the a vector + * @param std_a The standard deviation of the a vector * @return The coefficient of determination between vector a and vector b */ inline double r2(const double* a, const double* b, const int size, const double mean_a, const double std_a) @@ -362,13 +362,13 @@ namespace util_funcs /** * @brief The Pearson correlation for two vectors * - * @param a the pointer to the head of the first vector - * @param b the pointer to the head of the second vector - * @param size the size of the vector - * @param mean_a the mean of the a vector - * @param std_a the standard deviation of the a vector - * @param mean_b the mean of the b vector - * @param std_b the standard deviation of the b vector + * @param a The pointer to the head of the first vector + * @param b The pointer to the head of the second vector + * @param size The size of the vector + * @param mean_a The mean of the a vector + * @param std_a The standard deviation of the a vector + * @param mean_b The mean of the b vector + * @param std_b The standard deviation of the b vector * @return The coefficient of determination between vector a and vector b */ inline double r2(const double* a, const double* b, const int size, const double mean_a, const double std_a, const double mean_b, const double std_b) @@ -382,9 +382,9 @@ namespace util_funcs /** * @brief Calculate the average Coefficient of Determination between two vectors * - * @param a the pointer to the head of the first vector - * @param b the pointer to the head of the second vector - * @param sizes the sizes of the tasks to calculate the correlation on + * @param a The pointer to the head of the first vector + * @param b The pointer to the head of the second vector + * @param sizes The sizes of the tasks to calculate the correlation on * @return The average Coefficient of Determination */ double r2(const double* a, const double* b, const std::vector<int>& sizes); @@ -392,11 +392,11 @@ namespace util_funcs /** * @brief Calculate the average Coefficient of Determination between two vectors * - * @param a the pointer to the head of the first vector - * @param b the pointer to the head of the second vector - * @param sizes the sizes of the tasks to calculate the correlation on - * @param mean_a the mean of the a vector for each task - * @param std_a the standard deviation of the a vector for each task + * @param a The pointer to the head of the first vector + * @param b The pointer to the head of the second vector + * @param sizes The sizes of the tasks to calculate the correlation on + * @param mean_a The mean of the a vector for each task + * @param std_a The standard deviation of the a vector for each task * @return The average Coefficient of Determination */ double r2(const double* a, const double* b, const std::vector<int>& sizes, const std::vector<double>& mean_a, const std::vector<double>& std_a); @@ -404,13 +404,13 @@ namespace util_funcs /** * @brief Calculate the average Coefficient of Determination between two vectors * - * @param a the pointer to the head of the first vector - * @param b the pointer to the head of the second vector - * @param sizes the sizes of the tasks to calculate the correlation on - * @param mean_a the mean of the a vector for each task - * @param std_a the standard deviation of the a vector for each task - * @param mean_b the mean of the b vector for each task - * @param std_b the standard deviation of the b vector for each task + * @param a The pointer to the head of the first vector + * @param b The pointer to the head of the second vector + * @param sizes The sizes of the tasks to calculate the correlation on + * @param mean_a The mean of the a vector for each task + * @param std_a The standard deviation of the a vector for each task + * @param mean_b The mean of the b vector for each task + * @param std_b The standard deviation of the b vector for each task * @return The average Coefficient of Determination */ double r2( @@ -426,10 +426,10 @@ namespace util_funcs /** * @brief Calculate the average Coefficient of Determination between two vectors * - * @param a the pointer to the head of the first vector - * @param b the pointer to the head of the second vector - * @param sz the start of vector that describes the sizes of the tasks to calculate the correlation on - * @param n_tasks number of tasks to average over + * @param a The pointer to the head of the first vector + * @param b The pointer to the head of the second vector + * @param sz The start of vector that describes the sizes of the tasks to calculate the correlation on + * @param n_tasks The number of tasks to average over * @return The average Coefficient of Determination */ double r2(const double* a, const double* b, const int* sz, const int n_tasks); @@ -437,12 +437,12 @@ namespace util_funcs /** * @brief Calculate the average Coefficient of Determination between two vectors * - * @param a the pointer to the head of the first vector - * @param b the pointer to the head of the second vector - * @param sz the start of vector that describes the sizes of the tasks to calculate the correlation on - * @param mean_a the mean of the a vector for each task - * @param std_a the standard deviation of the a vector for each task - * @param n_tasks number of tasks to average over + * @param a The pointer to the head of the first vector + * @param b The pointer to the head of the second vector + * @param sz The start of vector that describes the sizes of the tasks to calculate the correlation on + * @param mean_a The mean of the a vector for each task + * @param std_a The standard deviation of the a vector for each task + * @param n_tasks The number of tasks to average over * @return The average Coefficient of Determination */ double r2(const double* a, const double* b, const int* sz, const double* mean_a, const double* std_a, const int n_tasks); @@ -450,14 +450,14 @@ namespace util_funcs /** * @brief Calculate the average Coefficient of Determination between two vectors * - * @param a the pointer to the head of the first vector - * @param b the pointer to the head of the second vector - * @param sz the start of vector that describes the sizes of the tasks to calculate the correlation on - * @param mean_a the mean of the a vector for each task - * @param std_a the standard deviation of the a vector for each task - * @param mean_b the mean of the b vector for each task - * @param std_b the standard deviation of the b vector for each task - * @param n_tasks number of tasks to average over + * @param a The pointer to the head of the first vector + * @param b The pointer to the head of the second vector + * @param sz The start of vector that describes the sizes of the tasks to calculate the correlation on + * @param mean_a The mean of the a vector for each task + * @param std_a The standard deviation of the a vector for each task + * @param mean_b The mean of the b vector for each task + * @param std_b The standard deviation of the b vector for each task + * @param n_tasks The number of tasks to average over * @return The average Coefficient of Determination */ double r2(const double* a, const double* b, const int* sz, const double* mean_a, const double* std_a, const double* mean_b, const double* std_b, const int n_tasks); @@ -465,10 +465,10 @@ namespace util_funcs /** * @brief Calculate the Coefficient of Determination between two vectors (For the log transformed problem) * - * @param a the pointer to the head of the first vector - * @param b the pointer to the head of the second vector + * @param a The pointer to the head of the first vector + * @param b The pointer to the head of the second vector * @param log_a the pointer to the head of the vector used to store the log_transformed a value - * @param size the size of the vector + * @param size The size of the vector * @return The Coefficient of Determination */ double log_r2(const double* a, const double* b, double* log_a, const int size); @@ -476,12 +476,12 @@ namespace util_funcs /** * @brief Calculate the Coefficient of Determination between two vectors (For the log transformed problem) * - * @param a the pointer to the head of the first vector - * @param b the pointer to the head of the second vector + * @param a The pointer to the head of the first vector + * @param b The pointer to the head of the second vector * @param log_a the pointer to the head of the vector used to store the log_transformed a value - * @param size the size of the vector - * @param mean_b the mean of the b vector for each task - * @param std_b the standard deviation of the b vector for each task + * @param size The size of the vector + * @param mean_b The mean of the b vector for each task + * @param std_b The standard deviation of the b vector for each task * @return The Coefficient of Determination */ double log_r2(const double* a, const double* b, double* log_a, const int size, const double mean_b, const double std_b); @@ -489,10 +489,10 @@ namespace util_funcs /** * @brief Calculate the average Coefficient of Determination between two vectors (For the log transformed problem) * - * @param a the pointer to the head of the first vector - * @param b the pointer to the head of the second vector + * @param a The pointer to the head of the first vector + * @param b The pointer to the head of the second vector * @param log_a the pointer to the head of the vector used to store the log_transformed a value - * @param sizes the sizes of the tasks to calculate the correlation on + * @param sizes The sizes of the tasks to calculate the correlation on * @return The average Coefficient of Determination */ double log_r2(const double* a, const double* b, double* log_a, const std::vector<int>& sizes); @@ -500,12 +500,12 @@ namespace util_funcs /** * @brief Calculate the average Coefficient of Determination between two vectors (For the log transformed problem) * - * @param a the pointer to the head of the first vector - * @param b the pointer to the head of the second vector + * @param a The pointer to the head of the first vector + * @param b The pointer to the head of the second vector * @param log_a the pointer to the head of the vector used to store the log_transformed a value - * @param sizes the sizes of the tasks to calculate the correlation on - * @param mean_b the mean of the b vector for each task - * @param std_b the standard deviation of the b vector for each task + * @param sizes The sizes of the tasks to calculate the correlation on + * @param mean_b The mean of the b vector for each task + * @param std_b The standard deviation of the b vector for each task * @return The average Coefficient of Determination */ double log_r2(const double* a, const double* b, double* log_a, const std::vector<int>& sizes, const std::vector<double>& mean_b, const std::vector<double>& std_b); @@ -513,11 +513,11 @@ namespace util_funcs /** * @brief Calculate the average Coefficient of Determination between two vectors (For the log transformed problem) * - * @param a the pointer to the head of the first vector - * @param b the pointer to the head of the second vector + * @param a The pointer to the head of the first vector + * @param b The pointer to the head of the second vector * @param log_a the pointer to the head of the vector used to store the log_transformed a value - * @param sz the start of vector that describes the sizes of the tasks to calculate the correlation on - * @param n_tasks number of tasks to average over + * @param sz The start of vector that describes the sizes of the tasks to calculate the correlation on + * @param n_tasks The number of tasks to average over * @return The average Coefficient of Determination */ double log_r2(const double* a, const double* b, double* log_a, const int* sz, const int n_tasks); @@ -525,13 +525,13 @@ namespace util_funcs /** * @brief Calculate the average Coefficient of Determination between two vectors (For the log transformed problem) * - * @param a the pointer to the head of the first vector - * @param b the pointer to the head of the second vector + * @param a The pointer to the head of the first vector + * @param b The pointer to the head of the second vector * @param log_a the pointer to the head of the vector used to store the log_transformed a value - * @param sz the start of vector that describes the sizes of the tasks to calculate the correlation on - * @param mean_b the mean of the b vector for each task - * @param std_b the standard deviation of the b vector for each task - * @param n_tasks number of tasks to average over + * @param sz The start of vector that describes the sizes of the tasks to calculate the correlation on + * @param mean_b The mean of the b vector for each task + * @param std_b The standard deviation of the b vector for each task + * @param n_tasks The number of tasks to average over * @return The average Coefficient of Determination */ double log_r2(const double* a, const double* b, double* log_a, const int* sz, const double* mean_b, const double* std_b, const int n_tasks); @@ -549,12 +549,12 @@ namespace util_funcs /** * @brief Calculate the Spearman's rank correlation coefficient between two vectors * - * @param a the pointer to the head of the first vector - * @param b the pointer to the head of the second vector - * @param rank_a the pointer to the head of the vector used to rank of a - * @param rank_b the pointer to the head of the vector used to rank of b - * @param index the pointer used to store the sorted indexes - * @param size the size of the vector + * @param a The pointer to the head of the first vector + * @param b The pointer to the head of the second vector + * @param rank_a The pointer to the head of the vector used to rank of a + * @param rank_b The pointer to the head of the vector used to rank of b + * @param index The pointer used to store the sorted indexes + * @param size The size of the vector * @return The Coefficient of Determination */ double spearman_r(const double* a, const double* b, double* rank_a, double* rank_b, int* index, const int size); @@ -562,12 +562,12 @@ namespace util_funcs /** * @brief Calculate the average Spearman's rank correlation coefficient between two vectors * - * @param a the pointer to the head of the first vector - * @param b the pointer to the head of the second vector - * @param rank_a the pointer to the head of the vector used to rank of a - * @param rank_b the pointer to the head of the vector used to rank of b - * @param index the pointer used to store the sorted indexes - * @param sizes the sizes of the tasks to calculate the correlation on + * @param a The pointer to the head of the first vector + * @param b The pointer to the head of the second vector + * @param rank_a The pointer to the head of the vector used to rank of a + * @param rank_b The pointer to the head of the vector used to rank of b + * @param index The pointer used to store the sorted indexes + * @param sizes The sizes of the tasks to calculate the correlation on * @return The average Coefficient of Determination */ double spearman_r(const double* a, const double* b, double* rank_a, double* rank_b, int* index, const std::vector<int>& sizes); @@ -575,13 +575,13 @@ namespace util_funcs /** * @brief Calculate the average Spearman's rank correlation coefficient between two vectors * - * @param a the pointer to the head of the first vector - * @param b the pointer to the head of the second vector - * @param rank_a the pointer to the head of the vector used to rank of a - * @param rank_b the pointer to the head of the vector used to rank of b - * @param index the pointer used to store the sorted indexes - * @param sz the start of vector that describes the sizes of the tasks to calculate the correlation on - * @param n_tasks number of tasks to average over + * @param a The pointer to the head of the first vector + * @param b The pointer to the head of the second vector + * @param rank_a The pointer to the head of the vector used to rank of a + * @param rank_b The pointer to the head of the vector used to rank of b + * @param index The pointer used to store the sorted indexes + * @param sz The start of vector that describes the sizes of the tasks to calculate the correlation on + * @param n_tasks The number of tasks to average over * @return The average Coefficient of Determination */ double spearman_r(const double* a, const double* b, double* rank_a, double* rank_b, int* index, const int* sz, const int n_tasks); @@ -605,9 +605,9 @@ namespace util_funcs /** * @brief Sort a vector and return the indexes of the unsorted array that corresponds to the sorted one * - * @param begin the starting point for the sorting - * @param end the end point for the sorting - * @param vec vector to sort + * @param begin The starting point for the sorting + * @param end The end point for the sorting + * @param vec The vector to sort * @return The indexes of the sorted array */ template<typename T> @@ -619,9 +619,9 @@ namespace util_funcs /** * @brief Sort a vector and return the indexes of the unsorted array that corresponds to the sorted one * - * @param begin the starting point for the sorting - * @param end the end point for the sorting - * @param vec_begin start pointer to the vector to sort + * @param begin The starting point for the sorting + * @param end The end point for the sorting + * @param vec_begin A pointer to the head of the vector to sort */ template<typename T> inline void argsort(int* begin, int* end, const T* vec_begin) @@ -629,7 +629,7 @@ namespace util_funcs std::sort(begin, end, [vec_begin](int i1, int i2){return vec_begin[i1] < vec_begin[i2];}); } - /**const + /** * @brief The maximum absolute value of the vector * * @param start The starting point for the comparison @@ -658,9 +658,9 @@ namespace util_funcs /** * @brief Iterate the set of indices to get all combinations * - * @param inds indices to iterate over - * @param size size of the indices - * @param increment amount to increment the indices + * @param inds The indices to iterate over + * @param size The size of the indices + * @param increment The amount to increment the indices * @return True if the all combinations have been explored */ bool iterate(std::vector<int>& inds, int size, int increment); diff --git a/src/utils/mkl_interface.hpp b/src/utils/mkl_interface.hpp index 5cf5a76592e0c78eb84e4b5dafa99f210ff346da..7248f1ddf037e488cd1581fcff75e4de4827ff3b 100644 --- a/src/utils/mkl_interface.hpp +++ b/src/utils/mkl_interface.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file utils/mkl_interface.hpp - * @brief wrapper functions to a mkl blas functionality + * @brief wrapper functions to a mkl blas functionality * * @author Thomas A. Purcell (tpurcell90) * @bug No known bugs diff --git a/src/utils/project.hpp b/src/utils/project.hpp index 954a97156015f0b355b8121036c5819748789317..ba3cd752f4483c12539e1ba9dcf61b0adbdec6e8 100644 --- a/src/utils/project.hpp +++ b/src/utils/project.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file utils/project.hpp - * @brief A set of functions to project features onto a second vector + * @brief A set of functions to project features onto a second vector * * @author Thomas A. R. Purcell (tpurcell) * @bug No known bugs. @@ -56,7 +56,7 @@ namespace project_funcs * * @param loss The LossFunnction used for the projection * @param feats The set of features to calculate - * @param scores vector to output the scores to + * @param scores A pointer to the head of the vector to output the scores to */ void project_loss(std::shared_ptr<LossFunction> loss, const std::vector<node_ptr>& feats, double* scores); @@ -65,7 +65,7 @@ namespace project_funcs * * @param loss The LossFunnction used for the projection * @param feats The set of features to calculate - * @param scores vector to output the scores to + * @param scores A pointer to the head of the vector to output the scores to */ void project_loss_no_omp(std::shared_ptr<LossFunction> loss, const std::vector<node_ptr>& feats, double* scores); } diff --git a/src/utils/string_utils.hpp b/src/utils/string_utils.hpp index 652a9f27a45f858620d66d28f1dd57558be3983d..df48d193f9e0fbb57bb23a7c4a23e8949f4c97d7 100644 --- a/src/utils/string_utils.hpp +++ b/src/utils/string_utils.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file utils/string_utils.hpp - * @brief A set of functions to manipulate strings + * @brief A set of functions to manipulate strings * * @author Thomas A. R. Purcell (tpurcell) * @bug No known bugs. @@ -35,7 +35,7 @@ namespace str_utils * @brief split a string and trim whitespace * * @param str String to split - * @param split_tokens characters to split the string with + * @param split_tokens Characters to split the string with * @return The vector with the string split along the split tokens */ std::vector<std::string> split_string_trim(const std::string str, const std::string split_tokens = ",;:"); @@ -44,7 +44,7 @@ namespace str_utils * @brief Convert a string into a latex string * * @param str String to convert to a latex string - * @return The latexified version of the string + * @return The LaTeXified version of the string */ std::string latexify(const std::string str); diff --git a/src/utils/vector_utils.hpp b/src/utils/vector_utils.hpp index 08c9f249595f7cd0488d040d6aa345b8a02bbb8b..7801e11df7e25599c134b44b43a95a2a347793fe 100644 --- a/src/utils/vector_utils.hpp +++ b/src/utils/vector_utils.hpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. /** @file utils/vector_utils.hpp - * @brief A set of functions to manipulate vectors + * @brief A set of functions to manipulate vectors * * @author Thomas A. R. Purcell (tpurcell) * @bug No known bugs. @@ -25,6 +25,13 @@ namespace vector_utils { +/** + * @brief Return a vector of all unique elements of in_vec + * + * @param in_vec The input vector + * @tparam T The type of elements of T + * @return The vector of unique elements of in_vec + */ template<typename T> std::vector<T> unique(const std::vector<T> in_vec) { diff --git a/tests/googletest/feature_creation/feature_space/test_feat_space.cc b/tests/googletest/feature_creation/feature_space/test_feat_space.cc index be8e080a79b6f5401d44eafe2ac5a05dca182dc6..6f89b7fae353bdc2bc6ed25b0c89466743a41b1c 100644 --- a/tests/googletest/feature_creation/feature_space/test_feat_space.cc +++ b/tests/googletest/feature_creation/feature_space/test_feat_space.cc @@ -104,7 +104,7 @@ namespace EXPECT_STREQ(feat_space.feature_space_file().c_str(), "feature_space/selected_features.txt"); EXPECT_EQ(feat_space.l_bound(), 1e-50); EXPECT_EQ(feat_space.u_bound(), 1e50); - EXPECT_EQ(feat_space.max_phi(), 2); + EXPECT_EQ(feat_space.max_rung(), 2); EXPECT_EQ(feat_space.n_sis_select(), 10); EXPECT_EQ(feat_space.n_samp(), 10); EXPECT_EQ(feat_space.n_feat(), 154); @@ -159,7 +159,7 @@ namespace EXPECT_STREQ(feat_space.feature_space_file().c_str(), "feature_space/selected_features.txt"); EXPECT_EQ(feat_space.l_bound(), 1e-50); EXPECT_EQ(feat_space.u_bound(), 1e50); - EXPECT_EQ(feat_space.max_phi(), 2); + EXPECT_EQ(feat_space.max_rung(), 2); EXPECT_EQ(feat_space.n_sis_select(), 10); EXPECT_EQ(feat_space.n_samp(), 10); EXPECT_EQ(feat_space.n_feat(), 16); @@ -214,7 +214,7 @@ namespace EXPECT_STREQ(feat_space.feature_space_file().c_str(), "feature_space/selected_features.txt"); EXPECT_EQ(feat_space.l_bound(), 1e-50); EXPECT_EQ(feat_space.u_bound(), 1e50); - EXPECT_EQ(feat_space.max_phi(), 2); + EXPECT_EQ(feat_space.max_rung(), 2); EXPECT_EQ(feat_space.n_sis_select(), 10); EXPECT_EQ(feat_space.n_samp(), 10); EXPECT_EQ(feat_space.n_feat(), 154); @@ -271,7 +271,7 @@ namespace EXPECT_STREQ(feat_space.feature_space_file().c_str(), "feature_space/selected_features.txt"); EXPECT_EQ(feat_space.l_bound(), 1e-50); EXPECT_EQ(feat_space.u_bound(), 1e50); - EXPECT_EQ(feat_space.max_phi(), 2); + EXPECT_EQ(feat_space.max_rung(), 2); EXPECT_EQ(feat_space.n_sis_select(), 10); EXPECT_EQ(feat_space.n_samp(), 10); EXPECT_EQ(feat_space.n_feat(), 154); @@ -327,7 +327,7 @@ namespace EXPECT_STREQ(feat_space.feature_space_file().c_str(), "feature_space/selected_features.txt"); EXPECT_EQ(feat_space.l_bound(), 1e-50); EXPECT_EQ(feat_space.u_bound(), 1e50); - EXPECT_EQ(feat_space.max_phi(), 0); + EXPECT_EQ(feat_space.max_rung(), 0); EXPECT_EQ(feat_space.n_sis_select(), 1); EXPECT_EQ(feat_space.n_samp(), 10); EXPECT_EQ(feat_space.n_feat(), 3);