* @brief Perform the marginal effects transition step */
| 206 | * @brief Perform the marginal effects transition step |
| 207 | */ |
| 208 | AnyType |
| 209 | margins_linregr_int_transition::run(AnyType &args) { |
| 210 | // Early return because of an exception has been "thrown" |
| 211 | // (actually "warning") in the previous invocations |
| 212 | if (args[0].isNull()) |
| 213 | return Null(); |
| 214 | MarginsLinregrInteractionState<MutableArrayHandle<double> > state = args[0]; |
| 215 | if (args[1].isNull() || args[2].isNull() || |
| 216 | args[3].isNull() || args[4].isNull()) { |
| 217 | return args[0]; |
| 218 | } |
| 219 | MappedColumnVector x; |
| 220 | try { |
| 221 | // an exception is raised in the backend if args[2] contains nulls |
| 222 | MappedColumnVector xx = args[1].getAs<MappedColumnVector>(); |
| 223 | // x is a const reference, we can only rebind to change its pointer |
| 224 | x.rebind(xx.memoryHandle(), xx.size()); |
| 225 | } catch (const ArrayWithNullException &e) { |
| 226 | return args[0]; |
| 227 | } |
| 228 | |
| 229 | // The following check was added with MADLIB-138. |
| 230 | if (!dbal::eigen_integration::isfinite(x)) { |
| 231 | //throw std::domain_error("Design matrix is not finite."); |
| 232 | warning("Design matrix is not finite."); |
| 233 | return Null(); |
| 234 | } |
| 235 | |
| 236 | MappedColumnVector beta = args[2].getAs<MappedColumnVector>(); |
| 237 | |
| 238 | Matrix J_trans = args[4].getAs<MappedMatrix>(); |
| 239 | J_trans.transposeInPlace(); // we actually pass-in J but transpose since |
| 240 | // we only require J^T in our equations |
| 241 | |
| 242 | if (state.numRows == 0) { |
| 243 | if (x.size() > std::numeric_limits<uint16_t>::max()) { |
| 244 | //throw std::domain_error("Number of independent variables cannot be " |
| 245 | // "larger than 65535."); |
| 246 | warning("Number of independent variables cannot be larger than 65535."); |
| 247 | return Null(); |
| 248 | } |
| 249 | state.initialize(*this, |
| 250 | static_cast<uint16_t>(beta.size()), |
| 251 | static_cast<uint16_t>(J_trans.rows())); |
| 252 | Matrix training_data_vcov = args[3].getAs<MappedMatrix>(); |
| 253 | state.training_data_vcov = training_data_vcov; |
| 254 | } |
| 255 | |
| 256 | // Now do the transition step |
| 257 | state.numRows++; |
| 258 | |
| 259 | // compute marginal effects and delta using 1st and 2nd derivatives |
| 260 | state.marginal_effects += J_trans * beta; |
| 261 | state.delta += J_trans; |
| 262 | return state; |
| 263 | } |
| 264 | |
| 265 |
nothing calls this directly
no test coverage detected