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

SelectRowsVMatrix.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 // Copyright (C) 2003 Olivier Delalleau 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: SelectRowsVMatrix.cc,v 1.15 2004/06/18 16:45:23 tihocan Exp $ 00040 ******************************************************* */ 00041 00042 #include "SelectRowsVMatrix.h" 00043 00044 namespace PLearn { 00045 using namespace std; 00046 00049 PLEARN_IMPLEMENT_OBJECT(SelectRowsVMatrix, 00050 "VMat class that selects samples from a source matrix according to given vector of indices.", 00051 "" 00052 ); 00053 00054 SelectRowsVMatrix::SelectRowsVMatrix() 00055 { 00056 } 00057 00058 SelectRowsVMatrix::SelectRowsVMatrix(VMat the_source, TVec<int> the_indices) 00059 : indices(the_indices) 00060 { 00061 source = the_source; 00062 build_(); 00063 } 00064 00066 SelectRowsVMatrix::SelectRowsVMatrix(VMat the_source, Vec the_indices) 00067 { 00068 source = the_source; 00069 indices.resize(the_indices.length()); 00070 indices << the_indices; // copy to integer indices 00071 build_(); 00072 } 00073 00074 real SelectRowsVMatrix::get(int i, int j) const 00075 { return source->get(indices[i], j); } 00076 00077 void SelectRowsVMatrix::getSubRow(int i, int j, Vec v) const 00078 { source->getSubRow(indices[i], j, v); } 00079 00080 real SelectRowsVMatrix::dot(int i1, int i2, int inputsize) const 00081 { return source->dot(int(indices[i1]), int(indices[i2]), inputsize); } 00082 00083 real SelectRowsVMatrix::dot(int i, const Vec& v) const 00084 { return source->dot(indices[i],v); } 00085 00086 real SelectRowsVMatrix::getStringVal(int col, const string & str) const 00087 { return source->getStringVal(col, str); } 00088 00089 string SelectRowsVMatrix::getValString(int col, real val) const 00090 { return source->getValString(col,val); } 00091 00092 string SelectRowsVMatrix::getString(int row, int col) const 00093 { return source->getString(indices[row], col); } 00094 00095 const map<string,real>& SelectRowsVMatrix::getStringToRealMapping(int col) const 00096 { return source->getStringToRealMapping(col);} 00097 00098 const map<real,string>& SelectRowsVMatrix::getRealToStringMapping(int col) const 00099 { return source->getRealToStringMapping(col);} 00100 00101 void SelectRowsVMatrix::declareOptions(OptionList &ol) 00102 { 00103 declareOption(ol, "indices", &SelectRowsVMatrix::indices, OptionBase::buildoption, 00104 " The array of row indices to extract"); 00105 inherited::declareOptions(ol); 00106 } 00107 00108 void SelectRowsVMatrix::makeDeepCopyFromShallowCopy(map<const void*, void*>& copies) 00109 { 00110 inherited::makeDeepCopyFromShallowCopy(copies); 00111 deepCopyField(indices, copies); 00112 } 00113 00115 // build // 00117 void SelectRowsVMatrix::build() 00118 { 00119 inherited::build(); 00120 build_(); 00121 } 00122 00124 // build_ // 00126 void SelectRowsVMatrix::build_() 00127 { 00128 length_ = indices.length(); 00129 if (source) { 00130 width_ = source->width(); 00131 inputsize_ = source->inputsize(); 00132 targetsize_ = source->targetsize(); 00133 weightsize_ = source->weightsize(); 00134 fieldinfos = source->fieldinfos; 00135 } 00136 } 00137 00138 } // end of namespcae PLearn

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