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 "SelectRowsVMatrix.h"
00043
00044
namespace PLearn {
00045
using namespace std;
00046
00049
PLEARN_IMPLEMENT_OBJECT(SelectRowsVMatrix,
00050
"VMat class that selects samples from a source matrix according to given vector of indices.",
00051
""
00052 );
00053
00054 SelectRowsVMatrix::SelectRowsVMatrix()
00055 {
00056 }
00057
00058 SelectRowsVMatrix::SelectRowsVMatrix(
VMat the_source,
TVec<int> the_indices)
00059 : indices(the_indices)
00060 {
00061 source = the_source;
00062
build_();
00063 }
00064
00066 SelectRowsVMatrix::SelectRowsVMatrix(
VMat the_source,
Vec the_indices)
00067 {
00068 source = the_source;
00069
indices.
resize(the_indices.
length());
00070
indices << the_indices;
00071
build_();
00072 }
00073
00074 real SelectRowsVMatrix::get(
int i,
int j)
const
00075
{
return source->get(
indices[i], j); }
00076
00077 void SelectRowsVMatrix::getSubRow(
int i,
int j,
Vec v)
const
00078
{ source->
getSubRow(
indices[i], j, v); }
00079
00080 real SelectRowsVMatrix::dot(
int i1,
int i2,
int inputsize)
const
00081
{
return source->dot(
int(
indices[i1]),
int(
indices[i2]), inputsize); }
00082
00083 real SelectRowsVMatrix::dot(
int i,
const Vec& v)
const
00084
{
return source->dot(
indices[i],v); }
00085
00086 real SelectRowsVMatrix::getStringVal(
int col,
const string & str)
const
00087
{
return source->getStringVal(col, str); }
00088
00089 string SelectRowsVMatrix::getValString(
int col,
real val)
const
00090
{
return source->getValString(col,
val); }
00091
00092 string SelectRowsVMatrix::getString(
int row,
int col)
const
00093
{
return source->getString(
indices[row], col); }
00094
00095 const map<string,real>& SelectRowsVMatrix::getStringToRealMapping(
int col)
const
00096
{
return source->getStringToRealMapping(col);}
00097
00098 const map<real,string>& SelectRowsVMatrix::getRealToStringMapping(
int col)
const
00099
{
return source->getRealToStringMapping(col);}
00100
00101 void SelectRowsVMatrix::declareOptions(
OptionList &ol)
00102 {
00103
declareOption(ol,
"indices", &SelectRowsVMatrix::indices, OptionBase::buildoption,
00104
" The array of row indices to extract");
00105 inherited::declareOptions(ol);
00106 }
00107
00108 void SelectRowsVMatrix::makeDeepCopyFromShallowCopy(map<const void*, void*>& copies)
00109 {
00110 inherited::makeDeepCopyFromShallowCopy(copies);
00111
deepCopyField(
indices, copies);
00112 }
00113
00115
00117 void SelectRowsVMatrix::build()
00118 {
00119 inherited::build();
00120
build_();
00121 }
00122
00124
00126 void SelectRowsVMatrix::build_()
00127 {
00128 length_ =
indices.
length();
00129
if (source) {
00130 width_ = source->
width();
00131 inputsize_ = source->inputsize();
00132 targetsize_ = source->targetsize();
00133 weightsize_ = source->weightsize();
00134 fieldinfos = source->fieldinfos;
00135 }
00136 }
00137
00138 }