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
00043
#include "SubInputVMatrix.h"
00044
00045
namespace PLearn {
00046
using namespace std;
00047
00049
00051 SubInputVMatrix::SubInputVMatrix()
00052 :
inherited(),
00053 j_start(0),
00054 n_inputs(-1)
00055 {
00056 }
00057
00058
PLEARN_IMPLEMENT_OBJECT(
SubInputVMatrix,
00059
"A VMat that only takes part of the input of its source VMat.",
00060
"This can be useful for instance to only take the first k components\n"
00061
"after applying some dimensionality reduction method."
00062 );
00063
00065
00067 void SubInputVMatrix::declareOptions(
OptionList& ol)
00068 {
00069
declareOption(ol,
"j_start", &SubInputVMatrix::j_start, OptionBase::buildoption,
00070
"The column we start at.");
00071
00072
declareOption(ol,
"n_inputs", &SubInputVMatrix::n_inputs, OptionBase::buildoption,
00073
"The number of inputs to keep (-1 means we keep them all, from j_start).");
00074
00075
00076 inherited::declareOptions(ol);
00077 }
00078
00080
00082 void SubInputVMatrix::build()
00083 {
00084 inherited::build();
00085
build_();
00086 }
00087
00089
00091 void SubInputVMatrix::build_()
00092 {
00093
if (source) {
00094
if (
n_inputs == -1) {
00095
00096
n_inputs = source->inputsize() -
j_start;
00097 }
00098
if (n_inputs < 0 || n_inputs + j_start > source->inputsize()) {
00099
PLERROR(
"In SubInputVMatrix::build_ - Source VMatrix hasn't enough inputs");
00100 }
00101
int n_removed = source->inputsize() -
n_inputs;
00102 inputsize_ =
n_inputs;
00103 width_ = source->
width() - n_removed;
00104
setMetaInfoFromSource();
00105
00106 }
00107 }
00108
00110
00112 void SubInputVMatrix::getNewRow(
int i,
const Vec& v)
const
00113
{
00114
00115 source->
getSubRow(i,
j_start, v.
subVec(0,
n_inputs));
00116
00117 source->
getSubRow(
00118 i,
00119 source->inputsize(),
00120 v.
subVec(
n_inputs, v.
length() -
n_inputs));
00121 }
00122
00124
00126 void SubInputVMatrix::makeDeepCopyFromShallowCopy(map<const void*, void*>& copies)
00127 {
00128 inherited::makeDeepCopyFromShallowCopy(copies);
00129 }
00130
00131 }
00132