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

RemapLastColumnVMatrix.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: RemapLastColumnVMatrix.cc,v 1.6 2004/07/07 17:30:48 tihocan Exp $ 00039 ******************************************************* */ 00040 00041 #include "RemapLastColumnVMatrix.h" 00042 00043 namespace PLearn { 00044 using namespace std; 00045 00046 00049 PLEARN_IMPLEMENT_OBJECT(RemapLastColumnVMatrix, "ONE LINE DESC", "NO HELP"); 00050 00051 RemapLastColumnVMatrix::RemapLastColumnVMatrix() 00052 : if_equals_val(0), then_val(0), else_val(0) 00053 { 00054 } 00055 00056 RemapLastColumnVMatrix::RemapLastColumnVMatrix(VMat the_underlying_distr, Mat the_mapping) 00057 : inherited (the_underlying_distr->length(), the_underlying_distr->width()+the_mapping.width()-2), 00058 underlying_distr(the_underlying_distr), mapping(the_mapping) 00059 { 00060 } 00061 00062 RemapLastColumnVMatrix::RemapLastColumnVMatrix(VMat the_underlying_distr, real if_equals_value, real then_value, real else_value) 00063 : inherited(the_underlying_distr->length(), the_underlying_distr->width()), 00064 underlying_distr(the_underlying_distr), if_equals_val(if_equals_value), 00065 then_val(then_value), else_val(else_value) 00066 { 00067 } 00068 00069 void 00070 RemapLastColumnVMatrix::build() 00071 { 00072 inherited::build(); 00073 build_(); 00074 } 00075 00076 void 00077 RemapLastColumnVMatrix::build_() 00078 { 00079 } 00080 00081 void 00082 RemapLastColumnVMatrix::declareOptions(OptionList &ol) 00083 { 00084 declareOption(ol, "underlying_distr", &RemapLastColumnVMatrix::underlying_distr, OptionBase::buildoption, ""); 00085 declareOption(ol, "mapping", &RemapLastColumnVMatrix::mapping, OptionBase::buildoption, ""); 00086 declareOption(ol, "if_equals_val", &RemapLastColumnVMatrix::if_equals_val, OptionBase::buildoption, ""); 00087 declareOption(ol, "then_val", &RemapLastColumnVMatrix::then_val, OptionBase::buildoption, ""); 00088 declareOption(ol, "else_val", &RemapLastColumnVMatrix::else_val, OptionBase::buildoption, ""); 00089 inherited::declareOptions(ol); 00090 } 00091 00092 void RemapLastColumnVMatrix::getNewRow(int i, const Vec& samplevec) const 00093 { 00094 #ifdef BOUNDCHECK 00095 if(i<0 || i>=length()) 00096 PLERROR("In RemapLastColumnVMatrix::getNewRow OUT OF BOUNDS"); 00097 if(samplevec.length()!=width()) 00098 PLERROR("In RemapLastColumnVMatrix::getNewRow samplevec.length() must be equal to the VMat's width"); 00099 #endif 00100 if(mapping.isEmpty()) // use if-then-else mapping 00101 { 00102 underlying_distr->getRow(i,samplevec); 00103 real& lastelem = samplevec.lastElement(); 00104 if(lastelem==if_equals_val) 00105 lastelem = then_val; 00106 else 00107 lastelem = else_val; 00108 } 00109 else // use mapping matrix 00110 { 00111 int underlying_width = underlying_distr->width(); 00112 int replacement_width = mapping.width()-1; 00113 underlying_distr->getRow(i,samplevec.subVec(0,underlying_width)); 00114 real val = samplevec[underlying_width-1]; 00115 int k; 00116 for(k=0; k<mapping.length(); k++) 00117 { 00118 if(mapping(k,0)==val) 00119 { 00120 samplevec.subVec(underlying_width-1,replacement_width) << mapping(k).subVec(1,replacement_width); 00121 break; 00122 } 00123 } 00124 if(k>=mapping.length()) 00125 PLERROR("In RemapLastColumnVMatrix::getRow there is a value in the last column that does not have any defined mapping"); 00126 } 00127 } 00128 00129 } // end of namespcae PLearn

Generated on Tue Aug 17 16:03:54 2004 for PLearn by doxygen 1.3.7