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

GeneralizedOneHotVMatrix.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: GeneralizedOneHotVMatrix.cc,v 1.6 2004/07/09 19:42:23 tihocan Exp $ 00039 ******************************************************* */ 00040 00041 #include "GeneralizedOneHotVMatrix.h" 00042 00043 namespace PLearn { 00044 using namespace std; 00045 00046 00049 PLEARN_IMPLEMENT_OBJECT(GeneralizedOneHotVMatrix, "ONE LINE DESC", "ONE LINE HELP"); 00050 00051 GeneralizedOneHotVMatrix::GeneralizedOneHotVMatrix() 00052 { 00053 } 00054 00055 GeneralizedOneHotVMatrix::GeneralizedOneHotVMatrix(VMat the_distr, Vec the_index, 00056 Vec the_nclasses, Vec the_cold_value, 00057 Vec the_host_value) 00058 : inherited(the_distr->length(), the_distr->width()+(int)sum(the_nclasses)-the_nclasses.length()), 00059 distr(the_distr), index(the_index), nclasses(the_nclasses), 00060 cold_value(the_cold_value), hot_value(the_host_value) 00061 { 00062 if (min(index)<0 || max(index)>distr->length()-1) 00063 PLERROR("In GeneralizedOneHotVMatrix: all values of index must be in range [0,%d]", 00064 distr->length()-1); 00065 if (index.length()!=nclasses.length() || cold_value.length()!=hot_value.length() || index.length()!=hot_value.length()) 00066 PLERROR("In GeneralizedOneHotVMatrix: index, nclasses, cold_value and hot_value must have same length"); 00067 } 00068 00069 void 00070 GeneralizedOneHotVMatrix::build() 00071 { 00072 inherited::build(); 00073 build_(); 00074 } 00075 00076 void 00077 GeneralizedOneHotVMatrix::build_() 00078 { 00079 } 00080 00081 void 00082 GeneralizedOneHotVMatrix::declareOptions(OptionList &ol) 00083 { 00084 declareOption(ol, "distr", &GeneralizedOneHotVMatrix::distr, OptionBase::buildoption, ""); 00085 declareOption(ol, "index", &GeneralizedOneHotVMatrix::index, OptionBase::buildoption, ""); 00086 declareOption(ol, "nclasses", &GeneralizedOneHotVMatrix::nclasses, OptionBase::buildoption, ""); 00087 declareOption(ol, "cold_value", &GeneralizedOneHotVMatrix::cold_value, OptionBase::buildoption, ""); 00088 declareOption(ol, "hot_value", &GeneralizedOneHotVMatrix::hot_value, OptionBase::buildoption, ""); 00089 inherited::declareOptions(ol); 00090 } 00091 00092 void GeneralizedOneHotVMatrix::getNewRow(int i, const Vec& v) const 00093 { 00094 #ifdef BOUNDCHECK 00095 if(i<0 || i>=length()) 00096 PLERROR("In OneHotVMatrix::getNewRow OUT OF BOUNDS"); 00097 if(v.length()!=width()) 00098 PLERROR("In GeneralizedOneHotVMatrix::getNewRow v.length() must be equal to the VMat's width"); 00099 #endif 00100 00101 Vec input(distr->width()); 00102 distr->getRow(i, input); 00103 int v_pos = 0; 00104 for (int j=0; j<input.length(); j++) { 00105 const int index_pos = vec_find(index, (real)j); 00106 if (index_pos == -1) 00107 v[v_pos++] = input[j]; 00108 else { 00109 const int nb_class = (int)nclasses[index_pos]; 00110 Vec target = v.subVec(v_pos, nb_class); 00111 const real cold = cold_value[index_pos]; 00112 const real hot = hot_value[index_pos]; 00113 const int classnum = int(distr->get(i,j)); 00114 fill_one_hot(target, classnum, cold, hot); 00115 v_pos += nb_class; 00116 } 00117 } 00118 } 00119 00120 00121 } // end of namespcae PLearn

Generated on Tue Aug 17 15:54:11 2004 for PLearn by doxygen 1.3.7