* @brief IRLS Transition * @param args * * Arguments (Matched with PSQL wrapped) * - 0: Current State * - 1: y value (Integer) * - 2: numCategories (Integer) * - 3: ref_category (Integer) * - 4: X value (Column Vector) * - 5: Previous State */
| 339 | |
| 340 | */ |
| 341 | AnyType |
| 342 | __mlogregr_irls_step_transition::run(AnyType &args) { |
| 343 | MLogRegrIRLSTransitionState<MutableArrayHandle<double> > state = args[0]; |
| 344 | |
| 345 | if (args[1].isNull() || args[2].isNull() || args[3].isNull() || |
| 346 | args[4].isNull()) { |
| 347 | return args[0]; |
| 348 | } |
| 349 | |
| 350 | // Get x as a vector of double |
| 351 | MappedColumnVector x; |
| 352 | try{ |
| 353 | // an exception is raised in the backend if args[2] contains nulls |
| 354 | MappedColumnVector xx = args[4].getAs<MappedColumnVector>(); |
| 355 | // x is a const reference, we can only rebind to change its pointer |
| 356 | x.rebind(xx.memoryHandle(), xx.size()); |
| 357 | } catch (const ArrayWithNullException &e) { |
| 358 | return args[0]; |
| 359 | } |
| 360 | |
| 361 | // Get the category & numCategories as integer |
| 362 | int32_t category = args[1].getAs<int32_t>(); |
| 363 | // Number of categories after pivoting (we pivot around the first category) |
| 364 | int32_t numCategories = (args[2].getAs<int32_t>() - 1); |
| 365 | int32_t ref_category = args[3].getAs<int32_t>(); |
| 366 | |
| 367 | // The following check was added with MADLIB-138. |
| 368 | if (!x.is_finite()) |
| 369 | throw std::domain_error("Design matrix is not finite."); |
| 370 | |
| 371 | if (state.numRows == 0) { |
| 372 | if (x.size() > std::numeric_limits<uint16_t>::max()) |
| 373 | throw std::domain_error("Number of independent variables cannot be " |
| 374 | "larger than 65535."); |
| 375 | |
| 376 | if (numCategories < 1) |
| 377 | throw std::domain_error("Number of cateogires must be at least 2"); |
| 378 | |
| 379 | // Init the state (requires x.size() and category.size()) |
| 380 | state.initialize(*this, |
| 381 | static_cast<uint16_t>(x.size()) , |
| 382 | static_cast<uint16_t>(numCategories), |
| 383 | static_cast<uint16_t>(ref_category)); |
| 384 | |
| 385 | if (!args[5].isNull()) { |
| 386 | MLogRegrIRLSTransitionState<ArrayHandle<double> > |
| 387 | previousState = args[5]; |
| 388 | state = previousState; |
| 389 | state.reset(); |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | |
| 394 | /* |
| 395 | * This check should be done for each iteration. Only checking the first |
| 396 | * run is not enough. |
| 397 | */ |
| 398 | if (category > numCategories || category < 0) |
nothing calls this directly
no test coverage detected