Code Monkey home page Code Monkey logo

Comments (3)

observingClouds avatar observingClouds commented on June 22, 2024

I just add to this that I could imagine that BitInformation.jl would raise a user defined error, which could be as simple as

    type DimensionalityError <: Exception
    end
    type DimensionalityErrorTree <: Exception
        var::String
    end

    Base.showerror(io::IO, e:: DimensionalityErrorTree) = print(io, "You try to calculate bitinformation along a (too) short dimension of",e.var, "elements.")

    julia> throw(DimensionalityError(Len(data[dim])))

Not sure if this is the correct syntax. I just adapted it from here.

This would be easier to catch from calling scripts.

from bitinformation.jl.

milankl avatar milankl commented on June 22, 2024

At the moment we are doing

C = bitpair_count(A,mask) # nbits x 2 x 2 array of bitpair counters
nelements = sum(C[1,:,:]) # depending on mask nelements changes so obtain via C
@assert nelements > 0 "Mask has $(sum(.~mask)) unmasked values, 0 entries are adjacent."

So we count the bits but if the counter is still zero afterwards an AssertionError is triggered.

julia> using BitInformation
julia> A = rand(100);
julia> mask = A .== A;
julia> bitinformation(A,mask)
ERROR: AssertionError: Mask has 0 unmasked values, 0 entries are adjacent.
Stacktrace:
 [1] bitinformation(A::Vector{Float64}, mask::BitVector; dim::Int64, set_zero_insignificant::Bool, confidence::Float64)
   @ BitInformation ~/.julia/packages/BitInformation/VpaaY/src/mutual_information.jl:105
...

Julia has a bunch of error types. I agree that an AssertionError is maybe not the most telling and that we may want to reconsider what kind of error is thrown. However, it seems that this AssertionError is only propagated as a string in the error message (why are python error messages always sooo long 😄) probably because the python errors are not matched to julia errors. Meaning that whether we decide for another error type or define our own, this would only be of use if you could actually catch that error somehow. And what do you want to do with it if you catch it?

from bitinformation.jl.

milankl avatar milankl commented on June 22, 2024

You try to calculate bitinformation along a (too) short dimension of {length(data[dim])} elements. Maybe even continuing ... bitinformation assumes that adjacents analysis elements are also physically adjacent...

Feel free to suggest error messages. I'd rather have it short and on the point though. I don't think it's the job of an error message to explain how a function is used though, this should be part of the docstring / documentation. On that note I don't think the masked array support ever made it into the documentation ... 😞

from bitinformation.jl.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.