| 46 | } |
| 47 | |
| 48 | void |
| 49 | NuSMOSolver::select_working_set(vector<int> &ws_indicator, const SyncArray<int> &f_idx2sort, const SyncArray<int> &y, |
| 50 | const SyncArray<float_type> &alpha, float_type Cp, float_type Cn, |
| 51 | SyncArray<int> &working_set) const { |
| 52 | int n_instances = ws_indicator.size(); |
| 53 | int p_left_p = 0; |
| 54 | int p_left_n = 0; |
| 55 | int p_right_p = n_instances - 1; |
| 56 | int p_right_n = n_instances - 1; |
| 57 | int n_selected = 0; |
| 58 | const int *index = f_idx2sort.host_data(); |
| 59 | const int *y_data = y.host_data(); |
| 60 | const float_type *alpha_data = alpha.host_data(); |
| 61 | int *working_set_data = working_set.host_data(); |
| 62 | int ws_size = working_set.size(); |
| 63 | while (n_selected < ws_size) { |
| 64 | int i; |
| 65 | if (p_left_p < n_instances) { |
| 66 | i = index[p_left_p]; |
| 67 | while (ws_indicator[i] == 1 || !(y_data[i] > 0 && is_I_up(alpha_data[i], y_data[i], Cp, Cn))) { |
| 68 | //construct working set of I_up |
| 69 | p_left_p++; |
| 70 | if (p_left_p == n_instances) break; |
| 71 | i = index[p_left_p]; |
| 72 | } |
| 73 | if (p_left_p < n_instances) { |
| 74 | working_set_data[n_selected++] = i; |
| 75 | ws_indicator[i] = 1; |
| 76 | } |
| 77 | } |
| 78 | if (p_left_n < n_instances) { |
| 79 | i = index[p_left_n]; |
| 80 | while (ws_indicator[i] == 1 || !(y_data[i] < 0 && is_I_up(alpha_data[i], y_data[i], Cp, Cn))) { |
| 81 | //construct working set of I_up |
| 82 | p_left_n++; |
| 83 | if (p_left_n == n_instances) break; |
| 84 | i = index[p_left_n]; |
| 85 | } |
| 86 | if (p_left_n < n_instances && n_selected < ws_size) { |
| 87 | working_set_data[n_selected++] = i; |
| 88 | ws_indicator[i] = 1; |
| 89 | } |
| 90 | } |
| 91 | if (p_right_p >= 0) { |
| 92 | i = index[p_right_p]; |
| 93 | while (ws_indicator[i] == 1 || !(y_data[i] > 0 && is_I_low(alpha_data[i], y_data[i], Cp, Cn))) { |
| 94 | //construct working set of I_low |
| 95 | p_right_p--; |
| 96 | if (p_right_p == -1) break; |
| 97 | i = index[p_right_p]; |
| 98 | } |
| 99 | if (p_right_p >= 0 && n_selected < ws_size) { |
| 100 | working_set_data[n_selected++] = i; |
| 101 | ws_indicator[i] = 1; |
| 102 | } |
| 103 | } |
| 104 | if (p_right_n >= 0) { |
| 105 | i = index[p_right_n]; |