| 144 | // ---------------------------------------------------------------------- |
| 145 | |
| 146 | AnyType rb_coxph_step_transition::run(AnyType& args) |
| 147 | { |
| 148 | RBCoxPHTransitionState<MutableArrayHandle<double> > state = args[0]; |
| 149 | if (args[1].isNull() || args[2].isNull()) { return args[0]; } |
| 150 | MappedColumnVector x; |
| 151 | try { |
| 152 | // an exception is raised in the backend if input data contains nulls |
| 153 | MappedColumnVector xx = args[1].getAs<MappedColumnVector>(); |
| 154 | // x is a const reference, we can only rebind to change its pointer |
| 155 | x.rebind(xx.memoryHandle(), xx.size()); |
| 156 | } catch (const ArrayWithNullException &e) { |
| 157 | // independent variable array contains NULL. We skip this row |
| 158 | return args[0]; |
| 159 | } |
| 160 | double y = args[2].getAs<double>(); |
| 161 | bool status; |
| 162 | if (args[3].isNull()) { |
| 163 | // by default we assume that the data is uncensored => status = TRUE |
| 164 | status = true; |
| 165 | } else { |
| 166 | status = args[3].getAs<bool>(); |
| 167 | } |
| 168 | |
| 169 | MappedColumnVector H = args[6].getAs<MappedColumnVector>(); |
| 170 | double S = args[7].getAs<double>(); |
| 171 | |
| 172 | // The following check was added with MADLIB-138. |
| 173 | if (!dbal::eigen_integration::isfinite(x)) |
| 174 | throw std::domain_error("Design matrix is not finite."); |
| 175 | |
| 176 | if (x.size() > std::numeric_limits<uint16_t>::max()) |
| 177 | throw std::domain_error( |
| 178 | "Number of independent variables cannot be larger than 65535."); |
| 179 | |
| 180 | if (state.numRows == 0) { |
| 181 | state.initialize(*this, static_cast<uint16_t>(x.size()), |
| 182 | args[4].getAs<MappedColumnVector>().data(), |
| 183 | args[5].getAs<MappedMatrix>().data()); |
| 184 | } |
| 185 | |
| 186 | state.numRows++; |
| 187 | |
| 188 | /** In case of a tied time of death or in the first iteration: |
| 189 | We must only perform the "pre compuations". When the tie is resolved |
| 190 | we add up all the precomputations once in for all. This is |
| 191 | an implementation of Breslow's method. |
| 192 | The time of death for two records are considered "equal" if they |
| 193 | differ by less than 1.0e-6. |
| 194 | Also, in case status = 0, the observation must be censored so no |
| 195 | computations are required |
| 196 | */ |
| 197 | |
| 198 | if (std::abs(y-state.y_previous) > 1.0e-6 && state.numRows != 1) { |
| 199 | state.M = state.M - (state.tie12 + trans(state.tie12)) * state.A |
| 200 | + (state.tie13 * trans(state.B) + state.B * trans(state.tie13)) |
| 201 | - (state.tie23 * trans(state.B) + state.B * trans(state.tie23)) * state.A |
| 202 | + state.tie22 * state.A * state.A + state.tie33 * state.B * trans(state.B); |
| 203 | state.tie12.setZero(); |
nothing calls this directly
no test coverage detected