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

Method run

src/modules/stats/chi_squared_test.cpp:83–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81}
82
83AnyType
84chi2_gof_test_transition::run(AnyType &args) {
85 // §4.15.4 ("Aggregate functions") of ISO/IEC 9075-2:2003, "SQL/Foundation"
86 // demands that rows containing NULLs are ignored
87 // We currently rely on the backend filtering out rows with NULLs, i.e., to
88 // perform an action equivalent to:
89 // for (uint16_t i = 0; i < args.numFields(); ++i)
90 // if (args[i].isNull)
91 // return state;
92
93 Chi2TestTransitionState<MutableArrayHandle<double> > state = args[0];
94 double observed = static_cast<double>(args[1].getAs<int64_t>());
95 double expected = args.numFields() <= 2 ? 1 : args[2].getAs<double>();
96 int64_t df = args.numFields() <= 3 ? 0 : args[3].getAs<int64_t>();
97
98 if (observed < 0)
99 throw std::invalid_argument("Number of observations must be "
100 "nonnegative.");
101 else if (expected < 0)
102 throw std::invalid_argument("Value of expected (count or probability) "
103 "must be nonnegative.");
104 else if (df < 0)
105 throw std::invalid_argument("Degree of freedom must be positive (or 0 "
106 "to use the default of <number of rows> - 1).");
107 else if (state.df != df) {
108 if (state.numRows > 0)
109 throw std::invalid_argument("Degree of freedom must be constant.");
110 state.df = df;
111 }
112
113 updateSumSquaredDeviations(state.numRows.ref(), state.sum_expect.ref(),
114 state.sum_obs_square_over_expect.ref(), state.sum_obs.ref(),
115 state.sumSquaredDeviations.ref(),
116 1, expected, observed * observed / expected,
117 observed, 0);
118
119 return state;
120}
121
122AnyType
123chi2_gof_test_merge_states::run(AnyType &args) {

Callers

nothing calls this directly

Calls 4

NullFunction · 0.85
numFieldsMethod · 0.80
cdfFunction · 0.50

Tested by

no test coverage detected