| 72 | */ |
| 73 | template <class T1, class T2, class T3, class T4> |
| 74 | class Algorithm { |
| 75 | public: |
| 76 | int model_fit_max; // Maximum number of iterations taken for the primary model fitting. |
| 77 | int model_type; // primary model type. |
| 78 | int algorithm_type; // algorithm type. |
| 79 | int group_df = 0; // freedom |
| 80 | int sparsity_level = 0; // Number of non-zero coefficients. |
| 81 | double lambda_level = 0; // l2 normalization coefficients. |
| 82 | int max_iter; // Maximum number of iterations taken for the splicing algorithm to converge. |
| 83 | int exchange_num; // Max exchange variable num. |
| 84 | bool warm_start; // When tuning the optimal parameter combination, whether to use the last solution as a warm start |
| 85 | // to accelerate the iterative convergence of the splicing algorithm. |
| 86 | T4 *x = NULL; |
| 87 | T1 *y = NULL; |
| 88 | T2 beta; // coefficients. |
| 89 | Eigen::VectorXd bd; // sacrifices. |
| 90 | T3 coef0; // intercept. |
| 91 | double train_loss = 0.; // train loss. |
| 92 | T2 beta_init; // initialization coefficients. |
| 93 | T3 coef0_init; // initialization intercept. |
| 94 | Eigen::VectorXi A_init; // initialization active set. |
| 95 | Eigen::VectorXi I_init; // initialization inactive set. |
| 96 | Eigen::VectorXd bd_init; // initialization bd vector. |
| 97 | |
| 98 | Eigen::VectorXi A_out; // final active set. |
| 99 | Eigen::VectorXi I_out; // final active set. |
| 100 | |
| 101 | bool lambda_change; // lambda_change or not. |
| 102 | |
| 103 | Eigen::VectorXi always_select; // always select variable. |
| 104 | double tau; // algorithm stop threshold |
| 105 | int primary_model_fit_max_iter; // The maximal number of iteration for primaty model fit |
| 106 | double primary_model_fit_epsilon; // The epsilon (threshold) of iteration for primaty model fit |
| 107 | |
| 108 | T2 beta_warmstart; // warmstart beta. |
| 109 | T3 coef0_warmstart; // warmstart intercept. |
| 110 | |
| 111 | double effective_number; // effective number of parameter. |
| 112 | int splicing_type; // exchange number update mathod. |
| 113 | int sub_search; // size of sub_searching in splicing |
| 114 | int U_size; |
| 115 | |
| 116 | double beta_range[2] = {-DBL_MAX, DBL_MAX}; |
| 117 | |
| 118 | Algorithm() = default; |
| 119 | |
| 120 | virtual ~Algorithm(){}; |
| 121 | |
| 122 | Algorithm(int algorithm_type, int model_type, int max_iter = 100, int primary_model_fit_max_iter = 10, |
| 123 | double primary_model_fit_epsilon = 1e-8, bool warm_start = true, int exchange_num = 5, |
| 124 | Eigen::VectorXi always_select = Eigen::VectorXi::Zero(0), int splicing_type = 0, int sub_search = 0) { |
| 125 | this->max_iter = max_iter; |
| 126 | this->model_type = model_type; |
| 127 | // this->coef0_init = 0.0; |
| 128 | this->warm_start = warm_start; |
| 129 | this->exchange_num = exchange_num; |
| 130 | this->always_select = always_select; |
| 131 | this->algorithm_type = algorithm_type; |
nothing calls this directly
no outgoing calls
no test coverage detected