* @brief Perform the logistic-regression transition step */
| 208 | * @brief Perform the logistic-regression transition step |
| 209 | */ |
| 210 | AnyType |
| 211 | logregr_cg_step_transition::run(AnyType &args) { |
| 212 | LogRegrCGTransitionState<MutableArrayHandle<double> > state = args[0]; |
| 213 | if (args[1].isNull() || args[2].isNull()) { return args[0]; } |
| 214 | double y = args[1].getAs<bool>() ? 1. : -1.; |
| 215 | MappedColumnVector x; |
| 216 | try { |
| 217 | // an exception is raised in the backend if args[2] contains nulls |
| 218 | MappedColumnVector xx = args[2].getAs<MappedColumnVector>(); |
| 219 | // x is a const reference, we can only rebind to change its pointer |
| 220 | x.rebind(xx.memoryHandle(), xx.size()); |
| 221 | } catch (const ArrayWithNullException &e) { |
| 222 | return args[0]; |
| 223 | } |
| 224 | |
| 225 | // The following check was added with MADLIB-138. |
| 226 | if (!dbal::eigen_integration::isfinite(x)) { |
| 227 | //throw std::domain_error("Design matrix is not finite."); |
| 228 | warning("Design matrix is not finite."); |
| 229 | state.status = TERMINATED; |
| 230 | return state; |
| 231 | } |
| 232 | |
| 233 | if (state.numRows == 0) { |
| 234 | if (x.size() > std::numeric_limits<uint16_t>::max()){ |
| 235 | //throw std::domain_error( |
| 236 | // "Number of independent variables cannot be " |
| 237 | // "larger than 65535."); |
| 238 | warning("Number of independent variables cannot be larger than 65535."); |
| 239 | state.status = TERMINATED; |
| 240 | return state; |
| 241 | } |
| 242 | |
| 243 | |
| 244 | state.initialize(*this, static_cast<uint16_t>(x.size())); |
| 245 | if (!args[3].isNull()) { |
| 246 | LogRegrCGTransitionState<ArrayHandle<double> > previousState = args[3]; |
| 247 | |
| 248 | state = previousState; |
| 249 | state.reset(); |
| 250 | } |
| 251 | } |
| 252 | // Now do the transition step |
| 253 | state.numRows++; |
| 254 | double xc = dot(x, state.coef); |
| 255 | state.gradNew.noalias() += sigma(-y * xc) * y * trans(x); |
| 256 | |
| 257 | // Note: sigma(-x) = 1 - sigma(x). |
| 258 | // a_i = sigma(x_i c) sigma(-x_i c) |
| 259 | double a = sigma(xc) * sigma(-xc); |
| 260 | //triangularView<Lower>(state.X_transp_AX) += x * trans(x) * a; |
| 261 | state.X_transp_AX += x * trans(x) * a; |
| 262 | |
| 263 | // n |
| 264 | // -- |
| 265 | // l(c) = -\ log(1 + exp(-y_i * c^T x_i)) |
| 266 | // /_ |
| 267 | // i=1 |
nothing calls this directly
no test coverage detected