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

InterleaveVMatrix.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: InterleaveVMatrix.cc,v 1.4 2004/04/05 22:55:21 morinf Exp $ 00039 ******************************************************* */ 00040 00041 #include "InterleaveVMatrix.h" 00042 00043 namespace PLearn { 00044 using namespace std; 00045 00046 00049 PLEARN_IMPLEMENT_OBJECT(InterleaveVMatrix, "ONE LINE DESC", "ONE LINE HELP"); 00050 00051 InterleaveVMatrix::InterleaveVMatrix() 00052 { 00053 } 00054 00055 InterleaveVMatrix::InterleaveVMatrix(Array<VMat> the_vm) 00056 : vm(the_vm) 00057 { 00058 build(); 00059 } 00060 00061 InterleaveVMatrix::InterleaveVMatrix(VMat d1, VMat d2) 00062 : vm(d1,d2) 00063 { 00064 build(); 00065 } 00066 00067 void 00068 InterleaveVMatrix::build() 00069 { 00070 inherited::build(); 00071 build_(); 00072 } 00073 00074 void 00075 InterleaveVMatrix::build_() 00076 { 00077 if (vm) { 00078 int n = vm.size(); 00079 if (n<1) 00080 PLERROR("InterleaveVMatrix expects >= 1 underlying-distribution, got %d",n); 00081 00082 // Copy the parent fields 00083 fieldinfos = vm[0]->getFieldInfos(); 00084 00085 width_ = vm[0]->width(); 00086 int maxl = 0; 00087 for (int i = 0; i < n; i++) { 00088 if (vm[i]->width() != width_) 00089 PLERROR("InterleaveVMatrix: underlying-distr %d has %d width, while 0-th has %d",i,vm[i]->width(),width_); 00090 int l = vm[i]->length(); 00091 if (l > maxl) 00092 maxl=l; 00093 } 00094 length_ = n * maxl; 00095 } 00096 } 00097 00098 void 00099 InterleaveVMatrix::declareOptions(OptionList &ol) 00100 { 00101 declareOption(ol, "vm", &InterleaveVMatrix::vm, OptionBase::buildoption, ""); 00102 inherited::declareOptions(ol); 00103 } 00104 00105 real InterleaveVMatrix::get(int i, int j) const 00106 { 00107 #ifdef BOUNDCHECK 00108 if(i<0 || i>=length() || j<0 || j>=width()) 00109 PLERROR("In InterleaveVMatrix::get OUT OF BOUNDS"); 00110 #endif 00111 int n=vm.size(); 00112 int m = i%n; // which VM 00113 int pos = int(i/n) % vm[m].length(); // position within vm[m] 00114 return vm[m]->get(pos,j); 00115 } 00116 00117 void InterleaveVMatrix::getSubRow(int i, int j, Vec v) const 00118 { 00119 #ifdef BOUNDCHECK 00120 if(i<0 || i>=length() || j<0 || j+v.length()>width()) 00121 PLERROR("In InterleaveVMatrix::getRow OUT OF BOUNDS"); 00122 #endif 00123 int n=vm.size(); 00124 int m = i%n; // which VM 00125 int pos = int(i/n) % vm[m].length(); // position within vm[m] 00126 vm[m]->getSubRow(pos, j, v); 00127 } 00128 00129 } // end of namespcae PLearn

Generated on Tue Aug 17 15:55:37 2004 for PLearn by doxygen 1.3.7