milankl / BitInformation.jl

Information between bits and bytes.
MIT License
33 stars 3 forks source link

Bitinformation along dimensions of size 2 fails when masked_value given #50

Closed observingClouds closed 2 months ago

observingClouds commented 2 months ago

In https://github.com/observingClouds/xbitinfo/pull/286 popped up a test case, where the dimension along which the bitinformation shall be retrieved has a size of 2. I could trace this back to the Julia implementation:

>>> using BitInformation
>>> A = [1. 2. 3. 4. ; 5. 6. 7. 8.]
2×4 Matrix{Float64}:
 1.0  2.0  3.0  4.0
 5.0  6.0  7.0  8.0

>>> BitInformation.bitinformation(A, dim=1, masked_value=nothing)
64-element Vector{Float64}:
 0.0
 0.0
 0.0
 0.0
 0.0

>>> BitInformation.bitinformation(A, dim=2, masked_value=999.)
64-element Vector{Float64}:
 0.0
 0.0
 0.0
 0.0

>>> BitInformation.bitinformation(A, dim=1, masked_value=999.)
ERROR: AssertionError: Mask has 4 unmasked values, 0 entries are adjacent.
Stacktrace:
 [1] bitinformation(A::Matrix{Float64}, mask::BitMatrix; dim::Int64, set_zero_insignificant::Bool, confidence::Float64)
   @ BitInformation ~/.julia/packages/BitInformation/rcCbn/src/mutual_information.jl:105
 [2] bitinformation
   @ ~/.julia/packages/BitInformation/rcCbn/src/mutual_information.jl:90 [inlined]
 [3] bitinformation(A::Matrix{Float64}; dim::Int64, masked_value::Float64, kwargs::@Kwargs{})
   @ BitInformation ~/.julia/packages/BitInformation/rcCbn/src/mutual_information.jl:72
 [4] top-level scope
   @ REPL[66]:1

Shouldn't the last call work?

milankl commented 2 months ago

Yes, this should work, but this is currently implemented as masking the last element in the first dimension to not count bitpairs across boundaries. Hence, right now you're actually counting bitpairs for

julia> mask
2×4 BitMatrix:
 0  0  0  0
 1  1  1  1

where there is no adjacent pairs to count, hence the assertion error. Not the best algorithm I agree, will change this to a loop that doesn't have that problem!

milankl commented 2 months ago

@JuliaRegistrator register

JuliaRegistrator commented 2 months ago

Registration pull request created: JuliaRegistries/General/112971

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text "Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.2 -m "<description of version>" bda307edfe0b73bf0d296e167246a9fdd9a42516
git push origin v0.6.2
milankl commented 2 months ago

@JuliaRegistrator register

JuliaRegistrator commented 2 months ago

Registration pull request created: JuliaRegistries/General/113147

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text "Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.3 -m "<description of version>" afcc1da45914283da61ff10ab81c412fc9e77929
git push origin v0.6.3