Background
The normalized marginals are calculated as follows (see Section 2.3.1 and 2.3.4):
Margin type |
Formula |
Sum-margin |
![image](https://user-images.githubusercontent.com/9334594/87315383-213bf880-c52d-11ea-8829-14dc6353b743.png) |
Max-margin |
![image](https://user-images.githubusercontent.com/9334594/87315668-5cd6c280-c52d-11ea-8abf-631de6f5c563.png) |
The current implementation of the margin normalization is not exactly the (correct) one described in the paper
In the _marginals
function all marginals (
and
) are divided by
. Originally intended to "increase the numerical stability" of the exponentiation (np.exp
) it actually interferes with the normalization for the sum-margin. Further down the in the pipeline the get_marginals
and get_max_marginals
both use the same normalization function _normalize_marginals_sum_to_one
, if normalized marginals are requested. This is only correct for the sum-marginal though.
Up to this point: If no normalization is requested (normalize=False
), than the max-marginals are correctly calculated, but the sum-marginals have some additional "normalization" step.
In the eval__TFG scripts, we actually request un-normalized marginals. Those are passed to the margin aggregation (over the tree ensemble) where they are normalized according to the sum-margin formula before the topk-acc is calculated for the parameter selection. Later, when the marginals are calculated for the test set, than normalized marginals are requested and this normalization is incorrect for the max-marginal.
How to fix this