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
00039
00040
00041
00042
#include "TemporalHorizonVMatrix.h"
00043
00044
namespace PLearn {
00045
using namespace std;
00046
00049
PLEARN_IMPLEMENT_OBJECT(TemporalHorizonVMatrix,
"ONE LINE DESCR",
00050
" VMat class that delay the last entries of an underlying VMat by a certain horizon.\n");
00051
00052 TemporalHorizonVMatrix::TemporalHorizonVMatrix(
VMat the_distr,
int the_horizon,
int target_size)
00053 :
inherited(the_distr.length()-the_horizon, the_distr->width()),
00054 distr(the_distr), horizon(the_horizon), targetsize(target_size)
00055 {
00056 fieldinfos =
distr->fieldinfos;
00057
row_delay.
resize(
width());
00058
for (
int i=0; i<
width(); i++)
00059
row_delay[i] = i<
width()-
targetsize ? 0 :
horizon;
00060
00061 defineSizes(
distr->inputsize(),
distr->targetsize(),
distr->weightsize());
00062 }
00063
00064 real TemporalHorizonVMatrix::get(
int i,
int j)
const
00065
{
return distr->get(i+
row_delay[j], j); }
00066
00067 void TemporalHorizonVMatrix::put(
int i,
int j,
real value)
00068 {
distr->put(i+
row_delay[j], j, value); }
00069
00070 real TemporalHorizonVMatrix::dot(
int i1,
int i2,
int inputsize)
const
00071
{
00072
real res = 0.;
00073
for(
int k=0;
k<inputsize;
k++)
00074 res +=
distr->get(i1+
row_delay[
k],
k)*
distr->get(i2+
row_delay[
k],
k);
00075
return res;
00076 }
00077
00078 real TemporalHorizonVMatrix::dot(
int i,
const Vec& v)
const
00079
{
00080
real res = 0.;
00081
for(
int k=0;
k<v.
length();
k++)
00082 res +=
distr->get(i+
row_delay[
k],
k)*v[
k];
00083
return res;
00084 }
00085
00086 real TemporalHorizonVMatrix::getStringVal(
int col,
const string & str)
const
00087
{
return distr->getStringVal(col, str); }
00088
00089 string TemporalHorizonVMatrix::getValString(
int col,
real val)
const
00090
{
return distr->getValString(col,
val); }
00091
00092 string TemporalHorizonVMatrix::getString(
int row,
int col)
const
00093
{
return distr->getString(row+
row_delay[col],col); }
00094
00095 const map<string,real>& TemporalHorizonVMatrix::getStringToRealMapping(
int col)
const
00096
{
return distr->getStringToRealMapping(col);}
00097
00098 const map<real,string>& TemporalHorizonVMatrix::getRealToStringMapping(
int col)
const
00099
{
return distr->getRealToStringMapping(col);}
00100
00101 void TemporalHorizonVMatrix::declareOptions(
OptionList &ol)
00102 {
00103
declareOption(ol,
"distr", &TemporalHorizonVMatrix::distr, OptionBase::buildoption,
00104
" The matrix viewed by the TemporalHorizonVMatrix");
00105
declareOption(ol,
"horizon", &TemporalHorizonVMatrix::horizon, OptionBase::buildoption,
00106
" The temporal value by which to delay the VMat");
00107
declareOption(ol,
"targetsize", &TemporalHorizonVMatrix::targetsize, OptionBase::buildoption,
00108
" The number of last entries to delay");
00109 inherited::declareOptions(ol);
00110 }
00111
00112 void TemporalHorizonVMatrix::makeDeepCopyFromShallowCopy(map<const void*, void*>& copies)
00113 {
00114 inherited::makeDeepCopyFromShallowCopy(copies);
00115
deepCopyField(
distr, copies);
00116 }
00117
00119
00121 void TemporalHorizonVMatrix::build()
00122 {
00123 inherited::build();
00124
build_();
00125 }
00126
00128
00130 void TemporalHorizonVMatrix::build_()
00131 {
00132
if (
distr) {
00133 length_ =
distr->
length()-
horizon;
00134 width_ =
distr->
width();
00135 fieldinfos =
distr->fieldinfos;
00136
00137
row_delay.
resize(
width());
00138
for (
int i=0; i<
width(); i++)
00139
row_delay[i] = i<
width()-
targetsize ? 0 :
horizon;
00140
00141 defineSizes(
distr->inputsize(),
distr->targetsize(),
distr->weightsize());
00142 }
00143 }
00144
00145 }