diff --git a/dlib/serialize.h b/dlib/serialize.h index ae071b319..67db72400 100644 --- a/dlib/serialize.h +++ b/dlib/serialize.h @@ -62,6 +62,7 @@ - std::string - std::wstring - std::vector + - std::deque - std::map - std::set - std::pair @@ -79,6 +80,7 @@ - std::string - std::wstring - std::vector + - std::deque - std::map - std::set - std::pair @@ -143,6 +145,7 @@ #include #include #include +#include #include #include #include @@ -652,6 +655,18 @@ namespace dlib std::istream& in ); + template + void serialize ( + const std::deque& item, + std::ostream& out + ); + + template + void deserialize ( + std::deque& item, + std::istream& in + ); + inline void serialize ( const std::string& item, std::ostream& out @@ -1035,6 +1050,44 @@ namespace dlib { throw serialization_error(e.info + "\n while deserializing object of type std::vector"); } } +// ---------------------------------------------------------------------------------------- + + template + void serialize ( + const std::deque& item, + std::ostream& out + ) + { + try + { + const unsigned long size = static_cast(item.size()); + + serialize(size,out); + for (unsigned long i = 0; i < item.size(); ++i) + serialize(item[i],out); + } + catch (serialization_error& e) + { throw serialization_error(e.info + "\n while serializing object of type std::deque"); } + } + + template + void deserialize ( + std::deque& item, + std::istream& in + ) + { + try + { + unsigned long size; + deserialize(size,in); + item.resize(size); + for (unsigned long i = 0; i < size; ++i) + deserialize(item[i],in); + } + catch (serialization_error& e) + { throw serialization_error(e.info + "\n while deserializing object of type std::deque"); } + } + // ---------------------------------------------------------------------------------------- inline void serialize ( diff --git a/dlib/statistics/running_gradient.h b/dlib/statistics/running_gradient.h index c8fb3468b..a0d0c22d7 100644 --- a/dlib/statistics/running_gradient.h +++ b/dlib/statistics/running_gradient.h @@ -151,6 +151,51 @@ namespace dlib matrix w; double residual_squared; }; + +// ---------------------------------------------------------------------------------------- + + template < + typename T + > + double probability_gradient_less_than ( + const T& container, + double thresh + ) + { + running_gradient g; + for(auto&& v : container) + g.add(v); + + // make sure requires clause is not broken + DLIB_ASSERT(g.current_n() > 2, + "\t double probability_gradient_less_than()" + << "\n\t You need more than 2 elements in the given container to call this function." + ); + return g.probability_gradient_less_than(thresh); + } + + template < + typename T + > + double probability_gradient_greater_than ( + const T& container, + double thresh + ) + { + running_gradient g; + for(auto&& v : container) + g.add(v); + + // make sure requires clause is not broken + DLIB_ASSERT(g.current_n() > 2, + "\t double probability_gradient_greater_than()" + << "\n\t You need more than 2 elements in the given container to call this function." + ); + return g.probability_gradient_greater_than(thresh); + } + +// ---------------------------------------------------------------------------------------- + } #endif // DLIB_RuNNING_GRADIENT_Hh_ diff --git a/dlib/statistics/running_gradient_abstract.h b/dlib/statistics/running_gradient_abstract.h index 4af416fa3..4389721e3 100644 --- a/dlib/statistics/running_gradient_abstract.h +++ b/dlib/statistics/running_gradient_abstract.h @@ -116,6 +116,45 @@ namespace dlib /*! provides serialization support !*/ + +// ---------------------------------------------------------------------------------------- + + template < + typename T + > + double probability_gradient_less_than ( + const T& container, + double thresh + ); + /*! + requires + - container muse be a container of double values that can be enumerated with a + range based for loop. + - The container must contain more than 2 elements. + ensures + - Puts all the elements of container into a running_gradient object, R, and + then returns R.probability_gradient_less_than(thresh). + !*/ + + template < + typename T + > + double probability_gradient_greater_than ( + const T& container, + double thresh + ); + /*! + requires + - container muse be a container of double values that can be enumerated with a + range based for loop. + - The container must contain more than 2 elements. + ensures + - Puts all the elements of container into a running_gradient object, R, and + then returns R.probability_gradient_greater_than(thresh). + !*/ + +// ---------------------------------------------------------------------------------------- + } #endif // DLIB_RuNNING_GRADIENT_ABSTRACT_Hh_ diff --git a/docs/docs/term_index.xml b/docs/docs/term_index.xml index 5149dc5fc..7bce81606 100644 --- a/docs/docs/term_index.xml +++ b/docs/docs/term_index.xml @@ -258,6 +258,8 @@ + +