PLearn 0.1
|
Scales (or suppress) the gradient that is backpropagated. More...
#include <ScaleGradientModule.h>
Public Member Functions | |
ScaleGradientModule () | |
Default constructor. | |
virtual void | fprop (const Mat &inputs, Mat &outputs) |
Given a batch of inputs, compute the outputs. | |
virtual void | fprop (const Vec &input, Vec &output) const |
given the input, compute the output (possibly resize it appropriately) SOON TO BE DEPRECATED, USE fprop(const TVec<Mat*>& ports_value) | |
virtual void | bpropUpdate (const Mat &inputs, const Mat &outputs, Mat &input_gradients, const Mat &output_gradients, bool accumulate=false) |
SOON TO BE DEPRECATED, USE bpropAccUpdate(const TVec<Mat*>& ports_value, const TVec<Mat*>& ports_gradient) | |
virtual void | bpropUpdate (const Vec &input, const Vec &output, Vec &input_gradient, const Vec &output_gradient, bool accumulate=false) |
SOON TO BE DEPRECATED, USE bpropAccUpdate(const TVec<Mat*>& ports_value, const TVec<Mat*>& ports_gradient) this version allows to obtain the input gradient as well N.B. | |
virtual void | forget () |
Reset the parameters to the state they would be BEFORE starting training. | |
virtual void | setLearningRate (real the_learning_rate) |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual ScaleGradientModule * | deepCopy (CopiesMap &copies) const |
virtual void | build () |
Post-constructor. | |
virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
Transforms a shallow copy into a deep copy. | |
Static Public Member Functions | |
static string | _classname_ () |
static OptionList & | _getOptionList_ () |
static RemoteMethodMap & | _getRemoteMethodMap_ () |
static Object * | _new_instance_for_typemap_ () |
static bool | _isa_ (const Object *o) |
static void | _static_initialize_ () |
static const PPath & | declaringFile () |
Public Attributes | |
real | scale |
Scaling factor. | |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares the class options. | |
Private Types | |
typedef OnlineLearningModule | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. |
Scales (or suppress) the gradient that is backpropagated.
Definition at line 51 of file ScaleGradientModule.h.
typedef OnlineLearningModule PLearn::ScaleGradientModule::inherited [private] |
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 53 of file ScaleGradientModule.h.
PLearn::ScaleGradientModule::ScaleGradientModule | ( | ) |
string PLearn::ScaleGradientModule::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 51 of file ScaleGradientModule.cc.
OptionList & PLearn::ScaleGradientModule::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 51 of file ScaleGradientModule.cc.
RemoteMethodMap & PLearn::ScaleGradientModule::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 51 of file ScaleGradientModule.cc.
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 51 of file ScaleGradientModule.cc.
Object * PLearn::ScaleGradientModule::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 51 of file ScaleGradientModule.cc.
StaticInitializer ScaleGradientModule::_static_initializer_ & PLearn::ScaleGradientModule::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 51 of file ScaleGradientModule.cc.
void PLearn::ScaleGradientModule::bpropUpdate | ( | const Vec & | input, |
const Vec & | output, | ||
Vec & | input_gradient, | ||
const Vec & | output_gradient, | ||
bool | accumulate = false |
||
) | [virtual] |
SOON TO BE DEPRECATED, USE bpropAccUpdate(const TVec<Mat*>& ports_value, const TVec<Mat*>& ports_gradient) this version allows to obtain the input gradient as well N.B.
THE DEFAULT IMPLEMENTATION JUST RAISES A PLERROR. The flag indicates whether the input_gradients gets accumulated into or set with the computed derivatives.
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 144 of file ScaleGradientModule.cc.
References PLearn::TVec< T >::clear(), PLearn::multiply(), PLearn::multiplyAcc(), PLASSERT_MSG, PLearn::TVec< T >::resize(), scale, and PLearn::TVec< T >::size().
{ if (accumulate) { PLASSERT_MSG( input_gradient.size() == output_gradient.size(), "Cannot accumulate into input_gradient and resize it" ); if (scale == 0) return; else // input_gradient += scale * output_gradients multiplyAcc(input_gradient, output_gradient, scale); } else { input_gradient.resize(output_gradient.size()); if (scale == 0) input_gradient.clear(); else // input_gradient = scale * output_gradients multiply(output_gradient, scale, input_gradient); } }
void PLearn::ScaleGradientModule::bpropUpdate | ( | const Mat & | inputs, |
const Mat & | outputs, | ||
Mat & | input_gradients, | ||
const Mat & | output_gradients, | ||
bool | accumulate = false |
||
) | [virtual] |
SOON TO BE DEPRECATED, USE bpropAccUpdate(const TVec<Mat*>& ports_value, const TVec<Mat*>& ports_gradient)
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 116 of file ScaleGradientModule.cc.
References PLearn::TMat< T >::clear(), PLearn::TMat< T >::length(), PLearn::multiply(), PLearn::multiplyAcc(), PLASSERT_MSG, PLearn::TMat< T >::resize(), scale, and PLearn::TMat< T >::width().
{ if (accumulate) { PLASSERT_MSG( input_gradients.length() == output_gradients.length() && input_gradients.width() == output_gradients.width(), "Cannot accumulate into input_gradients and resize it" ); if (scale == 0) return; else // input_gradients += scale * output_gradients multiplyAcc(input_gradients, output_gradients, scale); } else { input_gradients.resize(output_gradients.length(), output_gradients.width()); if (scale == 0) input_gradients.clear(); else // input_gradients = scale * output_gradients multiply(input_gradients, output_gradients, scale); } }
void PLearn::ScaleGradientModule::build | ( | ) | [virtual] |
Post-constructor.
The normal implementation should call simply inherited::build(), then this class's build_(). This method should be callable again at later times, after modifying some option fields to change the "architecture" of the object.
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 85 of file ScaleGradientModule.cc.
References PLearn::OnlineLearningModule::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::ScaleGradientModule::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 78 of file ScaleGradientModule.cc.
Referenced by build().
{ }
string PLearn::ScaleGradientModule::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 51 of file ScaleGradientModule.cc.
void PLearn::ScaleGradientModule::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares the class options.
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 64 of file ScaleGradientModule.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::OnlineLearningModule::declareOptions(), and scale.
{ declareOption(ol, "scale", &ScaleGradientModule::scale, OptionBase::buildoption, "The scaling factor. If 0, no gradient will be backpropagated." ); // Now call the parent class' declareOptions inherited::declareOptions(ol); }
static const PPath& PLearn::ScaleGradientModule::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 95 of file ScaleGradientModule.h.
:
//##### Protected Member Functions ######################################
ScaleGradientModule * PLearn::ScaleGradientModule::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 51 of file ScaleGradientModule.cc.
void PLearn::ScaleGradientModule::forget | ( | ) | [virtual] |
Reset the parameters to the state they would be BEFORE starting training.
Note that this method is necessarily called from build().
Implements PLearn::OnlineLearningModule.
Definition at line 94 of file ScaleGradientModule.cc.
{ }
given the input, compute the output (possibly resize it appropriately) SOON TO BE DEPRECATED, USE fprop(const TVec<Mat*>& ports_value)
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 107 of file ScaleGradientModule.cc.
References PLearn::TVec< T >::resize(), and PLearn::TVec< T >::size().
{ output.resize(input.size()); output << input; }
Given a batch of inputs, compute the outputs.
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 101 of file ScaleGradientModule.cc.
References PLearn::TMat< T >::length(), PLearn::TMat< T >::resize(), and PLearn::TMat< T >::width().
{ outputs.resize(inputs.length(), inputs.width()); outputs << inputs; }
OptionList & PLearn::ScaleGradientModule::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 51 of file ScaleGradientModule.cc.
OptionMap & PLearn::ScaleGradientModule::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 51 of file ScaleGradientModule.cc.
RemoteMethodMap & PLearn::ScaleGradientModule::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 51 of file ScaleGradientModule.cc.
void PLearn::ScaleGradientModule::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 176 of file ScaleGradientModule.cc.
References PLearn::OnlineLearningModule::makeDeepCopyFromShallowCopy().
{ inherited::makeDeepCopyFromShallowCopy(copies); }
void PLearn::ScaleGradientModule::setLearningRate | ( | real | the_learning_rate | ) | [virtual] |
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 168 of file ScaleGradientModule.cc.
{
// pass;
}
Reimplemented from PLearn::OnlineLearningModule.
Definition at line 95 of file ScaleGradientModule.h.
Scaling factor.
Definition at line 59 of file ScaleGradientModule.h.
Referenced by bpropUpdate(), and declareOptions().