MCPcopy Create free account
hub / github.com/apache/madlib / mLogstateToResult

Function mLogstateToResult

src/modules/regress/multilogistic.cpp:562–599  ·  view source on GitHub ↗

* @brief Compute the diagnostic statistics * * This function wraps the common parts of mlogregr state into the result. * (the result data type is defined in multilogistic.sql_in) */

Source from the content-addressed store, hash-verified

560 * (the result data type is defined in multilogistic.sql_in)
561 */
562AnyType mLogstateToResult(
563 const Allocator &inAllocator,
564 MLogRegrIRLSTransitionState<ArrayHandle<double> > state) {
565
566 int ref_category = state.ref_category;
567 const HandleMap<const ColumnVector, TransparentHandle<double> > &inCoef = state.coef;
568 double logLikelihood = state.logLikelihood;
569 uint64_t num_processed = state.numRows;
570
571 // Per the hack at the end of the final function we place the inverse
572 // of the X_tranp_AX into the state.X_transp_AX
573 const Matrix & X_transp_AX_inverse = state.X_transp_AX;
574 const ColumnVector &diagonal_of_hessian = X_transp_AX_inverse.diagonal();
575
576 MutableNativeColumnVector stdErr(
577 inAllocator.allocateArray<double>(inCoef.size()));
578 MutableNativeColumnVector waldZStats(
579 inAllocator.allocateArray<double>(inCoef.size()));
580 MutableNativeColumnVector waldPValues(
581 inAllocator.allocateArray<double>(inCoef.size()));
582 MutableNativeColumnVector oddsRatios(
583 inAllocator.allocateArray<double>(inCoef.size()));
584
585 for (Index i = 0; i < inCoef.size(); ++i) {
586 stdErr(i) = std::sqrt(diagonal_of_hessian(i));
587 waldZStats(i) = inCoef(i) / stdErr(i);
588 waldPValues(i) = 2. * prob::cdf( prob::normal(),
589 -std::abs(waldZStats(i)));
590 oddsRatios(i) = std::exp( inCoef(i) );
591 }
592 int num_iterations = 0;
593 // Return all coefficients, standard errors, etc. in a tuple
594 AnyType tuple;
595 tuple << ref_category << inCoef << logLikelihood << stdErr
596 << waldZStats << waldPValues << oddsRatios
597 << static_cast<double>(state.conditionNo) << num_iterations << num_processed;
598 return tuple;
599}
600
601
602/**

Callers 1

runMethod · 0.85

Calls 2

cdfFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected