<commit_before>#pragma once

#include "state.hpp"
#include <type_traits>
#include <functional>
#include <string>

namespace ncv
{
        namespace optimize
        {
                ///
                /// \brief describes a multivariate optimization problem
                ///
                template
                <
                        typename tscalar_,
                        typename tsize_,
                        typename top_size,              ///< dimensionality operator: size = op()
                        typename top_fval,              ///< function value operator: f = op(x)
                        typename top_grad,              ///< function value and gradient operator: f = op(x, g)

                        /// disable for not valid types!
                        typename tvalid_tscalar = typename std::enable_if<std::is_floating_point<tscalar_>::value>::type,
                        typename tvalid_tsize = typename std::enable_if<std::is_integral<tsize_>::value>::type
                >
                class problem_t
                {
                public:
                        typedef tscalar_                                                tscalar;
                        typedef tsize_                                                  tsize;

                        /// optimization current/optimum state
                        typedef state_t<tscalar, tsize>                                 tstate;

                        typedef typename tstate::tvector                                tvector;

                        /// logging: warning, error, update (with the current state)
                        typedef std::function<void(const std::string&)>                 twlog;
                        typedef std::function<void(const std::string&)>                 telog;
                        typedef std::function<void(const tstate&)>                      tulog;

                        ///
                        /// \brief constructor (analytic gradient)
                        ///
                        explicit problem_t(
                                const top_size& op_size,
                                const top_fval& op_fval,
                                const top_grad& op_grad)
                                :       m_op_size(op_size),
                                        m_op_fval(op_fval),
                                        m_op_grad(op_grad),
                                        m_eps(std::sqrt(std::numeric_limits<tscalar>::epsilon()))
                        {
                                reset();
                        }

                        ///
                        /// \brief constructor (no analytic gradient, can be estimated)
                        ///
                        explicit problem_t(
                                const top_size& op_size,
                                const top_fval& op_fval)
                                :       problem_t(op_size, op_fval, top_grad())
                        {
                        }

                        ///
                        /// \brief reset statistics
                        ///
                        void reset() const
                        {
                                m_n_fvals = 0;
                                m_n_grads = 0;
                        }

                        ///
                        /// \brief compute dimensionality
                        ///
                        tsize size() const { return _size(); }

                        ///
                        /// \brief compute function value
                        ///
                        tscalar operator()(const tvector& x) const { return _f(x); }

                        ///<commit_msg>custom epsilon to check gradients<commit_after>#pragma once

#include "state.hpp"
#include <type_traits>
#include <functional>
#include <string>

namespace ncv
{
        namespace optimize
        {
                ///
                /// \brief describes a multivariate optimization problem
                ///
                template
                <
                        typename tscalar_,
                        typename tsize_,
                        typename top_size,              ///< dimensionality operator: size = op()
                        typename top_fval,              ///< function value operator: f = op(x)
                        typename top_grad,              ///< function value and gradient operator: f = op(x, g)

                        /// disable for not valid types!
                        typename tvalid_tscalar = typename std::enable_if<std::is_floating_point<tscalar_>::value>::type,
                        typename tvalid_tsize = typename std::enable_if<std::is_integral<tsize_>::value>::type
                >
                class problem_t
                {
                public:
                        typedef tscalar_                                                tscalar;
                        typedef tsize_                                                  tsize;

                        /// optimization current/optimum state
                        typedef state_t<tscalar, tsize>                                 tstate;

                        typedef typename tstate::tvector                                tvector;

                        /// logging: warning, error, update (with the current state)
                        typedef std::function<void(const std::string&)>                 twlog;
                        typedef std::function<void(const std::string&)>                 telog;
                        typedef std::function<void(const tstate&)>                      tulog;

                        ///
                        /// \brief constructor (analytic gradient)
                        ///
                        explicit problem_t(
                                const top_size& op_size,
                                const top_fval& op_fval,
                                const top_grad& op_grad,
                                tscalar eps = std::sqrt(std::numeric_limits<tscalar>::epsilon()))
                                :       m_op_size(op_size),
                                        m_op_fval(op_fval),
                                        m_op_grad(op_grad),
                                        m_eps(eps)
                        {
                                reset();
                        }

                        ///
                        /// \brief constructor (no analytic gradient, can be estimated)
                        ///
                        explicit problem_t(
                                const top_size& op_size,
                                const top_fval& op_fval,
                                tscalar eps = std::sqrt(std::numeric_limits<tscalar>::epsilon()))
                                :       problem_t(op_size, op_fval, top_grad(), eps)
                        {
                        }

                        ///
                        /// \brief reset statistics
                        ///
                        void reset() const
                        {
                                m_n_fvals = 0;
                                m_n_grads = 0;
                        }

                        ///
                        /// \brief compute dimensionality
                        ///
                        tsize size() const { return _size(); }

                        ///
                        /// \brief compute function value
                        ///
                        tscalar operator()(const tvector& x) const { return _f(x); }

                        ///
{'fraction_non_alphanumeric': 0.07360931435963777, 'fraction_numerical': 0.000517464424320828, 'mean_word_length': 0.702863436123348, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4117616', 'n_tokens_mistral': 1637, 'n_tokens_neox': 1441, 'n_words': 349}