NumPy Adapter - Counting Helpers¶
Stateless counting helpers used by the NumPy adapter. They were
extracted into this sibling module so that causaliq_data.numpy stays within
the module size limits described in the
development policy.
The adapter passes all state to these functions as arguments, so the
NumPy.MAX_BINCOUNT class attribute remains the single place that selects
the fast packing path over the slower NumPy unique path.
Combination Counting¶
combinations_from_binning
¶
combinations_from_binning(
sample_cols: ndarray, num_vals: ndarray, n_reqd: int, minlength: int
) -> Tuple[ndarray, ndarray]
Count unique combinations of values by packing them into integers.
Parameters:
-
(sample_cols¶ndarray) –Sample values for the required columns.
-
(num_vals¶ndarray) –Number of values in each of those columns.
-
(n_reqd¶int) –Number of columns required.
-
(minlength¶int) –Maximum possible number of value combinations.
Returns:
-
Tuple[ndarray, ndarray]–Tuple of unique value combinations and their counts.
crosstab_counts
¶
crosstab_counts(
combos: ndarray, combo_counts: ndarray, n_child_values: int
) -> Tuple[ndarray, ndarray]
Return a counts matrix of child values against parental combos.
Parameters:
-
(combos¶ndarray) –Unique value combinations, with child value first.
-
(combo_counts¶ndarray) –Count of each unique value combination.
-
(n_child_values¶int) –Number of distinct child values.
Returns:
-
Tuple[ndarray, ndarray]–Tuple of counts matrix and unique parental combinations.
Categorical Counts¶
categorical_value_counts
¶
categorical_value_counts(
sample: ndarray,
categories: ndarray,
nodes: Tuple[str, ...],
orig_to_ext: Dict[str, str],
) -> Dict[str, Dict[str, int]]
Return value counts for each categorical column of a sample.
Parameters:
-
(sample¶ndarray) –Sample data array.
-
(categories¶ndarray) –Category values for each column.
-
(nodes¶Tuple[str, ...]) –Internal (i.e. original) node names.
-
(orig_to_ext¶Dict[str, str]) –Map from original to external names.
Returns:
-
Dict[str, Dict[str, int]]–Value counts for each categorical node.