desdeo_brb.inference¶
Low-level NumPy inference functions. These implement the four steps of the RIMER pipeline: input transform, activation weights, combined belief degrees (via evidential reasoning), and scalar output.
inference
¶
Pure functions implementing the BRB inference pipeline.
Each function corresponds to one step in the BRB evidential reasoning process: input transformation, activation weight computation, belief combination, and output aggregation. All functions are vectorized over samples.
input_transform
¶
Transform raw inputs into belief distributions over referential values.
Implements Eq. A-1 from Chen et al. (2011). For each attribute, computes matching degrees (alphas) describing how strongly each input relates to each referential value using piecewise-linear interpolation with wrapping boundary conditions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
Input array of shape |
required |
referential_values
|
list[ndarray]
|
List of 1-D arrays, one per attribute, each containing the sorted referential values for that attribute. Arrays may have different lengths. |
required |
Returns:
| Type | Description |
|---|---|
list[ndarray]
|
List of 2-D arrays, one per attribute. The i-th array has shape |
list[ndarray]
|
|
list[ndarray]
|
degrees for each sample over the i-th attribute's referential values. |
Notes
Following the RIMER wrapping boundary conditions (Yang et al. 2006), inputs outside the referential value range are clamped to the nearest boundary. This means inputs below the minimum get belief degree 1.0 at the first referential value, and inputs above the maximum get belief degree 1.0 at the last referential value. At most two adjacent referential values receive nonzero belief, and they always sum to 1.
Source code in src/desdeo_brb/inference.py
compute_activation_weights
¶
compute_activation_weights(alphas: list[ndarray], rule_antecedent_indices: ndarray, thetas: ndarray, deltas: ndarray) -> ndarray
Compute the activation weight of each rule given input belief distributions.
Implements Eq. A-3 from Chen et al. (2011).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alphas
|
list[ndarray]
|
List of 2-D arrays from :func: |
required |
rule_antecedent_indices
|
ndarray
|
2-D integer array of shape
|
required |
thetas
|
ndarray
|
1-D array of rule weights, shape |
required |
deltas
|
ndarray
|
2-D array of attribute weights, shape
|
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
2-D array of shape |
ndarray
|
that sum to 1 across rules for each sample. |
Notes
When all matching degrees for a rule are zero the rule does not fire. A small epsilon (1e-12) is added only to the denominator during normalization to avoid division by zero; the numerator products are computed without any epsilon.
Source code in src/desdeo_brb/inference.py
compute_combined_belief_degrees
¶
Combine activated belief degrees using the analytical evidential reasoning algorithm.
Implements Eq. A-15 from Chen et al. (2011) / Eq. 3.20 from the thesis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bre_matrix
|
ndarray
|
2-D array of shape |
required |
weights
|
ndarray
|
2-D array of shape |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
2-D array of shape |
ndarray
|
belief degrees. |
Notes
Products over rules are computed in log-space for numerical stability. When a rule's activation weight is zero for a given sample, that rule contributes a multiplicative factor of 1 (i.e., is skipped). This is achieved by setting the log-space contribution to 0 for inactive rules.
The formula is:
.. math::
\beta_n = \frac{
\prod_k (w_k \beta_{n,k} + 1 - w_k \sum_j \beta_{j,k})
- \prod_k (1 - w_k \sum_j \beta_{j,k})
}{
\sum_j \prod_k (w_k \beta_{j,k} + 1 - w_k \sum_j \beta_{j,k})
- (N-1) \prod_k (1 - w_k \sum_j \beta_{j,k})
- \prod_k (1 - w_k)
}
Source code in src/desdeo_brb/inference.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
compute_output
¶
compute_output(belief_degrees: ndarray, consequents: ndarray, utility_fn: Callable[[ndarray], ndarray] | None = None) -> ndarray
Compute scalar outputs from combined belief degrees and consequent values.
Applies a utility function to the consequent referential values, then computes the weighted sum with the combined belief degrees.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
belief_degrees
|
ndarray
|
2-D array of shape |
required |
consequents
|
ndarray
|
1-D array of shape |
required |
utility_fn
|
Callable[[ndarray], ndarray] | None
|
Optional function mapping consequent values to utilities.
Signature: |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
1-D array of shape |