PLearn 0.1
|
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 8239 2007-11-09 15:35:34Z nouiz $ 00041 * This file is part of the PLearn library. 00042 ******************************************************* */ 00043 00044 00047 #ifndef VMat_INC 00048 #define VMat_INC 00049 00050 #include "VMatrix.h" 00051 //#include <cstdlib> 00052 #include <plearn/base/PP.h> 00053 #include <plearn/math/TMat.h> 00054 //#include "VMField.h" 00055 #include "VVec.h" 00056 00057 namespace PLearn { 00058 using namespace std; 00059 00060 class VMat: public PP<VMatrix> 00061 { 00062 public: 00063 VMat(); 00064 VMat(VMatrix* d); 00065 VMat(const VMat& d); 00066 VMat(const Mat& datamat); 00067 00069 int length() const { return ptr->length(); } 00070 00072 int width() const { return ptr->width(); } 00073 00074 string fieldName(int fieldindex) const 00075 { return ptr->fieldName(fieldindex); } 00076 00077 int getFieldIndex(const string& fieldname_or_num) const 00078 { return ptr->getFieldIndex(fieldname_or_num); } 00079 00080 00081 real operator()(int i, int j) const { return ptr->get(i,j); } 00082 VVec operator()(int i) const { return VVec(*this, i); } 00083 Vec getColumn(int i) const { Vec v(ptr->length()); ptr->getColumn(i,v); return v; } 00084 Vec getSubRow(int i, int s) const { Vec v(s); ptr->getSubRow(i, 0, v); return v; } 00085 00086 VMat subMat(int i, int j, int l, int w) const { return ptr->subMat(i,j,l,w); } 00087 VMat subMatRows(int i, int l) const; 00088 //VMat subMatRows(int i, int l) const { return ptr->subMat(i,0,l,width()); } 00089 VMat subMatColumns(int j, int w) const { return ptr->subMat(0,j,length(),w); } 00090 00091 inline void getExample(int i, Vec& input, Vec& target, real& weight) 00092 { ptr->getExample(i, input, target, weight); } 00093 00094 VMat row(int i) const { return subMatRows(i,1); } 00095 VMat firstRow() const { return row(0); } 00096 VMat lastRow() const { return row(length()-1); } 00097 VMat column(int j) const { return subMatColumns(j,1); } 00098 VMat firstColumn() const { return column(0); } 00099 VMat lastColumn() const { return column(width()-1); } 00100 Mat toMat() const { return ptr->toMat();} 00101 00103 VMat rows(TVec<int> rows_indices) const; 00105 VMat rows(Vec rows_indices) const; 00107 VMat rows(const PPath& indexfile) const; 00108 00110 VMat columns(TVec<int> columns_indices) const; 00112 VMat columns(Vec columns_indices) const; 00113 00114 00115 operator Mat() const { return ptr->toMat(); } 00116 inline void save(const PPath& filename) const { ptr->save(filename); } 00117 00122 void precompute(); 00123 00132 void precompute(const PPath& pmatfile, bool use_existing_file=false); 00133 00134 // inline void print(PStream& out) const { ptr->print(out); } 00135 00136 ~VMat(); 00137 }; 00138 00139 DECLARE_OBJECT_PP(VMat, VMatrix); 00140 00141 inline void operator<<(const Mat& dest, const VMatrix& src) 00142 { 00143 if(dest.length()!=src.length() || dest.width()!=src.width()) 00144 PLERROR("In operator<<(const Mat& dest, const VMatrix& src), incompatible dimensions"); 00145 src.getMat(0,0,dest); 00146 } 00147 00148 inline void operator>>(const VMatrix& src, const Mat& dest) 00149 { dest << src; } 00150 00151 inline void operator<<(const Mat& dest, const VMat& src) 00152 { dest << *(VMatrix*)src; } 00153 00154 inline void operator>>(const VMat& src, const Mat& dest) 00155 { dest << src; } 00156 00157 00158 00164 inline Array<VMat> operator&(const VMat& d1, const VMat& d2) 00165 { return Array<VMat>(d1,d2); } 00166 00167 /* Already defined in the DECLARE_OBJECT_PP macro. 00168 inline PStream& operator<<(PStream& out, const VMat& m) 00169 { m.print(out); return out; } 00170 */ 00171 00172 template <> void deepCopyField(VMat& field, CopiesMap& copies); 00173 00176 VMat loadAsciiAsVMat(const PPath& filename); 00177 00178 } // end of namespace PLearn 00179 00180 #endif 00181 00182 00183 /* 00184 Local Variables: 00185 mode:c++ 00186 c-basic-offset:4 00187 c-file-style:"stroustrup" 00188 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00189 indent-tabs-mode:nil 00190 fill-column:79 00191 End: 00192 */ 00193 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :