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
00043
00046
#include "ForwardVMatrix.h"
00047
#include <plearn/ker/Kernel.h>
00048
#include <plearn/var/Func.h>
00049
00050
namespace PLearn {
00051
using namespace std;
00052
00053
PLEARN_IMPLEMENT_OBJECT(ForwardVMatrix,
"ONE LINE DESCR",
"NO HELP");
00054
00055 ForwardVMatrix::ForwardVMatrix()
00056 {}
00057
00058 ForwardVMatrix::ForwardVMatrix(
VMat the_vm)
00059 : vm(the_vm)
00060 {
00061 }
00062
00063
void
00064 ForwardVMatrix::build()
00065 {
00066 inherited::build();
00067
build_();
00068 }
00069
00070
void
00071 ForwardVMatrix::build_()
00072 {
00073
if (
vm) {
00074 length_ =
vm->
length();
00075 width_ =
vm->
width();
00076 writable =
vm->isWritable();
00077
if(inputsize_ < 0)
00078 inputsize_ =
vm->inputsize();
00079
if(targetsize_ < 0)
00080 targetsize_ =
vm->targetsize();
00081
if(weightsize_ < 0)
00082 weightsize_ =
vm->weightsize();
00083 setMtime(
vm->getMtime());
00084
if(
vm->hasMetaDataDir())
00085 setMetaDataDir(
vm->getMetaDataDir());
00086 setAlias(
vm->getAlias());
00087
00088
00089
00090
if(!
hasFieldInfos() && (
width() ==
vm->
width()) &&
vm->hasFieldInfos() )
00091 setFieldInfos(
vm->getFieldInfos());
00092 }
else {
00093 length_ = 0;
00094 width_ = 0;
00095 }
00096 }
00097
00098 void ForwardVMatrix::setVMat(
VMat the_vm)
00099 {
00100
if(the_vm)
00101
vm = the_vm;
00102
else
00103
vm =
VMat();
00104
build_();
00105 }
00106
00107
void
00108 ForwardVMatrix::declareOptions(
OptionList &ol)
00109 {
00110
declareOption(ol,
"vm", &ForwardVMatrix::vm, OptionBase::buildoption,
"");
00111 inherited::declareOptions(ol);
00112 }
00113
00114 string ForwardVMatrix::getValString(
int col,
real val)
const
00115
{
return vm->getValString(col,
val); }
00116
00117
00118 real ForwardVMatrix::getStringVal(
int col,
const string& str)
const
00119
{
return vm->getStringVal(col, str); }
00120
00121
00122 string ForwardVMatrix::getString(
int row,
int col)
const
00123
{
return vm->getString(row,col); }
00124
00125 map<string,real> ForwardVMatrix::getStringMapping(
int col)
const
00126
{
00127
PLERROR(
"ForwardVMatrix::getStringMapping not implemented yet");
00128
00129
return map<string,real>();
00130
00131
00132 }
00133
00135
00137 const map<string,real>& ForwardVMatrix::getStringToRealMapping(
int col)
const {
00138
return vm->getStringToRealMapping(col);
00139 }
00140
00142
00144 const map<real,string>& ForwardVMatrix::getRealToStringMapping(
int col)
const {
00145
return vm->getRealToStringMapping(col);
00146 }
00147
00148 void ForwardVMatrix::computeStats()
00149 {
vm->computeStats(); }
00150
00151
00152 void ForwardVMatrix::save(
const string& filename)
const
00153
{
vm->
save(filename); }
00154
00155 void ForwardVMatrix::savePMAT(
const string& pmatfile)
const
00156
{
vm->savePMAT(pmatfile); }
00157 void ForwardVMatrix::saveDMAT(
const string& dmatdir)
const
00158
{
vm->saveDMAT(dmatdir); }
00159 void ForwardVMatrix::saveAMAT(
const string& amatfile)
const
00160
{
vm->saveAMAT(amatfile); }
00161
00162
00163 real ForwardVMatrix::get(
int i,
int j)
const
00164
{
return vm->get(i, j); }
00165
00166
00167 void ForwardVMatrix::put(
int i,
int j,
real value)
00168 {
vm->put(i, j, value); }
00169
00170 void ForwardVMatrix::getSubRow(
int i,
int j,
Vec v)
const
00171
{
vm->
getSubRow(i, j, v); }
00172
00173 void ForwardVMatrix::putSubRow(
int i,
int j,
Vec v)
00174 {
vm->putSubRow(i, j, v); }
00175
00176 void ForwardVMatrix::appendRow(
Vec v)
00177 {
vm->appendRow(v); }
00178
00179 void ForwardVMatrix::getRow(
int i,
Vec v)
const
00180
{
vm->getRow(i, v); }
00181 void ForwardVMatrix::putRow(
int i,
Vec v)
00182 {
vm->putRow(i, v); }
00183 void ForwardVMatrix::fill(
real value)
00184 {
vm->fill(value); }
00185 void ForwardVMatrix::getMat(
int i,
int j,
Mat m)
const
00186
{
vm->getMat(i, j, m); }
00187 void ForwardVMatrix::putMat(
int i,
int j,
Mat m)
00188 {
vm->putMat(i, j, m); }
00189
00190
00191 void ForwardVMatrix::getColumn(
int i,
Vec v)
const
00192
{
vm->
getColumn(i, v); }
00193
00194 Mat ForwardVMatrix::toMat()
const
00195
{
return vm->
toMat(); }
00196
00197
00198
00199 void ForwardVMatrix::compacify()
00200 {
vm->compacify(); }
00201
00202
00203 void ForwardVMatrix::reset_dimensions()
00204 {
00205
if (
vm) {
00206
vm->reset_dimensions();
00207 length_ =
vm->
length();
00208 width_ =
vm->
width();
00209 inputsize_ =
vm->inputsize();
00210 targetsize_ =
vm->targetsize();
00211 weightsize_ =
vm->weightsize();
00212 }
00213 }
00214
00215 VMat ForwardVMatrix::subMat(
int i,
int j,
int l,
int w)
00216 {
return vm->
subMat(i,j,l,w); }
00217
00218 real ForwardVMatrix::dot(
int i1,
int i2,
int inputsize)
const
00219
{
return vm->dot(i1, i2, inputsize); }
00220
00221
00222 real ForwardVMatrix::dot(
int i,
const Vec& v)
const
00223
{
return vm->dot(i, v); }
00224
00225
00226
00227 void ForwardVMatrix::getRow(
int i,
VarArray& inputs)
const
00228
{
vm->getRow(i, inputs); }
00229
00230 void ForwardVMatrix::oldwrite(ostream& out)
const
00231
{
vm->oldwrite(out); }
00232 void ForwardVMatrix::oldread(istream& in)
00233 {
vm->oldread(in); }
00234
00235 void ForwardVMatrix::evaluateKernel(
Ker ker,
int v1_startcol,
int v1_ncols,
00236
const Vec& v2,
const Vec& result,
int startrow,
int nrows)
const
00237
{
vm->evaluateKernel(ker, v1_startcol, v1_ncols,
00238 v2, result, startrow, nrows); }
00239
00240
00241 real ForwardVMatrix::evaluateKernelSum(
Ker ker,
int v1_startcol,
int v1_ncols,
00242
const Vec& v2,
int startrow,
int nrows,
int ignore_this_row)
const
00243
{
return vm->evaluateKernelSum(ker, v1_startcol, v1_ncols,
00244 v2, startrow, nrows, ignore_this_row); }
00245
00246
00247
00248 real ForwardVMatrix::evaluateKernelWeightedTargetSum(
Ker ker,
int v1_startcol,
int v1_ncols,
const Vec& v2,
00249
int t_startcol,
int t_ncols,
Vec& targetsum,
int startrow,
int nrows,
int ignore_this_row)
const
00250
{
return vm->evaluateKernelWeightedTargetSum(ker, v1_startcol, v1_ncols, v2,
00251 t_startcol, t_ncols, targetsum, startrow, nrows, ignore_this_row); }
00252
00253
00258 TVec< pair<real,int> > ForwardVMatrix::evaluateKernelTopN(
int N,
Ker ker,
int v1_startcol,
int v1_ncols,
00259
const Vec& v2,
int startrow,
int nrows,
int ignore_this_row)
const
00260
{
return vm->evaluateKernelTopN(N, ker, v1_startcol, v1_ncols,
00261 v2, startrow, nrows, ignore_this_row); }
00262
00263
00264
00265 TVec< pair<real,int> > ForwardVMatrix::evaluateKernelBottomN(
int N,
Ker ker,
int v1_startcol,
int v1_ncols,
00266
const Vec& v2,
int startrow,
int nrows,
int ignore_this_row)
const
00267
{
return vm->evaluateKernelBottomN(N, ker, v1_startcol, v1_ncols,
00268 v2, startrow, nrows, ignore_this_row); }
00269 void ForwardVMatrix::accumulateXtY(
int X_startcol,
int X_ncols,
int Y_startcol,
int Y_ncols,
00270
Mat& result,
int startrow,
int nrows,
int ignore_this_row)
const
00271
{
vm->accumulateXtY(X_startcol, X_ncols, Y_startcol, Y_ncols,
00272 result, startrow, nrows, ignore_this_row); }
00273
00274 void ForwardVMatrix::accumulateXtX(
int X_startcol,
int X_ncols,
00275
Mat& result,
int startrow,
int nrows,
int ignore_this_row)
const
00276
{
vm->accumulateXtX(X_startcol, X_ncols,
00277 result, startrow, nrows, ignore_this_row); }
00278
00279
00280 void ForwardVMatrix::evaluateSumOfFprop(
Func f,
Vec& output_result,
int nsamples)
00281 {
vm->evaluateSumOfFprop(f, output_result, nsamples); }
00282
00283 void ForwardVMatrix::evaluateSumOfFbprop(
Func f,
Vec& output_result,
Vec& output_gradient,
int nsamples)
00284 {
vm->evaluateSumOfFbprop(f, output_result, output_gradient, nsamples); }
00285
00286 void ForwardVMatrix::makeDeepCopyFromShallowCopy(map<const void*, void*>& copies)
00287 {
00288 inherited::makeDeepCopyFromShallowCopy(copies);
00289
deepCopyField(
vm, copies);
00290 }
00291
00292 }
00293
00294