| 121 | } |
| 122 | |
| 123 | void |
| 124 | CSMOSolver::select_working_set(vector<int> &ws_indicator, const SyncArray<int> &f_idx2sort, const SyncArray<int> &y, |
| 125 | const SyncArray<float_type> &alpha, float_type Cp, float_type Cn, |
| 126 | SyncArray<int> &working_set) const { |
| 127 | int n_instances = ws_indicator.size(); |
| 128 | int p_left = 0; |
| 129 | int p_right = n_instances - 1; |
| 130 | int n_selected = 0; |
| 131 | const int *index = f_idx2sort.host_data(); |
| 132 | const int *y_data = y.host_data(); |
| 133 | const float_type *alpha_data = alpha.host_data(); |
| 134 | int *working_set_data = working_set.host_data(); |
| 135 | while (n_selected < working_set.size()) { |
| 136 | int i; |
| 137 | if (p_left < n_instances) { |
| 138 | i = index[p_left]; |
| 139 | while (ws_indicator[i] == 1 || !is_I_up(alpha_data[i], y_data[i], Cp, Cn)) { |
| 140 | //construct working set of I_up |
| 141 | p_left++; |
| 142 | if (p_left == n_instances) break; |
| 143 | i = index[p_left]; |
| 144 | } |
| 145 | if (p_left < n_instances) { |
| 146 | working_set_data[n_selected++] = i; |
| 147 | ws_indicator[i] = 1; |
| 148 | } |
| 149 | } |
| 150 | if (p_right >= 0) { |
| 151 | i = index[p_right]; |
| 152 | while (ws_indicator[i] == 1 || !is_I_low(alpha_data[i], y_data[i], Cp, Cn)) { |
| 153 | //construct working set of I_low |
| 154 | p_right--; |
| 155 | if (p_right == -1) break; |
| 156 | i = index[p_right]; |
| 157 | } |
| 158 | if (p_right >= 0) { |
| 159 | working_set_data[n_selected++] = i; |
| 160 | ws_indicator[i] = 1; |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | float_type |
| 168 | CSMOSolver::calculate_rho(const SyncArray<float_type> &f_val, const SyncArray<int> &y, SyncArray<float_type> &alpha, |