54#ifndef DOXYGEN_SHOULD_SKIP_THIS
70 template <
typename CellContribFn >
72 CellContribFn cellContrib) {
77 const std::size_t all_size = N_xyz.size();
82 if (nodeId2cols.empty()) {
86 var_x = nodeId2cols.second(idset[0]);
87 var_y = nodeId2cols.second(idset[1]);
93 double cumulStat = 0.0;
94 std::size_t n_skipped = 0;
95 const std::size_t Z_size
96 = idset.hasConditioningSet() ? all_size / (X_size * Y_size) : std::size_t(1);
98 if (idset.hasConditioningSet()) {
99 std::vector< double > N_xz
100 = this->marginalize_(std::size_t(1), X_size, Y_size, Z_size, N_xyz);
101 std::vector< double > N_yz
102 = this->marginalize_(std::size_t(0), X_size, Y_size, Z_size, N_xyz);
103 std::vector< double > N_z
104 = this->marginalize_(std::size_t(2), X_size, Y_size, Z_size, N_xyz);
106 for (std::size_t z = 0, beg_xz = 0, beg_yz = 0, xyz = 0; z < Z_size;
107 ++z, beg_xz += X_size, beg_yz += Y_size) {
109 for (std::size_t y = std::size_t(0), yz = beg_yz; y < Y_size; ++yz, ++y) {
110 for (std::size_t x = std::size_t(0), xz = beg_xz; x < X_size; ++xz, ++x, ++xyz) {
114 if (N_yz[yz] * N_xz[xz] != 0.0) {
115 cumulStat += cellContrib(N_xyz[xyz], N_xz[xz], N_yz[yz], N_z[z]);
122 n_skipped += X_size * Y_size;
123 xyz += X_size * Y_size;
127 std::vector< double > N_x
128 = this->marginalize_(std::size_t(1), X_size, Y_size, std::size_t(1), N_xyz);
129 std::vector< double > N_y
130 = this->marginalize_(std::size_t(0), X_size, Y_size, std::size_t(1), N_xyz);
133 for (
const auto n_x: N_x)
136 for (std::size_t y = std::size_t(0), xy = 0; y < Y_size; ++y) {
137 for (std::size_t x = 0; x < X_size; ++x, ++xy) {
138 if (N_y[y] * N_x[x] != 0.0) {
139 cumulStat += cellContrib(N_xyz[xy], N_x[x], N_y[y], N);
147 Size df = degreesOfFreedom_(X_size, Y_size, Z_size, n_skipped);
149 return {cumulStat, pValue};
The class that represents the chi2 distribution.
static double probaChi2(double x, Size df)
Computes the probability of chi2 value.
RecordCounter counter_
the record counter used for the counts over discrete variables
Prior * prior_
the expert knowledge prior added to the contingency tables
const DatabaseTable & database() const
return the database used by the score
std::size_t domainSize(const std::size_t k, const bool k_is_input_col=false) const
returns the domain size of the kth variable of the database table or of that of the first one corresp...
A class for storing a pair of sets of NodeIds, the second one corresponding to a conditional set.
std::pair< double, double > computeStatistics_(const IdCondSet &idset, CellContribFn cellContrib)
shared loop for chi-squared-family statistics
virtual bool isInformative() const =0
indicates whether the prior is potentially informative
virtual void addJointPseudoCount(const IdCondSet &idset, std::vector< double > &counts)=0
adds the prior to a counting vector corresponding to the idset
const DatabaseTable & database() const
returns the database on which we perform the counts
const Bijection< NodeId, std::size_t > & nodeId2Columns() const
returns the mapping from ids to column positions in the database
const std::vector< double > & counts(const IdCondSet &ids, const bool check_discrete_vars=false)
returns the counts over all the variables in an IdCondSet
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size Idx
Type for indexes.
the base class for all the independence tests used for learning
include the inlined functions if necessary
gum is the global namespace for all aGrUM entities