From b21dd37edf11df490f4b9e107dc35fa1eed17380 Mon Sep 17 00:00:00 2001 From: Davis King Date: Fri, 15 May 2009 17:56:24 +0000 Subject: [PATCH] Added the null_trainer_type object. --HG-- extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403037 --- dlib/svm.h | 1 + dlib/svm/null_trainer.h | 61 ++++++++++++++++++++ dlib/svm/null_trainer_abstract.h | 97 ++++++++++++++++++++++++++++++++ 3 files changed, 159 insertions(+) create mode 100644 dlib/svm/null_trainer.h create mode 100644 dlib/svm/null_trainer_abstract.h diff --git a/dlib/svm.h b/dlib/svm.h index 784520504..51e04800b 100644 --- a/dlib/svm.h +++ b/dlib/svm.h @@ -15,6 +15,7 @@ #include "svm/rvm.h" #include "svm/pegasos.h" #include "svm/sparse_kernel.h" +#include "svm/null_trainer.h" #endif // DLIB_SVm_HEADER diff --git a/dlib/svm/null_trainer.h b/dlib/svm/null_trainer.h new file mode 100644 index 000000000..f3137d4ad --- /dev/null +++ b/dlib/svm/null_trainer.h @@ -0,0 +1,61 @@ +// Copyright (C) 2009 Davis E. King (davisking@users.sourceforge.net) +// License: Boost Software License See LICENSE.txt for the full license. +#ifndef DLIB_NULL_TRAINERs_H_ +#define DLIB_NULL_TRAINERs_H_ + +#include "null_trainer_abstract.h" +#include "../algs.h" +#include "function_abstract.h" + +namespace dlib +{ + +// ---------------------------------------------------------------------------------------- + + template < + typename dec_funct_type + > + class null_trainer_type + { + public: + typedef typename dec_funct_type::kernel_type kernel_type; + typedef typename dec_funct_type::scalar_type scalar_type; + typedef typename dec_funct_type::sample_type sample_type; + typedef typename dec_funct_type::mem_manager_type mem_manager_type; + typedef dec_funct_type trained_function_type; + + null_trainer_type ( + ){} + + null_trainer_type ( + const dec_funct_type& dec_funct_ + ) : dec_funct(dec_funct_) {} + + template < + typename in_sample_vector_type, + typename in_scalar_vector_type + > + const dec_funct_type& train ( + const in_sample_vector_type& , + const in_scalar_vector_type& + ) const { return dec_funct; } + + private: + dec_funct_type dec_funct; + }; + +// ---------------------------------------------------------------------------------------- + + template < + typename dec_funct_type + > + const null_trainer_type null_trainer ( + const dec_funct_type& dec_funct + ) { return null_trainer_type(dec_funct); } + +// ---------------------------------------------------------------------------------------- + +} + +#endif // DLIB_NULL_TRAINERs_H_ + diff --git a/dlib/svm/null_trainer_abstract.h b/dlib/svm/null_trainer_abstract.h new file mode 100644 index 000000000..df1945c81 --- /dev/null +++ b/dlib/svm/null_trainer_abstract.h @@ -0,0 +1,97 @@ +// Copyright (C) 2009 Davis E. King (davisking@users.sourceforge.net) +// License: Boost Software License See LICENSE.txt for the full license. +#undef DLIB_NULL_TRAINERs_ABSTRACT_ +#ifdef DLIB_NULL_TRAINERs_ABSTRACT_ + +#include "../algs.h" +#include "function_abstract.h" + +namespace dlib +{ + +// ---------------------------------------------------------------------------------------- + + template < + typename dec_funct_type + > + class null_trainer_type + { + /*! + WHAT THIS OBJECT REPRESENTS + This object is a simple tool for turning a decision function + into a trainer object that always returns the original decision + function when you try to train with it. + + dlib contains a few "training post processing" algorithms (e.g. + reduced and reduced2()). These tools take in a trainer object, + tell it to perform training, and then they take the output decision + function and do some kind of post processing to it. The null_trainer_type + object is useful because you can use it to run an already + learned decision function through the training post processing + algorithms by turning a decision function into a null_trainer_type + and then giving it to a post processor. + !*/ + + public: + typedef typename dec_funct_type::kernel_type kernel_type; + typedef typename dec_funct_type::scalar_type scalar_type; + typedef typename dec_funct_type::sample_type sample_type; + typedef typename dec_funct_type::mem_manager_type mem_manager_type; + typedef dec_funct_type trained_function_type; + + null_trainer_type ( + ); + /*! + ensures + - any call to this->train(x,y) will return a default initialized + dec_funct_type object. + !*/ + + null_trainer_type ( + const dec_funct_type& dec_funct + ); + /*! + ensures + - any call to this->train(x,y) will always return a copy of + the given dec_funct object. + !*/ + + template < + typename in_sample_vector_type, + typename in_scalar_vector_type + > + const dec_funct_type& train ( + const in_sample_vector_type& x, + const in_scalar_vector_type& y + ) const; + /*! + ensures + - returns a copy of the decision function object given to + this object's constructor. + !*/ + + }; + +// ---------------------------------------------------------------------------------------- + + template < + typename dec_funct_type + > + const null_trainer_type null_trainer ( + const dec_funct_type& dec_funct + ) { return null_trainer_type(dec_funct); } + /*! + ensures + - returns a null_trainer_type object that has been instantiated with + the given arguments. That is, this function returns a null_trainer_type + trainer that will return a copy of the given dec_funct object every time + someone calls its train() function. + !*/ + +// ---------------------------------------------------------------------------------------- + +} + +#endif // DLIB_NULL_TRAINERs_ABSTRACT_ + +