PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // RealFunctionsProcessedVMatrix.cc 00004 // 00005 // Copyright (C) 2006 Xavier Saint-Mleux 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 // Author: Xavier Saint-Mleux 00036 00040 #include "RealFunctionsProcessedVMatrix.h" 00041 00042 namespace PLearn { 00043 using namespace std; 00044 00045 00046 RealFunctionsProcessedVMatrix::RealFunctionsProcessedVMatrix(VMat source_, 00047 const TVec<RealFunc>& functions_, 00048 bool put_raw_input_, 00049 bool put_non_input_, 00050 bool call_build_) 00051 :inherited(source_, call_build_), 00052 functions(functions_), 00053 put_raw_input(put_raw_input_), 00054 put_non_input(put_non_input_) 00055 { 00056 if( call_build_ ) 00057 build_(); 00058 } 00059 00060 00061 PLEARN_IMPLEMENT_OBJECT(RealFunctionsProcessedVMatrix, 00062 "",""); 00064 // declareOptions // 00066 void RealFunctionsProcessedVMatrix::declareOptions(OptionList& ol) 00067 { 00068 // ### Declare all of this object's options here 00069 // ### For the "flags" of each option, you should typically specify 00070 // ### one of OptionBase::buildoption, OptionBase::learntoption or 00071 // ### OptionBase::tuningoption. Another possible flag to be combined with 00072 // ### is OptionBase::nosave 00073 00074 declareOption(ol, "functions", 00075 &RealFunctionsProcessedVMatrix::functions, 00076 OptionBase::buildoption, 00077 "The functions used to process the inputs from the source VMat."); 00078 00079 declareOption(ol, "put_raw_input", &RealFunctionsProcessedVMatrix::put_raw_input, 00080 OptionBase::buildoption, 00081 "Whether to include in the input part of this VMatrix the" 00082 " raw input part\n" 00083 "of 'source'.\n"); 00084 00085 declareOption(ol, "put_non_input", &RealFunctionsProcessedVMatrix::put_non_input, 00086 OptionBase::buildoption, 00087 "Whether to include in this VMatrix the original target and" 00088 " weights."); 00089 00090 // Now call the parent class' declareOptions 00091 inherited::declareOptions(ol); 00092 } 00093 00095 // build_ // 00097 void RealFunctionsProcessedVMatrix::build_() 00098 { 00099 if(source) 00100 { 00101 updateMtime(source); 00102 length_= source->length(); 00103 if(functions) 00104 { 00105 width_= functions->length(); 00106 if(put_raw_input) 00107 width_+= source->inputsize(); 00108 if(put_non_input) 00109 width_+= source->targetsize() + source->weightsize(); 00110 } 00111 } 00112 } 00113 00115 // build // 00117 void RealFunctionsProcessedVMatrix::build() 00118 { 00119 inherited::build(); 00120 build_(); 00121 } 00122 00123 void RealFunctionsProcessedVMatrix::makeDeepCopyFromShallowCopy(CopiesMap& copies) 00124 { 00125 inherited::makeDeepCopyFromShallowCopy(copies); 00126 deepCopyField(input, copies); 00127 deepCopyField(targ, copies); 00128 deepCopyField(functions, copies); 00129 } 00130 00131 00132 00133 00134 00135 void RealFunctionsProcessedVMatrix::getNewRow(int i, const Vec& v) const 00136 { 00137 source->getExample(i, input, targ, weight); 00138 Vec v2; 00139 evaluate_functions(functions, input, v2); 00140 int l0= 0, l1= v2.length(); 00141 v.subVec(l0, l1) << v2; 00142 l0+= l1; 00143 if(put_raw_input) 00144 { 00145 l1= input.length(); 00146 v.subVec(l0, l1) << input; 00147 l0+= l1; 00148 } 00149 if(put_non_input) 00150 { 00151 l1= targ.length(); 00152 v.subVec(l0, l1) << targ; 00153 if(0 < weightsize_) 00154 v[l0+l1]= weight; 00155 } 00156 } 00157 00158 00159 00160 } // end of namespace PLearn 00161 00162 00163 /* 00164 Local Variables: 00165 mode:c++ 00166 c-basic-offset:4 00167 c-file-style:"stroustrup" 00168 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00169 indent-tabs-mode:nil 00170 fill-column:79 00171 End: 00172 */ 00173 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :