PLearn 0.1
VecExtendedVMatrix.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: VecExtendedVMatrix.cc 8617 2008-03-03 17:45:54Z nouiz $
00039  ******************************************************* */
00040 
00041 #include "VecExtendedVMatrix.h"
00042 #include <plearn/math/TMat.h>
00043 
00044 namespace PLearn {
00045 using namespace std;
00046 
00047 
00050 PLEARN_IMPLEMENT_OBJECT(VecExtendedVMatrix,
00051                         "Extends the source by appending columns to its right",
00052                         "A VecExtendedVMatrix is similar to an"
00053                         " ExtendedVMatrix: it extends the\n"
00054                         "source VMat by appending COLUMNS to its right.  The"
00055                         " appended columns\n"
00056                         "are filled with a constant vector passed upon"
00057                         " construction.  For example,\n"
00058                         "if the vector [1,2,3] is passed at construction, then"
00059                         " every row of the\n"
00060                         "source VMat will be extended by 3 columns, containing"
00061                         " [1,2,3]\n"
00062                         "(constant)\n"
00063                         );
00064 
00065 VecExtendedVMatrix::VecExtendedVMatrix(bool call_build_)
00066     : inherited(call_build_)
00067 {
00068     // build_() won't do anything
00069 }
00070 
00071 VecExtendedVMatrix::VecExtendedVMatrix(VMat the_source, Vec extend_data,
00072                                        bool call_build_)
00073     : inherited(the_source,
00074                 the_source->length(),
00075                 the_source->width() + extend_data.length(),
00076                 call_build_),
00077       extend_data_(extend_data)
00078 {
00079     if( call_build_ )
00080         build_();
00081 }
00082 
00083 void VecExtendedVMatrix::build()
00084 {
00085     inherited::build();
00086     build_();
00087 }
00088 
00089 void VecExtendedVMatrix::build_()
00090 {
00091     if (source)
00092         fieldinfos = source->getFieldInfos();
00093     updateMtime(source);
00094 }
00095 
00096 void VecExtendedVMatrix::declareOptions(OptionList &ol)
00097 {
00098     declareOption(ol, "underlying_", &VecExtendedVMatrix::source,
00099                   (OptionBase::learntoption | OptionBase::nosave),
00100                   "DEPRECATED - Use 'source' instead.");
00101 
00102     declareOption(ol, "extend_data_", &VecExtendedVMatrix::extend_data_,
00103                   OptionBase::buildoption, "");
00104 
00105     inherited::declareOptions(ol);
00106 }
00107 
00108 void VecExtendedVMatrix::getNewRow(int i, const Vec& v) const
00109 {
00110 #ifdef BOUNDCHECK
00111     if(i<0 || i>=length())
00112         PLERROR("In VecExtendedVMatrix::getNewRow OUT OF BOUNDS");
00113     if(v.length() != width())
00114         PLERROR("In VecExtendedVMatrix::getNewRow v.length() must be equal to the VMat's width");
00115 #endif
00116 
00117     Vec subv = v.subVec(0, source->width());
00118     source->getRow(i,subv);
00119     copy(extend_data_.begin(), extend_data_.end(),
00120          v.begin() + source->width());
00121 }
00122 
00123 } // end of namespace PLearn
00124 
00125 
00126 /*
00127   Local Variables:
00128   mode:c++
00129   c-basic-offset:4
00130   c-file-style:"stroustrup"
00131   c-file-offsets:((innamespace . 0)(inline-open . 0))
00132   indent-tabs-mode:nil
00133   fill-column:79
00134   End:
00135 */
00136 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines