PLearn 0.1
IdentityModule.cc
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // IdentityModule.cc
00004 //
00005 // Copyright (C) 2007 Olivier Delalleau
00006 //
00007 // Redistribution and use in source and binary forms, with or without
00008 // modification, are permitted provided that the following conditions are met:
00009 //
00010 //  1. Redistributions of source code must retain the above copyright
00011 //     notice, this list of conditions and the following disclaimer.
00012 //
00013 //  2. Redistributions in binary form must reproduce the above copyright
00014 //     notice, this list of conditions and the following disclaimer in the
00015 //     documentation and/or other materials provided with the distribution.
00016 //
00017 //  3. The name of the authors may not be used to endorse or promote
00018 //     products derived from this software without specific prior written
00019 //     permission.
00020 //
00021 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
00022 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00023 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
00024 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00025 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
00026 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00027 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00028 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00029 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00030 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031 //
00032 // This file is part of the PLearn library. For more information on the PLearn
00033 // library, go to the PLearn Web site at www.plearn.org
00034 
00035 // Authors: Olivier Delalleau
00036 
00041 #include "IdentityModule.h"
00042 
00043 namespace PLearn {
00044 using namespace std;
00045 
00046 PLEARN_IMPLEMENT_OBJECT(
00047     IdentityModule,
00048     "Module that simply replicates its input.",
00049     ""
00050 );
00051 
00052 IdentityModule::IdentityModule()
00053 {}
00054 
00056 // declareOptions //
00058 void IdentityModule::declareOptions(OptionList& ol)
00059 {
00060     // ### Declare all of this object's options here.
00061     // ### For the "flags" of each option, you should typically specify
00062     // ### one of OptionBase::buildoption, OptionBase::learntoption or
00063     // ### OptionBase::tuningoption. If you don't provide one of these three,
00064     // ### this option will be ignored when loading values from a script.
00065     // ### You can also combine flags, for example with OptionBase::nosave:
00066     // ### (OptionBase::buildoption | OptionBase::nosave)
00067 
00068     // Now call the parent class' declareOptions
00069     inherited::declareOptions(ol);
00070 }
00071 
00073 // build_ //
00075 void IdentityModule::build_()
00076 {
00077     // ### This method should do the real building of the object,
00078     // ### according to set 'options', in *any* situation.
00079     // ### Typical situations include:
00080     // ###  - Initial building of an object from a few user-specified options
00081     // ###  - Building of a "reloaded" object: i.e. from the complete set of
00082     // ###    all serialised options.
00083     // ###  - Updating or "re-building" of an object after a few "tuning"
00084     // ###    options have been modified.
00085     // ### You should assume that the parent class' build_() has already been
00086     // ### called.
00087 }
00088 
00089 // ### Nothing to add here, simply calls build_
00090 void IdentityModule::build()
00091 {
00092     inherited::build();
00093     build_();
00094 }
00095 
00096 
00098 // makeDeepCopyFromShallowCopy //
00100 void IdentityModule::makeDeepCopyFromShallowCopy(CopiesMap& copies)
00101 {
00102     inherited::makeDeepCopyFromShallowCopy(copies);
00103 }
00104 
00106 // fprop //
00108 void IdentityModule::fprop(const Vec& input, Vec& output) const
00109 {
00110     output.resize(input.length());
00111     output << input;
00112 }
00113 
00114 void IdentityModule::fprop(const Mat& inputs, Mat& outputs) {
00115     outputs.resize(inputs.length(), inputs.width());
00116     outputs << inputs;
00117 }
00118 
00120 // bpropAccUpdate //
00122 void IdentityModule::bpropAccUpdate(const TVec<Mat*>& ports_value,
00123                                     const TVec<Mat*>& ports_gradient)
00124 {
00125     // Deal with 'standard case' only.
00126     PLASSERT( ports_gradient.length() == 2 );
00127     Mat* input_grad = ports_gradient[0];
00128     Mat* output_grad = ports_gradient[1];
00129     if (!input_grad)
00130         return;
00131     PLASSERT( output_grad && !output_grad->isEmpty() &&
00132               input_grad->isEmpty() );
00133     PLASSERT( input_grad->width() == output_grad->width() );
00134     input_grad->resize(output_grad->length(), input_grad->width());
00135     *input_grad += *output_grad;
00136 }
00137 
00139 // bpropUpdate //
00141 /* THIS METHOD IS OPTIONAL
00142 void IdentityModule::bpropUpdate(const Vec& input, const Vec& output,
00143                                Vec& input_gradient,
00144                                const Vec& output_gradient,
00145                                bool accumulate)
00146 {
00147 }
00148 */
00149 
00150 /* THIS METHOD IS OPTIONAL
00151 void IdentityModule::bpropUpdate(const Vec& input, const Vec& output,
00152                                const Vec& output_gradient)
00153 {
00154 }
00155 */
00156 
00158 // bbpropUpdate //
00160 /* THIS METHOD IS OPTIONAL
00161 void IdentityModule::bbpropUpdate(const Vec& input, const Vec& output,
00162                                 Vec& input_gradient,
00163                                 const Vec& output_gradient,
00164                                 Vec& input_diag_hessian,
00165                                 const Vec& output_diag_hessian,
00166                                 bool accumulate)
00167 {
00168 }
00169 */
00170 
00171 /* THIS METHOD IS OPTIONAL
00172 void IdentityModule::bbpropUpdate(const Vec& input, const Vec& output,
00173                                 const Vec& output_gradient,
00174                                 const Vec& output_diag_hessian)
00175 {
00176 }
00177 */
00178 
00180 // forget //
00182 void IdentityModule::forget()
00183 {
00184     // Nothing to forget.
00185 }
00186 
00188 // finalize //
00190 /* THIS METHOD IS OPTIONAL
00191 void IdentityModule::finalize()
00192 {
00193 }
00194 */
00195 
00197 // bpropDoesNothing //
00199 /* THIS METHOD IS OPTIONAL
00200 bool IdentityModule::bpropDoesNothing()
00201 {
00202 }
00203 */
00204 
00206 // setLearningRate //
00208 /* OPTIONAL
00209 void IdentityModule::setLearningRate(real dynamic_learning_rate)
00210 {
00211 }
00212 */
00213 
00214 } // end of namespace PLearn
00215 
00216 
00217 /*
00218   Local Variables:
00219   mode:c++
00220   c-basic-offset:4
00221   c-file-style:"stroustrup"
00222   c-file-offsets:((innamespace . 0)(inline-open . 0))
00223   indent-tabs-mode:nil
00224   fill-column:79
00225   End:
00226 */
00227 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines