Giter VIP home page Giter VIP logo

Comments (13)

syclik avatar syclik commented on May 18, 2024

Things that need to happen:

  1. Create a new, parallel file to the check_* file called is_*.
  2. Add a new, parallel file to the test file.
  3. Add tests for the new function.
  4. Write the new function.
  5. Change the implementation of the check.

Later down the road, we'll need to reopen stan#1104 and expose all the functions. And add it to the doc.

from math.

seantalts avatar seantalts commented on May 18, 2024

Hey, Bob was suggesting I take a crack at this and I have a few questions about what we want to do here. First, my attempt to paraphrase the high level goal: We want to allow Stan users to use a standard set of error checking functions for use typically in their Stan code's functions block (i.e. User Defined Functions), and we think the functions listed above on this ticket are good candidates for end use. I'm a bit lost as to why we want to create copies of the checks with slightly different names (the check_* -> is_* step above)? Also, Bob mentioned that we wanted to do some clean up and vectorization here, and I'm wondering what the clean up especially should look like. @bob-carpenter might be the best person to answer at least parts of this.

from math.

bob-carpenter avatar bob-carpenter commented on May 18, 2024

from math.

seantalts avatar seantalts commented on May 18, 2024

Just to be clear, are we expecting things like is_positive to be vectorized, or just the check_positive version? Given that bool is_positive(...) couldn't return information about where the error occurred, I think the latter makes more sense but just want to run that by you guys while I'm working on it.

from math.

bob-carpenter avatar bob-carpenter commented on May 18, 2024

from math.

kw-fn avatar kw-fn commented on May 18, 2024

https://github.com/stan-dev/math/tree/feature/issue-50-boolean_functions
https://github.com/stan-dev/math/tree/feature/issue-50-error_handling_functions

from math.

syclik avatar syclik commented on May 18, 2024

@bob-carpenter, I forgot that there's another reason for these error checking functions. I was thinking that we'd have the boolean functions able to take in the different Stan types, including arrays. The check functions would be responsible for passing the right information back to the user. But a user could use these functions.

So... if we have something like:

vector[3] x[4]

from the Stan language, we could do something like is_positive(x) and it'll give us a sensible result.

The check_positive() would really try to indicate which element was wrong. Maybe at some point, we can have the generated code pass in the correct variable name (cc @seantalts @VMatthijs), but that's beyond the scope of this issue.

from math.

peterwicksstringfield avatar peterwicksstringfield commented on May 18, 2024

These check_ functions are still missing corresponding is_ functions:

  • stan/math/prim/err/check_vector.hpp
    Don't be confused, there's an is_vector; but it's a compile time check implemented with a meta program. Totally different thing.
  • stan/math/prim/err/check_simplex.hpp
  • stan/math/prim/err/check_positive_ordered.hpp
  • stan/math/prim/err/check_pos_semidefinite.hpp
  • stan/math/prim/err/check_cov_matrix.hpp
  • stan/math/prim/err/check_positive_finite.hpp
  • stan/math/prim/err/check_nonnegative.hpp
  • stan/math/prim/err/check_less.hpp
  • stan/math/prim/err/check_greater_or_equal.hpp
  • stan/math/prim/err/check_greater.hpp
    There is an is_less_or_equal, but is_less, is_greater, and is_greater_or_equal are missing.
  • stan/math/prim/err/check_bounded.hpp
  • stan/math/prim/err/check_multiplicable.hpp
  • stan/math/prim/err/check_row_index.hpp
    There is an is_column_index, but is_row_index is missing.
  • stan/math/prim/err/check_vector_index.hpp
  • stan/math/prim/err/check_range.hpp

These missing is functions obviously aren't needed in the math library, so the only reason to create them would be to expose them to Stan users. If we don't want to do that this ticket should be closed.

I don't think we need is functions for these. They don't seem like the kind of conditions that Stan users would want to evaluate (?):

  • stan/math/prim/err/check_consistent_size.hpp
  • stan/math/prim/err/check_consistent_sizes.hpp
  • stan/math/prim/err/check_consistent_size_mvt.hpp
  • stan/math/prim/err/check_consistent_sizes_mvt.hpp
  • stan/math/prim/err/check_2F1_converges.hpp
  • stan/math/prim/err/check_3F2_converges.hpp

Nor do we need is functions for these:

  • stan/math/prim/err/check_nonempty.hpp
    check_nonempty is redundant with check_nonzero_size and is_nonzero_size.
  • stan/math/prim/err/check_std_vector_index.hpp
    check_std_vector_index is redundant with check_vector_index; we do need an is_vector_index though.

from math.

bob-carpenter avatar bob-carpenter commented on May 18, 2024

Excellent summary. Yes, we still want to expose both check-X and is-X functions in Stan.

I think we may be missing extensions of some of these to containers, which we also need in the math lib. There are still lots of places in math lib code with checks embedded in loops that should be refactored in order to report the index properly and simplify code.

from math.

peterwicksstringfield avatar peterwicksstringfield commented on May 18, 2024

Yeah. Stuff like check_symmetric can easily be lifted to work on std::vector<std::vector<Eigen::MatrixXd>> and so forth.

from math.

bob-carpenter avatar bob-carpenter commented on May 18, 2024

That would be good for the multivariate distributions and just so that everything works the same way no matter the base type on which the test is being done.

from math.

kw-fn avatar kw-fn commented on May 18, 2024

The bulk of these functions have been finished and tested here: https://github.com/kw-fn/math, unfortunately at the time I was working on this the rest of library was going through a series of changes which caused the PR to bit-rot rather quickly, since I didn't have the capacity to solve the (then rather deep) compiler errors the PR has stalled. It would be great to see if the codes can be safely integrated into the Stan-lang math library.

from math.

kw-fn avatar kw-fn commented on May 18, 2024

(+) I have some free time to push this.

from math.

Related Issues (20)

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.