miicTeam / miic_R_package

Learning causal or non-causal graphical models using information theory
GNU General Public License v3.0
26 stars 3 forks source link

N_eff value can be wrongly shifted by 1 when computing mutual information #97

Closed franck-simon closed 3 years ago

franck-simon commented 3 years ago

Because of precision loss, the n_eff value can be wrongly shifted by 1 when computing the mutual information: image

honghaoli42 commented 3 years ago

It happens when:

  1. sample_weights are initialized automatically by a uniform weight based on n_eff, https://github.com/miicTeam/miic_R_package/blob/50e15f4f1f5aeb6443e2a84c8cf8f96d8a1f8aa7/src/r_cpp_interface.cpp#L92-L94
  2. n_eff is later re-evaluated as the sum of weights of non-NA samples during the computation, which may lead to the above shift due to loss of precision. https://github.com/miicTeam/miic_R_package/blob/50e15f4f1f5aeb6443e2a84c8cf8f96d8a1f8aa7/src/computation_discrete.cpp#L28 https://github.com/miicTeam/miic_R_package/blob/50e15f4f1f5aeb6443e2a84c8cf8f96d8a1f8aa7/src/computation_continuous.cpp#L320 https://github.com/miicTeam/miic_R_package/blob/50e15f4f1f5aeb6443e2a84c8cf8f96d8a1f8aa7/src/computation_continuous.cpp#L471