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
#include "SubsampleVariable.h"
00044
00045
namespace PLearn {
00046
using namespace std;
00047
00048
00051
PLEARN_IMPLEMENT_OBJECT(SubsampleVariable,
00052
"A subsample var; equals subsample(input, the_subsamplefactor)",
00053
"NO HELP");
00054
00055 SubsampleVariable::SubsampleVariable(
Variable* input,
int the_subsamplefactor)
00056 :
inherited(input, input->length()/the_subsamplefactor, input->width()/the_subsamplefactor),
00057 subsamplefactor(the_subsamplefactor)
00058 {
00059
build_();
00060 }
00061
00062
void
00063 SubsampleVariable::build()
00064 {
00065 inherited::build();
00066
build_();
00067 }
00068
00069
void
00070 SubsampleVariable::build_()
00071 {
00072
if (input) {
00073
if (input->
length() %
subsamplefactor != 0 || input->
width() %
subsamplefactor != 0)
00074
PLERROR(
"In SubsampleVariable constructor: Dimensions of input are not dividable by subsamplefactor");
00075 }
00076 }
00077
00078
void
00079 SubsampleVariable::declareOptions(
OptionList &ol)
00080 {
00081
declareOption(ol,
"subsamplefactor", &SubsampleVariable::subsamplefactor, OptionBase::buildoption,
"");
00082 inherited::declareOptions(ol);
00083 }
00084
00085 void SubsampleVariable::recomputeSize(
int& l,
int& w)
const
00086
{
00087
if (input) {
00088 l = input->
length() /
subsamplefactor;
00089 w = input->
width()/
subsamplefactor;
00090 }
else
00091 l = w = 0;
00092 }
00093
00094 void SubsampleVariable::fprop()
00095 {
00096
subsample(input->matValue,
subsamplefactor, matValue);
00097 }
00098
00099
00100 void SubsampleVariable::bprop()
00101 {
00102
int norm =
subsamplefactor *
subsamplefactor;
00103
for(
int i=0; i<
length(); i++)
00104
for(
int j=0; j<
width(); j++)
00105 {
00106
real* inputgradientptr = input->matGradient[subsamplefactor*i]+subsamplefactor*j;
00107
real thisgradient = matGradient(i,j);
00108
for(
int l=0; l<subsamplefactor; l++, inputgradientptr += input->matGradient.mod())
00109
for(
int c=0; c<subsamplefactor; c++)
00110 {
00111 inputgradientptr[c] = thisgradient/
norm;
00112 }
00113 }
00114 }
00115
00116
00117 void SubsampleVariable::symbolicBprop()
00118 {
PLERROR(
"SubsampleVariable::symbolicBprop() not yet implemented"); }
00119
00120
00121
00122 }
00123
00124