All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
roboptim::OptimizationLogger< T > Class Template Reference

Log the optimization process (values, Jacobians, time taken etc.). More...

#include <roboptim/core/optimization-logger.hh>

Inheritance diagram for roboptim::OptimizationLogger< T >:
roboptim::SolverCallback< S >

Public Types

enum  LogRequestFlag {
  LOG_X = 1 << 0,
  LOG_COST = 1 << 1,
  LOG_CONSTRAINT = 1 << 2,
  LOG_CONSTRAINT_JACOBIAN = 1 << 3,
  LOG_CONSTRAINT_VIOLATION = 1 << 4,
  LOG_TIME = 1 << 5,
  LOG_SOLVER = 1 << 6
}
 Requests supported by the logger. More...
 
typedef SolverCallback< S > parent_t
 
typedef S solver_t
 
typedef solver_t::problem_t problem_t
 
typedef
solver_t::problem_t::value_type 
value_type
 
typedef
solver_t::problem_t::size_type 
size_type
 
typedef
solver_t::problem_t::result_t 
result_t
 
typedef solver_t::solverState_t solverState_t
 
typedef solver_t::callback_t callback_t
 
typedef
solver_t::problem_t::function_t::traits_t 
traits_t
 
typedef
solver_t::problem_t::function_t 
function_t
 
typedef function_t::matrix_t jacobian_t
 
typedef function_t::argument_t argument_t
 
typedef
function_t::const_argument_ref 
const_argument_ref
 
typedef
GenericDifferentiableFunction
< traits_t
differentiableFunction_t
 
typedef unsigned int logRequest_t
 
- Public Types inherited from roboptim::SolverCallback< S >
typedef S solver_t
 Solver type. More...
 
typedef solver_t::problem_t problem_t
 Solver problem type. More...
 
typedef solver_t::callback_t callback_t
 Per-iteration callback type. More...
 
typedef solver_t::solverState_t solverState_t
 State of the solver. More...
 

Public Member Functions

 OptimizationLogger (solver_t &solver, const boost::filesystem::path &path, bool selfRegister=true, logRequest_t requests=FullLogging())
 Constructor. More...
 
virtual ~OptimizationLogger ()
 Destructor. More...
 
void append (const std::string &text)
 Append extra information to the log file. More...
 
OptimizationLogger< S > & operator<< (const std::string &text)
 Append extra information to the log file. More...
 
template<typename U >
OptimizationLogger< S > & operator<< (const U &u)
 Append extra information to the log file. More...
 
bool isRequested (logRequest_t r) const
 Determine if a given request was made by the user. More...
 
const boost::filesystem::path & logPath () const
 Return the path of the log directory. More...
 
virtual std::ostream & print (std::ostream &o) const
 Display the logger on the specified output stream. More...
 
template<typename U >
OptimizationLogger< T > & operator<< (const U &u)
 
- Public Member Functions inherited from roboptim::SolverCallback< S >
 SolverCallback (const std::string &name="unnamed callback")
 Solver callback constructor. More...
 
virtual ~SolverCallback ()
 Destructor. More...
 
const std::string & name () const
 Return the name of the callback. More...
 
callback_t callback ()
 Callback function. More...
 
void operator() (const problem_t &pb, solverState_t &state)
 Evaluate the callback. More...
 

Static Public Member Functions

static logRequest_t FullLogging ()
 Log everything. More...
 

Protected Member Functions

void perIterationCallback (const problem_t &pb, solverState_t &state)
 Wrapper around the callback function that catch exceptions. More...
 
virtual void perIterationCallbackUnsafe (const typename solver_t::problem_t &pb, typename solver_t::solverState_t &state)
 
const boost::filesystem::path & path () const
 Return the path of the log directory. More...
 
boost::filesystem::path & path ()
 Return the path of the log directory. More...
 
const solver_tsolver () const
 Return the solver associated with the logger. More...
 
solver_tsolver ()
 Return the solver associated with the logger. More...
 
unsigned callbackCallId () const
 Return the callback iteration index. More...
 
- Protected Member Functions inherited from roboptim::SolverCallback< S >
virtual void perIterationCallbackUnsafe (const problem_t &pb, solverState_t &state)=0
 The actual callback function. More...
 

Detailed Description

template<typename T>
class roboptim::OptimizationLogger< T >

Log the optimization process (values, Jacobians, time taken etc.).

Template Parameters
Ssolver type.

Member Typedef Documentation

template<typename T>
typedef function_t::argument_t roboptim::OptimizationLogger< T >::argument_t
template<typename T>
typedef solver_t::callback_t roboptim::OptimizationLogger< T >::callback_t
template<typename T>
typedef function_t::const_argument_ref roboptim::OptimizationLogger< T >::const_argument_ref
template<typename T>
typedef solver_t::problem_t::function_t roboptim::OptimizationLogger< T >::function_t
template<typename T>
typedef function_t::matrix_t roboptim::OptimizationLogger< T >::jacobian_t
template<typename T>
typedef unsigned int roboptim::OptimizationLogger< T >::logRequest_t
template<typename T>
typedef SolverCallback<S> roboptim::OptimizationLogger< T >::parent_t
template<typename T>
typedef solver_t::problem_t roboptim::OptimizationLogger< T >::problem_t
template<typename T>
typedef solver_t::problem_t::result_t roboptim::OptimizationLogger< T >::result_t
template<typename T>
typedef solver_t::problem_t::size_type roboptim::OptimizationLogger< T >::size_type
template<typename T>
typedef S roboptim::OptimizationLogger< T >::solver_t
template<typename T>
typedef solver_t::solverState_t roboptim::OptimizationLogger< T >::solverState_t
template<typename T>
typedef solver_t::problem_t::function_t::traits_t roboptim::OptimizationLogger< T >::traits_t
template<typename T>
typedef solver_t::problem_t::value_type roboptim::OptimizationLogger< T >::value_type

Member Enumeration Documentation

Requests supported by the logger.

TODO: use strongly typed enum when moving to C++11

Enumerator
LOG_X 

Log the argument vector.

LOG_COST 

Log the cost function's values.

LOG_CONSTRAINT 

Log the constraint values.

LOG_CONSTRAINT_JACOBIAN 

Log the constraint Jacobian matrices.

LOG_CONSTRAINT_VIOLATION 

Log the constraint violation.

LOG_TIME 

Log the time.

LOG_SOLVER 

Log the solver.

Constructor & Destructor Documentation

template<typename T >
roboptim::OptimizationLogger< T >::OptimizationLogger ( solver_t solver,
const boost::filesystem::path &  path,
bool  selfRegister = true,
logRequest_t  requests = FullLogging () 
)
explicit

Constructor.

Parameters
solversolver that will be logged.
pathpath to the log directory.
selfRegisterwhether the logger will register itself as a callback with the solver. Set this to false if you use it with a multiplexer.
requestsrequest the logging of specific data.

References roboptim::iendl(), roboptim::OptimizationLogger< T >::isRequested(), roboptim::OptimizationLogger< T >::LOG_CONSTRAINT, roboptim::OptimizationLogger< T >::LOG_CONSTRAINT_VIOLATION, roboptim::OptimizationLogger< T >::LOG_COST, and roboptim::OptimizationLogger< T >::LOG_X.

template<typename T >
roboptim::OptimizationLogger< T >::~OptimizationLogger ( )
virtual

Destructor.

CSV files are written in this destructor.

References roboptim::iendl().

Member Function Documentation

template<typename T >
void roboptim::OptimizationLogger< T >::append ( const std::string &  text)

Append extra information to the log file.

Parameters
texttext to append.

References roboptim::iendl().

template<typename T >
unsigned roboptim::OptimizationLogger< T >::callbackCallId ( ) const
protected

Return the callback iteration index.

Returns
callback iteration index.
template<typename T >
OptimizationLogger< T >::logRequest_t roboptim::OptimizationLogger< T >::FullLogging ( )
static

Log everything.

template<typename T >
bool roboptim::OptimizationLogger< T >::isRequested ( logRequest_t  r) const

Determine if a given request was made by the user.

Parameters
rrequest.
Returns
true if the user made this request.

Referenced by roboptim::OptimizationLogger< T >::OptimizationLogger().

template<typename T >
const boost::filesystem::path & roboptim::OptimizationLogger< T >::logPath ( ) const

Return the path of the log directory.

Note
Seeing that the non-const version of path () needs to be protected, we need to rename this function to make it public, since overload resolution takes place before accessibility checks.
Returns
path of the log directory.
template<typename T >
OptimizationLogger< T > & roboptim::OptimizationLogger< T >::operator<< ( const std::string &  text)

Append extra information to the log file.

Parameters
texttext to append.
template<typename T>
template<typename U >
OptimizationLogger<S>& roboptim::OptimizationLogger< T >::operator<< ( const U &  u)

Append extra information to the log file.

Parameters
uobject to print.
template<typename T>
template<typename U >
OptimizationLogger<T>& roboptim::OptimizationLogger< T >::operator<< ( const U &  u)
template<typename T >
const boost::filesystem::path & roboptim::OptimizationLogger< T >::path ( ) const
protected

Return the path of the log directory.

Note
This function should not be made public since the non-const version is protected.
Returns
path of the log directory.
template<typename T >
boost::filesystem::path & roboptim::OptimizationLogger< T >::path ( )
protected

Return the path of the log directory.

This method is protected since streams would need to be updated, and files that were already written moved to the new location.

Returns
path of the log directory.
template<typename T >
void roboptim::OptimizationLogger< T >::perIterationCallback ( const problem_t pb,
solverState_t state 
)
protectedvirtual

Wrapper around the callback function that catch exceptions.

Parameters
pboptimization problem.
statestate of the solver after an iteration.

Reimplemented from roboptim::SolverCallback< S >.

template<typename T >
void roboptim::OptimizationLogger< T >::perIterationCallbackUnsafe ( const typename solver_t::problem_t pb,
typename solver_t::solverState_t state 
)
protectedvirtual
template<typename T >
std::ostream & roboptim::OptimizationLogger< T >::print ( std::ostream &  o) const
virtual

Display the logger on the specified output stream.

Parameters
ooutput stream used for display.
Returns
output stream.

Reimplemented from roboptim::SolverCallback< S >.

References roboptim::decindent(), roboptim::iendl(), and roboptim::incindent().

template<typename T >
const OptimizationLogger< T >::solver_t & roboptim::OptimizationLogger< T >::solver ( ) const
protected

Return the solver associated with the logger.

Returns
solver associated with the logger.
template<typename T >
OptimizationLogger< T >::solver_t & roboptim::OptimizationLogger< T >::solver ( )
protected

Return the solver associated with the logger.

Returns
solver associated with the logger.