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

CrossReferenceVMatrix.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: CrossReferenceVMatrix.cc,v 1.4 2004/04/05 22:50:25 morinf Exp $ 00039 ******************************************************* */ 00040 00041 #include "CrossReferenceVMatrix.h" 00042 00043 namespace PLearn { 00044 using namespace std; 00045 00046 00049 PLEARN_IMPLEMENT_OBJECT(CrossReferenceVMatrix, "ONE LINE DESC", "ONE LINE HELP"); 00050 00051 CrossReferenceVMatrix::CrossReferenceVMatrix() 00052 : col1(0) 00053 { 00054 } 00055 00056 CrossReferenceVMatrix::CrossReferenceVMatrix(VMat v1, int c1, VMat v2) 00057 : inherited(v1.length(), v1.width()+v2.width()-1), vm1(v1), col1(c1), vm2(v2) 00058 { 00059 //fieldinfos = v1->getFieldInfos(); 00060 // fieldinfos &= v2->getFieldInfos(); 00061 build(); 00062 } 00063 00064 00065 void 00066 CrossReferenceVMatrix::declareOptions(OptionList &ol) 00067 { 00068 declareOption(ol, "vm1", &CrossReferenceVMatrix::vm1, OptionBase::buildoption, ""); 00069 declareOption(ol, "vm2", &CrossReferenceVMatrix::vm2, OptionBase::buildoption, ""); 00070 declareOption(ol, "col1", &CrossReferenceVMatrix::col1, OptionBase::buildoption, ""); 00071 inherited::declareOptions(ol); 00072 } 00073 00074 void 00075 CrossReferenceVMatrix::build() 00076 { 00077 inherited::build(); 00078 build_(); 00079 } 00080 00081 void 00082 CrossReferenceVMatrix::build_() 00083 { 00084 if (vm1 && vm2) { 00085 fieldinfos = vm1->getFieldInfos(); 00086 fieldinfos &= vm2->getFieldInfos(); 00087 } 00088 } 00089 00090 void CrossReferenceVMatrix::getRow(int i, Vec samplevec) const 00091 { 00092 #ifdef BOUNDCHECK 00093 if (i<0 || i>=length() || samplevec.length()!=width()) 00094 PLERROR("In CrossReferenceVMatrix::getRow OUT OF BOUNDS"); 00095 #endif 00096 00097 Vec v1(vm1.width()); 00098 Vec v2(vm2.width()); 00099 vm1->getRow(i, v1); 00100 int index = (int)v1[col1]; 00101 vm2->getRow(index, v2); 00102 00103 for (int j=0; j<col1; j++) samplevec[j] = v1[j]; 00104 for (int j=col1+1; j<v1.length(); j++) samplevec[j-1] = v1[j]; 00105 for (int j=0; j<v2.length(); j++) samplevec[j+v1.length()-1] = v2[j]; 00106 } 00107 00108 real CrossReferenceVMatrix::get(int i, int j) const 00109 { 00110 #ifdef BOUNDCHECK 00111 if(i<0 || i>=length() || j<0 || j>=width()) 00112 PLERROR("In CrossReferenceVMatrix::get OUT OF BOUNDS"); 00113 #endif 00114 00115 if (j < col1) 00116 return vm1->get(i,j); 00117 else if (j < vm1.width()-1) 00118 return vm1->get(i,j+1); 00119 else { 00120 int ii = (int)vm1->get(i,col1); 00121 int jj = j - vm1.width() + 1; 00122 return vm2->get(ii,jj); 00123 } 00124 } 00125 00126 } // end of namespcae PLearn

Generated on Tue Aug 17 15:50:44 2004 for PLearn by doxygen 1.3.7