PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // ExtractNNetParamsVMatrix.cc 00004 // 00005 // Copyright (C) 2005 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 /* ******************************************************* 00036 * $Id: ExtractNNetParamsVMatrix.cc 5557 2006-05-10 20:36:58Z lamblin $ 00037 ******************************************************* */ 00038 00039 // Authors: Olivier Delalleau 00040 00044 #include "ExtractNNetParamsVMatrix.h" 00045 00046 namespace PLearn { 00047 using namespace std; 00048 00049 00051 // ExtractNNetParamsVMatrix // 00053 ExtractNNetParamsVMatrix::ExtractNNetParamsVMatrix() 00054 : extract_w1(false), 00055 extract_w2(false), 00056 extract_wdirect(false), 00057 extract_wout(false) 00058 {} 00059 00060 PLEARN_IMPLEMENT_OBJECT(ExtractNNetParamsVMatrix, 00061 "Extract the (learned) parameters of a Neural Network.", 00062 "Currently, it can only extract ONE set of parameters, among w1, w2, wdirect\n" 00063 "and wout. In the future, it may be possible to extract simultaneously all\n" 00064 "those parameters." 00065 ); 00066 00068 // getNewRow // 00070 void ExtractNNetParamsVMatrix::getNewRow(int i, const Vec& v) const 00071 { 00072 v << data(i); 00073 } 00074 00076 // declareOptions // 00078 void ExtractNNetParamsVMatrix::declareOptions(OptionList& ol) 00079 { 00080 // ### Declare all of this object's options here 00081 // ### For the "flags" of each option, you should typically specify 00082 // ### one of OptionBase::buildoption, OptionBase::learntoption or 00083 // ### OptionBase::tuningoption. Another possible flag to be combined with 00084 // ### is OptionBase::nosave 00085 00086 declareOption(ol, "nnet", &ExtractNNetParamsVMatrix::nnet, OptionBase::buildoption, 00087 "The neural network whose parameters are extracted."); 00088 00089 declareOption(ol, "extract_w1", &ExtractNNetParamsVMatrix::extract_w1, OptionBase::buildoption, 00090 "Whether to extract w1."); 00091 00092 declareOption(ol, "extract_w2", &ExtractNNetParamsVMatrix::extract_w2, OptionBase::buildoption, 00093 "Whether to extract w2."); 00094 00095 declareOption(ol, "extract_wdirect", &ExtractNNetParamsVMatrix::extract_wdirect, OptionBase::buildoption, 00096 "Whether to extract wdirect."); 00097 00098 declareOption(ol, "extract_wout", &ExtractNNetParamsVMatrix::extract_wout, OptionBase::buildoption, 00099 "Whether to extract wout."); 00100 00101 // Now call the parent class' declareOptions 00102 inherited::declareOptions(ol); 00103 00104 redeclareOption(ol, "length", &ExtractNNetParamsVMatrix::length_, OptionBase::nosave, 00105 "Overwritten at build time."); 00106 00107 redeclareOption(ol, "width", &ExtractNNetParamsVMatrix::width_, OptionBase::nosave, 00108 "Overwritten at build time."); 00109 00110 } 00111 00113 // build_ // 00115 void ExtractNNetParamsVMatrix::build() 00116 { 00117 inherited::build(); 00118 build_(); 00119 } 00120 00122 // build_ // 00124 void ExtractNNetParamsVMatrix::build_() 00125 { 00126 if (nnet) { 00127 Mat m; 00128 if (extract_w1) 00129 m = nnet->getW1(); 00130 else if (extract_w2) 00131 m = nnet->getW2(); 00132 else if (extract_wdirect) 00133 m = nnet->getWdirect(); 00134 else if (extract_wout) 00135 m = nnet->getWout(); 00136 data.resize(m.length(), m.width()); 00137 data << m; 00138 length_ = data.length(); 00139 width_ = data.width(); 00140 } 00141 } 00142 00144 // makeDeepCopyFromShallowCopy // 00146 void ExtractNNetParamsVMatrix::makeDeepCopyFromShallowCopy(CopiesMap& copies) 00147 { 00148 inherited::makeDeepCopyFromShallowCopy(copies); 00149 // deepCopyField(trainvec, copies); 00150 PLERROR("ExtractNNetParamsVMatrix::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!"); 00151 } 00152 00153 } // end of namespace PLearn 00154 00155 00156 /* 00157 Local Variables: 00158 mode:c++ 00159 c-basic-offset:4 00160 c-file-style:"stroustrup" 00161 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00162 indent-tabs-mode:nil 00163 fill-column:79 00164 End: 00165 */ 00166 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :