00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
#ifndef SEQUENTIAL_LEARNER
00039
#define SEQUENTIAL_LEARNER
00040
00041
#include <plearn_learners/generic/PLearner.h>
00042
00043
namespace PLearn {
00044
using namespace std;
00045
00057 class SequentialLearner:
public PLearner
00058 {
00059
public:
00060 typedef PLearner inherited;
00061
00062
protected:
00063 int last_train_t;
00064 int last_call_train_t;
00065 mutable int last_test_t;
00066
00067
public:
00068 int get_last_train_t(){
return last_train_t; }
00069 int get_last_call_train_t(){
return last_call_train_t; }
00070 int get_last_test_t(){
return last_test_t; }
00071
00072
public:
00073
00078 int init_train_size;
00079 int max_seq_len;
00080 int max_train_len;
00081 int train_step;
00082 int horizon;
00083 int outputsize_;
00084
00087 Mat predictions;
00088
00089 Mat errors;
00090
00091
private:
00093
void build_();
00094
00095
protected:
00097
static void declareOptions(
OptionList& ol);
00098
00099
public:
00100
00102
SequentialLearner();
00103
00105
virtual void build();
00106
00108
virtual int outputsize() const;
00109
00110 virtual
int nTestCosts() const;
00111
00112 virtual
void setTrainingSet(
VMat training_set,
bool call_forget=true);
00113
00123 virtual
void train() =0;
00124
00131 virtual
void test(
VMat testset,
PP<
VecStatsCollector> test_stats,
00132
VMat testoutputs=0,
VMat testcosts=0) const =0;
00133
00134 virtual
void computeOutputAndCosts(const
Vec& input, const
Vec& target,
00135
Vec& output,
Vec& costs) const;
00136
00137 virtual
void computeCostsOnly(const
Vec& input, const
Vec& target,
00138
Vec& costs) const;
00139
00140 virtual
void computeOutput(const
Vec& input,
Vec& output) const;
00141
00142 virtual
void computeCostsFromOutputs(const
Vec& input, const
Vec& output,
00143 const
Vec& target,
Vec& costs) const;
00144
00151 int sequenceStart()
const {
return init_train_size; }
00152 int sequenceLength()
const {
return last_test_t -
init_train_size + 1; }
00153 Vec getCostSequence(
int cost_index)
const
00154
{
return errors.
subMat(
sequenceStart(), cost_index,
sequenceLength(), 1).toVecCopy(); }
00155 Vec getCostSequence(
string cname)
const
00156
{
return getCostSequence(getTestCostIndex(cname)); }
00157
00163
virtual void matlabSave(
const string& matlab_subdir);
00164
00165
virtual void forget();
00166
00169
PLEARN_DECLARE_ABSTRACT_OBJECT(
SequentialLearner);
00170
virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies);
00171 };
00172
00174
DECLARE_OBJECT_PTR(SequentialLearner);
00175
00176 }
00177
00178
#endif