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

VMat.h

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-2002 Pascal Vincent, Yoshua Bengio and University of Montreal 00006 // 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 00039 /* ******************************************************* 00040 * $Id: VMat.h,v 1.21 2004/07/21 16:30:55 chrish42 Exp $ 00041 * This file is part of the PLearn library. 00042 ******************************************************* */ 00043 00044 00047 #ifndef VMat_INC 00048 #define VMat_INC 00049 00050 #include <cstdlib> 00051 #include <plearn/base/PP.h> 00052 #include <plearn/math/TMat.h> 00053 #include "VMField.h" 00054 #include "VMatrix.h" 00055 #include "VVec.h" 00056 00057 namespace PLearn { 00058 using namespace std; 00059 00060 class Ker; 00061 00062 class VMat: public PP<VMatrix> 00063 { 00064 public: 00065 VMat(); 00066 VMat(VMatrix* d); 00067 VMat(const VMat& d); 00068 VMat(const Mat& datamat); 00069 00070 int length() const { return ptr->length(); } 00071 int width() const { return ptr->width(); } 00072 00073 string fieldName(int fieldindex) const 00074 { return ptr->fieldName(fieldindex); } 00075 00076 int getFieldIndex(const string& fieldname_or_num) const 00077 { return ptr->getFieldIndex(fieldname_or_num); } 00078 00079 00080 real operator()(int i, int j) const { return ptr->get(i,j); } 00081 VVec operator()(int i) const { return VVec(*this, i); } 00082 Vec getColumn(int i) const { Vec v(ptr->length()); ptr->getColumn(i,v); return v; } 00083 Vec getSubRow(int i, int s) const { Vec v(s); ptr->getSubRow(i, 0, v); return v; } 00084 00085 VMat subMat(int i, int j, int l, int w) const { return ptr->subMat(i,j,l,w); } 00086 VMat subMatRows(int i, int l) const; 00087 //VMat subMatRows(int i, int l) const { return ptr->subMat(i,0,l,width()); } 00088 VMat subMatColumns(int j, int w) const { return ptr->subMat(0,j,length(),w); } 00089 00090 inline void getExample(int i, Vec& input, Vec& target, real& weight) 00091 { ptr->getExample(i, input, target, weight); } 00092 00093 VMat row(int i) const { return subMatRows(i,1); } 00094 VMat firstRow() const { return row(0); } 00095 VMat lastRow() const { return row(length()-1); } 00096 VMat column(int j) const { return subMatColumns(j,1); } 00097 VMat firstColumn() const { return column(0); } 00098 VMat lastColumn() const { return column(width()-1); } 00099 Mat toMat() const { return ptr->toMat();} 00100 00102 VMat rows(TVec<int> rows_indices) const; 00104 VMat rows(Vec rows_indices) const; 00106 VMat rows(const string& indexfile) const; 00107 00109 VMat columns(TVec<int> columns_indices) const; 00111 VMat columns(Vec columns_indices) const; 00112 00113 00114 operator Mat() const { return ptr->toMat(); } 00115 inline void save(const string& filename) const { ptr->save(filename); } 00116 00121 void precompute(); 00122 00131 void precompute(const string& pmatfile, bool use_existing_file=false); 00132 00133 inline void print(ostream& out) const { ptr->print(out); } 00134 00135 ~VMat(); 00136 }; 00137 00138 DECLARE_OBJECT_PP(VMat, VMatrix); 00139 00140 inline void operator<<(const Mat& dest, const VMatrix& src) 00141 { 00142 if(dest.length()!=src.length() || dest.width()!=src.width()) 00143 PLERROR("In operator<<(const Mat& dest, const VMatrix& src), incompatible dimensions"); 00144 src.getMat(0,0,dest); 00145 } 00146 00147 inline void operator>>(const VMatrix& src, const Mat& dest) 00148 { dest << src; } 00149 00150 inline void operator<<(const Mat& dest, const VMat& src) 00151 { dest << *(VMatrix*)src; } 00152 00153 inline void operator>>(const VMat& src, const Mat& dest) 00154 { dest << src; } 00155 00156 00157 00163 inline Array<VMat> operator&(const VMat& d1, const VMat& d2) 00164 { return Array<VMat>(d1,d2); } 00165 00166 inline ostream& operator<<(ostream& out, const VMat& m) 00167 { m.print(out); return out; } 00168 00169 template <> void deepCopyField(VMat& field, CopiesMap& copies); 00170 00173 VMat loadAsciiAsVMat(const string& filename); 00174 00175 } // end of namespace PLearn 00176 00177 #endif 00178

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