Skip to content

Commit

Permalink
Update mutual_information_sensitivity.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
max-de-rooij committed Aug 2, 2024
1 parent e4d6ffe commit 8769b16
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/mutual_information_sensitivity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,11 @@ function _total_order_ci(Xi, Y, entropy_Y, discretization_entropy; n_bootstraps
mi_values = zeros(n_bootstraps)
est = ValueHistogram(Int(round(sqrt(length(Y)))))
Y_perm = copy(Y)
entropy_Xi = entropy(est, Xi)
for i in 1:n_bootstraps
shuffle!(Y_perm)

conditional_entropy = entropy(est, StateSpaceSet(Xi, Y_perm)) - entropy(est, Xi)
conditional_entropy = entropy(est, StateSpaceSet(Xi, Y_perm)) - entropy_Xi
mi_values[i] = (entropy_Y - conditional_entropy) / (entropy_Y - discretization_entropy)
end

Expand All @@ -145,10 +146,12 @@ function _first_order_ci(Xi, Y; n_bootstraps = 100, conf_level = 0.95)
mi_values = zeros(n_bootstraps)
est = ValueHistogram(Int(round(sqrt(length(Y)))))
Y_perm = copy(Y)
entropy_Xi = entropy(est, Xi)
entropy_Y = entropy(est, Y)
for i in 1:n_bootstraps
shuffle!(Y_perm)
mutual_information = entropy(est, Xi) + entropy(est, Y_perm) - entropy(est, StateSpaceSet(Xi, Y_perm))
mi_values[i] = mutual_information / entropy(est, Y_perm)
mutual_information = entropy_Xi + entropy_Y - entropy(est, StateSpaceSet(Xi, Y_perm))
mi_values[i] = mutual_information / entropy_Y
end

α = 1 - conf_level
Expand All @@ -162,11 +165,12 @@ function _second_order_ci(Xi, Xj, Y; n_bootstraps = 100, conf_level = 0.95)
mi_values = zeros(n_bootstraps)
est = ValueHistogram(Int(round(sqrt(length(Y)))))
Y_perm = copy(Y)
mutual_information = entropy(est, Xi) + entropy(est, Xj) - entropy(est, StateSpaceSet(Xi, Xj))
entropy_Y = entropy(est, Y_perm)
for i in 1:n_bootstraps
shuffle!(Y_perm)
conditional_mutual_information = entropy(est, StateSpaceSet(Xi, Y_perm)) + entropy(est, StateSpaceSet(Xj, Y_perm)) - entropy(est, StateSpaceSet(Xi, Xj, Y_perm)) - entropy(est, Y_perm)
mutual_information = entropy(est, Xi) + entropy(est, Xj) - entropy(est, StateSpaceSet(Xi, Xj))
mi_values[i] = (conditional_mutual_information - mutual_information) / entropy(est, Y_perm)
conditional_mutual_information = entropy(est, StateSpaceSet(Xi, Y_perm)) + entropy(est, StateSpaceSet(Xj, Y_perm)) - entropy(est, StateSpaceSet(Xi, Xj, Y_perm)) - entropy_Y
mi_values[i] = (conditional_mutual_information - mutual_information) / entropy_Y
end

α = 1 - conf_level
Expand Down

0 comments on commit 8769b16

Please sign in to comment.