mirror of
https://github.com/davisking/dlib.git
synced 2024-11-01 10:14:53 +08:00
Added the null_trainer_type object.
--HG-- extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403037
This commit is contained in:
parent
0ce66e9a92
commit
b21dd37edf
@ -15,6 +15,7 @@
|
|||||||
#include "svm/rvm.h"
|
#include "svm/rvm.h"
|
||||||
#include "svm/pegasos.h"
|
#include "svm/pegasos.h"
|
||||||
#include "svm/sparse_kernel.h"
|
#include "svm/sparse_kernel.h"
|
||||||
|
#include "svm/null_trainer.h"
|
||||||
|
|
||||||
#endif // DLIB_SVm_HEADER
|
#endif // DLIB_SVm_HEADER
|
||||||
|
|
||||||
|
61
dlib/svm/null_trainer.h
Normal file
61
dlib/svm/null_trainer.h
Normal file
@ -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<dec_funct_type> null_trainer (
|
||||||
|
const dec_funct_type& dec_funct
|
||||||
|
) { return null_trainer_type<dec_funct_type>(dec_funct); }
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // DLIB_NULL_TRAINERs_H_
|
||||||
|
|
97
dlib/svm/null_trainer_abstract.h
Normal file
97
dlib/svm/null_trainer_abstract.h
Normal file
@ -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<dec_funct_type> null_trainer (
|
||||||
|
const dec_funct_type& dec_funct
|
||||||
|
) { return null_trainer_type<dec_funct_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_
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user