Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

SubVMatrix.cc

Go to the documentation of this file.
00001 // -*- C++ -*- 00002 00003 // PLearn (A C++ Machine Learning Library) 00004 // Copyright (C) 1998 Pascal Vincent 00005 // Copyright (C) 1999-2001 Pascal Vincent, Yoshua Bengio, Rejean Ducharme and University of Montreal 00006 // Copyright (C) 2002 Pascal Vincent, Julien Keable, Xavier Saint-Mleux 00007 // 00008 // Redistribution and use in source and binary forms, with or without 00009 // modification, are permitted provided that the following conditions are met: 00010 // 00011 // 1. Redistributions of source code must retain the above copyright 00012 // notice, this list of conditions and the following disclaimer. 00013 // 00014 // 2. Redistributions in binary form must reproduce the above copyright 00015 // notice, this list of conditions and the following disclaimer in the 00016 // documentation and/or other materials provided with the distribution. 00017 // 00018 // 3. The name of the authors may not be used to endorse or promote 00019 // products derived from this software without specific prior written 00020 // permission. 00021 // 00022 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00023 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00024 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00025 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00026 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00027 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00028 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00029 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00030 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00031 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 // 00033 // This file is part of the PLearn library. For more information on the PLearn 00034 // library, go to the PLearn Web site at www.plearn.org 00035 00036 00037 /* ******************************************************* 00038 * $Id: SubVMatrix.cc,v 1.14 2004/07/26 20:10:43 tihocan Exp $ 00039 ******************************************************* */ 00040 00041 #include "SubVMatrix.h" 00042 00043 namespace PLearn { 00044 using namespace std; 00045 00046 00049 PLEARN_IMPLEMENT_OBJECT(SubVMatrix, "ONE LINE DESCR", "NO HELP"); 00050 00052 // SubVMatrix // 00054 SubVMatrix::SubVMatrix() 00055 :istart(0), 00056 jstart(0), 00057 fistart(-1), 00058 flength(-1) 00059 {} 00060 00061 SubVMatrix::SubVMatrix(VMat the_parent, int the_istart, int the_jstart, int the_length, int the_width) 00062 :VMatrix(the_length, the_width), parent(the_parent), istart(the_istart), jstart(the_jstart), 00063 fistart(-1), flength(-1) 00064 { 00065 build_(); 00066 } 00067 00068 SubVMatrix::SubVMatrix(VMat the_parent, real the_fistart, int the_jstart, real the_flength, int the_width) 00069 : VMatrix(int(the_flength * the_parent->length()), the_width), 00070 parent(the_parent), istart(-1), jstart(the_jstart), fistart(the_fistart), flength(the_flength) 00071 // Note that istart will be set to the right value in build_(). 00072 { 00073 build_(); 00074 } 00075 00077 // declareOptions // 00079 void SubVMatrix::declareOptions(OptionList &ol) 00080 { 00081 declareOption(ol, "parent", &SubVMatrix::parent, OptionBase::buildoption, "Source VMatrix"); 00082 declareOption(ol, "istart", &SubVMatrix::istart, OptionBase::buildoption, "Start i coordinate(row wise)"); 00083 declareOption(ol, "jstart", &SubVMatrix::jstart, OptionBase::buildoption, "Start j coordinate(column wise)"); 00084 declareOption(ol, "fistart", &SubVMatrix::fistart, OptionBase::buildoption, 00085 "If provided, will override istart to fistart * parent.length()"); 00086 declareOption(ol, "flength", &SubVMatrix::flength, OptionBase::buildoption, 00087 "If provided, will override length to flength * parent.length()"); 00088 inherited::declareOptions(ol); 00089 } 00090 00091 void SubVMatrix::build() 00092 { 00093 inherited::build(); 00094 build_(); 00095 } 00096 00097 void SubVMatrix::build_() 00098 { 00099 int pl = parent.length(); 00100 if (fistart >= 0) { 00101 istart = int(fistart * pl); 00102 } 00103 if (flength >= 0) { 00104 length_ = int(flength * pl); 00105 } 00106 if(length_<0) 00107 length_ = parent->length() - istart; 00108 00109 if(width_<0 && parent->width()>=0) 00110 width_ = parent->width() - jstart; 00111 00112 if(istart+length()>parent->length() || jstart+width()>parent->width()) 00113 PLERROR("In SubVMatrix constructor OUT OF BOUNDS of parent VMatrix"); 00114 00115 // Copy the parent field names. 00116 fieldinfos.resize(width_); 00117 if (parent->getFieldInfos().size() > 0) 00118 for(int j=0; j<width_; j++) 00119 fieldinfos[j] = parent->getFieldInfos()[jstart+j]; 00120 00121 // Copy the parent string mappings. 00122 map_rs.resize(width_); 00123 map_sr.resize(width_); 00124 for (int j = jstart; j < width_ + jstart; j++) { 00125 map_rs[j - jstart] = parent->getRealToStringMapping(j); 00126 map_sr[j - jstart] = parent->getStringToRealMapping(j); 00127 } 00128 00129 if (width_ == parent->width()) 00130 { 00131 if(inputsize_<0) inputsize_ = parent->inputsize(); 00132 if(targetsize_<0) targetsize_ = parent->targetsize(); 00133 if(weightsize_<0) weightsize_ = parent->weightsize(); 00134 } else { 00135 // The width has changed: if no sizes are specified, 00136 // we assume it's all input and no target. 00137 if(targetsize_<0) targetsize_ = 0; 00138 if(weightsize_<0) weightsize_ = 0; 00139 if(inputsize_<0) inputsize_ = width_ - targetsize_ - weightsize_; 00140 } 00141 00142 // cerr << "inputsize: "<<inputsize_ << " targetsize:"<<targetsize_<<"weightsize:"<<weightsize_<<endl; 00143 } 00144 00145 void SubVMatrix::reset_dimensions() 00146 { 00147 int delta_length = parent->length()-length_; 00148 int delta_width = 0; // parent->width()-width_; HACK 00149 parent->reset_dimensions(); 00150 length_=parent->length()-delta_length; 00151 width_=parent->width()-delta_width; 00152 } 00153 00154 real SubVMatrix::get(int i, int j) const 00155 { 00156 #ifdef BOUNDCHECK 00157 if(i<0 || i>=length() || j<0 || j>=width()) 00158 PLERROR("In SubVMatrix::get(i,j) OUT OF BOUND access"); 00159 #endif 00160 return parent->get(i+istart,j+jstart); 00161 } 00162 void SubVMatrix::getSubRow(int i, int j, Vec v) const 00163 { 00164 #ifdef BOUNDCHECK 00165 if(i<0 || i>=length() || j<0 || j+v.length()>width()) 00166 PLERROR("In SubVMatrix::getSubRow(i,j,v) OUT OF BOUND access"); 00167 #endif 00168 parent->getSubRow(i+istart,j+jstart,v); 00169 } 00170 00171 void SubVMatrix::getMat(int i, int j, Mat m) const 00172 { 00173 #ifdef BOUNDCHECK 00174 if(i<0 || i+m.length()>length() || j<0 || j+m.width()>width()) 00175 PLERROR("In SubVMatrix::getMat OUT OF BOUND access"); 00176 #endif 00177 parent->getMat(i+istart, j+jstart, m); 00178 } 00179 00180 void SubVMatrix::put(int i, int j, real value) 00181 { 00182 #ifdef BOUNDCHECK 00183 if(i<0 || i>=length() || j<0 || j>=width()) 00184 PLERROR("In SubVMatrix::put(i,j,value) OUT OF BOUND access"); 00185 #endif 00186 return parent->put(i+istart,j+jstart,value); 00187 } 00188 void SubVMatrix::putSubRow(int i, int j, Vec v) 00189 { 00190 #ifdef BOUNDCHECK 00191 if(i<0 || i>=length() || j<0 || j>=width()) 00192 PLERROR("In SubVMatrix::putSubRow(i,j,v) OUT OF BOUND access"); 00193 #endif 00194 parent->putSubRow(i+istart,j+jstart,v); 00195 } 00196 00197 void SubVMatrix::putMat(int i, int j, Mat m) 00198 { 00199 #ifdef BOUNDCHECK 00200 if(i<0 || i+m.length()>length() || j<0 || j+m.width()>width()) 00201 PLERROR("In SubVMatrix::putMat(i,j,m) OUT OF BOUND access"); 00202 #endif 00203 parent->putMat(i+istart, j+jstart, m); 00204 } 00205 00206 VMat SubVMatrix::subMat(int i, int j, int l, int w) 00207 { 00208 return parent->subMat(istart+i,jstart+j,l,w); 00209 } 00210 00212 // dot // 00214 real SubVMatrix::dot(int i1, int i2, int inputsize) const 00215 { 00216 if(jstart==0) 00217 return parent->dot(istart+i1, istart+i2, inputsize); 00218 else 00219 return VMatrix::dot(i1,i2,inputsize); 00220 } 00221 00222 real SubVMatrix::dot(int i, const Vec& v) const 00223 { 00224 if(jstart==0) 00225 return parent->dot(istart+i,v); 00226 else 00227 return VMatrix::dot(i,v); 00228 } 00229 00231 // makeDeepCopyFromShallowCopy // 00233 void SubVMatrix::makeDeepCopyFromShallowCopy(map<const void*, void*>& copies) { 00234 inherited::makeDeepCopyFromShallowCopy(copies); 00235 deepCopyField(parent, copies); 00236 } 00237 00238 } // end of namespcae PLearn

Generated on Tue Aug 17 16:07:55 2004 for PLearn by doxygen 1.3.7