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

TemporalHorizonVMatrix.cc

Go to the documentation of this file.
00001 // -*- C++ -*- 00002 00003 // TemporalHorizonVMatrix.cc 00004 // 00005 // PLearn (A C++ Machine Learning Library) 00006 // Copyright (C) 2003 Rejean Ducharme, Yoshua Bengio 00007 // Copyright (C) 2003 Pascal Vincent 00008 // 00009 // Redistribution and use in source and binary forms, with or without 00010 // modification, are permitted provided that the following conditions are met: 00011 // 00012 // 1. Redistributions of source code must retain the above copyright 00013 // notice, this list of conditions and the following disclaimer. 00014 // 00015 // 2. Redistributions in binary form must reproduce the above copyright 00016 // notice, this list of conditions and the following disclaimer in the 00017 // documentation and/or other materials provided with the distribution. 00018 // 00019 // 3. The name of the authors may not be used to endorse or promote 00020 // products derived from this software without specific prior written 00021 // permission. 00022 // 00023 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00024 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00025 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00026 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00027 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00028 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00029 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00030 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00031 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00032 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 // 00034 // This file is part of the PLearn library. For more information on the PLearn 00035 // library, go to the PLearn Web site at www.plearn.org 00036 00037 00038 /* ******************************************************* 00039 * $Id: TemporalHorizonVMatrix.cc,v 1.4 2004/04/05 23:07:07 morinf Exp $ 00040 ******************************************************* */ 00041 00042 #include "TemporalHorizonVMatrix.h" 00043 00044 namespace PLearn { 00045 using namespace std; 00046 00049 PLEARN_IMPLEMENT_OBJECT(TemporalHorizonVMatrix, "ONE LINE DESCR", 00050 " VMat class that delay the last entries of an underlying VMat by a certain horizon.\n"); 00051 00052 TemporalHorizonVMatrix::TemporalHorizonVMatrix(VMat the_distr, int the_horizon, int target_size) 00053 : inherited(the_distr.length()-the_horizon, the_distr->width()), 00054 distr(the_distr), horizon(the_horizon), targetsize(target_size) 00055 { 00056 fieldinfos = distr->fieldinfos; 00057 row_delay.resize(width()); 00058 for (int i=0; i<width(); i++) 00059 row_delay[i] = i<width()-targetsize ? 0 : horizon; 00060 00061 defineSizes(distr->inputsize(), distr->targetsize(), distr->weightsize()); 00062 } 00063 00064 real TemporalHorizonVMatrix::get(int i, int j) const 00065 { return distr->get(i+row_delay[j], j); } 00066 00067 void TemporalHorizonVMatrix::put(int i, int j, real value) 00068 { distr->put(i+row_delay[j], j, value); } 00069 00070 real TemporalHorizonVMatrix::dot(int i1, int i2, int inputsize) const 00071 { 00072 real res = 0.; 00073 for(int k=0; k<inputsize; k++) 00074 res += distr->get(i1+row_delay[k],k)*distr->get(i2+row_delay[k],k); 00075 return res; 00076 } 00077 00078 real TemporalHorizonVMatrix::dot(int i, const Vec& v) const 00079 { 00080 real res = 0.; 00081 for(int k=0; k<v.length(); k++) 00082 res += distr->get(i+row_delay[k],k)*v[k]; 00083 return res; 00084 } 00085 00086 real TemporalHorizonVMatrix::getStringVal(int col, const string & str) const 00087 { return distr->getStringVal(col, str); } 00088 00089 string TemporalHorizonVMatrix::getValString(int col, real val) const 00090 { return distr->getValString(col,val); } 00091 00092 string TemporalHorizonVMatrix::getString(int row, int col) const 00093 { return distr->getString(row+row_delay[col],col); } 00094 00095 const map<string,real>& TemporalHorizonVMatrix::getStringToRealMapping(int col) const 00096 { return distr->getStringToRealMapping(col);} 00097 00098 const map<real,string>& TemporalHorizonVMatrix::getRealToStringMapping(int col) const 00099 { return distr->getRealToStringMapping(col);} 00100 00101 void TemporalHorizonVMatrix::declareOptions(OptionList &ol) 00102 { 00103 declareOption(ol, "distr", &TemporalHorizonVMatrix::distr, OptionBase::buildoption, 00104 " The matrix viewed by the TemporalHorizonVMatrix"); 00105 declareOption(ol, "horizon", &TemporalHorizonVMatrix::horizon, OptionBase::buildoption, 00106 " The temporal value by which to delay the VMat"); 00107 declareOption(ol, "targetsize", &TemporalHorizonVMatrix::targetsize, OptionBase::buildoption, 00108 " The number of last entries to delay"); 00109 inherited::declareOptions(ol); 00110 } 00111 00112 void TemporalHorizonVMatrix::makeDeepCopyFromShallowCopy(map<const void*, void*>& copies) 00113 { 00114 inherited::makeDeepCopyFromShallowCopy(copies); 00115 deepCopyField(distr, copies); 00116 } 00117 00119 // build // 00121 void TemporalHorizonVMatrix::build() 00122 { 00123 inherited::build(); 00124 build_(); 00125 } 00126 00128 // build_ // 00130 void TemporalHorizonVMatrix::build_() 00131 { 00132 if (distr) { 00133 length_ = distr->length()-horizon; 00134 width_ = distr->width(); 00135 fieldinfos = distr->fieldinfos; 00136 00137 row_delay.resize(width()); 00138 for (int i=0; i<width(); i++) 00139 row_delay[i] = i<width()-targetsize ? 0 : horizon; 00140 00141 defineSizes(distr->inputsize(), distr->targetsize(), distr->weightsize()); 00142 } 00143 } 00144 00145 } // end of namespace PLearn

Generated on Tue Aug 17 16:08:15 2004 for PLearn by doxygen 1.3.7