| 165 | } |
| 166 | |
| 167 | float_type |
| 168 | CSMOSolver::calculate_rho(const SyncArray<float_type> &f_val, const SyncArray<int> &y, SyncArray<float_type> &alpha, |
| 169 | float_type Cp, |
| 170 | float_type Cn) const { |
| 171 | int n_free = 0; |
| 172 | double sum_free = 0; |
| 173 | float_type up_value = INFINITY; |
| 174 | float_type low_value = -INFINITY; |
| 175 | const float_type *f_val_data = f_val.host_data(); |
| 176 | const int *y_data = y.host_data(); |
| 177 | float_type *alpha_data = alpha.host_data(); |
| 178 | for (int i = 0; i < alpha.size(); ++i) { |
| 179 | if (is_free(alpha_data[i], y_data[i], Cp, Cn)) { |
| 180 | n_free++; |
| 181 | sum_free += f_val_data[i]; |
| 182 | } |
| 183 | if (is_I_up(alpha_data[i], y_data[i], Cp, Cn)) up_value = min(up_value, f_val_data[i]); |
| 184 | if (is_I_low(alpha_data[i], y_data[i], Cp, Cn)) low_value = max(low_value, f_val_data[i]); |
| 185 | } |
| 186 | return 0 != n_free ? (sum_free / n_free) : (-(up_value + low_value) / 2); |
| 187 | } |
| 188 | |
| 189 | void CSMOSolver::init_f(const SyncArray<float_type> &alpha, const SyncArray<int> &y, const KernelMatrix &k_mat, |
| 190 | SyncArray<float_type> &f_val) const { |