Coder Social home page Coder Social logo

mlpack bits (logging) about ensmallen HOT 5 CLOSED

mlpack avatar mlpack commented on August 22, 2024
mlpack bits (logging)

from ensmallen.

Comments (5)

conradsnicta avatar conradsnicta commented on August 22, 2024 1

Both are fine. arma::get_cout_stream() is probably best suited to "normal" and expected output, such as printing progress (eg. while executing an iterative algorithm). arma::get_cerr_stream() is best suited for printing warnings and errors.

Alternatively, we can use cout and cerr directly.

In combination with either of the options above, it might be useful to adapt the simple printing approach used by armadillo. Internally, armadillo uses macros such as arma_debug_print and arma_debug_warn, which can be made inactive by the user by defining ARMA_DONT_PRINT_ERRORS.

It's probably not a good idea to directly use arma_debug_print and arma_debug_warn, as these are internal functions. However, it would be easy to create analogues for ensmallen. For example, ens_debug_warn, which would use optional defines such as ENS_DONT_PRINT_ERRORS.

For all the gory details, see armadillo's debug.hpp

from ensmallen.

rcurtin avatar rcurtin commented on August 22, 2024

I think that maybe it might be a good idea here to emulate Armadillo's get_cout_stream() and get_cerr_stream(), so that we can do in some mlpack header, e.g.,

ens::set_cout_stream(Log::Info);
ens::set_cerr_stream(Log::Warn);

and then for any Log::Fatal call we can just throw an exception.

I think that it won't be quite as simple as that; I'll try and find some time in the next day or two to think about if that will actually work. Something simple is good for now, but in the longer term this may also be related to mlpack#1481, where the user would pass some functor that would have some behavior when they wanted to print the loss or something like this.

from ensmallen.

rcurtin avatar rcurtin commented on August 22, 2024

Actually, looks like I wrote my comment too late. :) 71e6979 seems to handle most of this already. Still I'll think about how this can be hooked up more nicely to the mlpack infrastructure when desired. Maybe this?

#ifdef ENS_CUSTOM_INFO_LOG
Info = ENS_CUSTOM_INFO_LOG
#endif

#ifdef ENS_CUSTOM_WARN_LOG
Warn = ENS_CUSTOM_WARN_LOG
#endif

and then before including ensmallen, mlpack headers can just #define ENS_CUSTOM_INFO_LOG mlpack::Log::Info and #define ENS_CUSTOM_WARN_LOG mlpack::Log::Warn. (Also the mlpack header will have to first include the Log headers before including ensmallen, but that shouldn't be an issue---we can control that ordering.)

from ensmallen.

coatless avatar coatless commented on August 22, 2024

This issue seems resolved. Though, in the event future modification happen, please take note that for R to work we need the ability to redirect output / error away from cout / cerr to Rcout and Rcerr, which maps internally to Rprintf and REprintf. The current setup that retrieves information from arma::get_cout_stream()/arma::get_cerr_stream() does allow for this.

References:

from ensmallen.

rcurtin avatar rcurtin commented on August 22, 2024

@coatless: agreed. Right now the code just uses Armadillo's output streams so there should be no problem for Rcpp.

from ensmallen.

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.