PLearn 0.1
SelectColumnsVMatrix.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-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: SelectColumnsVMatrix.h 9733 2008-12-02 19:53:54Z nouiz $
00040  ******************************************************* */
00041 
00042 
00045 #ifndef SelectColumnsVMatrix_INC
00046 #define SelectColumnsVMatrix_INC
00047 
00048 #include "SourceVMatrix.h"
00049 
00050 namespace PLearn {
00051 using namespace std;
00052 
00056 class SelectColumnsVMatrix: public SourceVMatrix
00057 {
00058 
00059 private:
00060 
00061     typedef SourceVMatrix inherited;
00062 
00064     Vec sinput;
00065 
00066 public:
00067 
00068     // Public build options.
00069 
00070     bool extend_with_missing;
00071     TVec<int> indices;
00072     TVec<string> fields;
00073     PPath save_fields;
00074     bool fields_partial_match;
00075     bool fields_regex;
00076     bool inverse_fields_selection;
00077     bool warn_non_selected_field;
00078 
00079 public:
00080 
00082     SelectColumnsVMatrix();
00083 
00086     SelectColumnsVMatrix(VMat the_source, TVec<string> the_fields,
00087                          bool the_extend_with_missing = false,
00088                          bool call_build_ = true);
00089 
00092     SelectColumnsVMatrix(VMat the_source, TVec<int> the_indices,
00093                          bool call_build_ = true);
00094 
00096     SelectColumnsVMatrix(VMat the_source, Vec the_indices);
00097 
00098     PLEARN_DECLARE_OBJECT(SelectColumnsVMatrix);
00099 
00100     virtual void build();
00101     virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies);
00102 
00103 protected:
00104 
00106     TVec<int> sel_indices;
00107 
00108     static void declareOptions(OptionList &ol);
00109     void getNewRow(int i, const Vec& v) const { getSubRow(i, 0, v); }
00112     void getIndicesFromFields();
00113 
00114 public:
00115 
00116     virtual real get(int i, int j) const;
00117     virtual void getSubRow(int i, int j, Vec v) const;
00118     virtual void reset_dimensions()
00119     {
00120         source->reset_dimensions(); length_=source->length();
00121         for (int i=0;indices.length();i++)
00122             if (indices[i]>=source->width())
00123                 PLERROR("SelectColumnsVMatrix::reset_dimensions, underlying source not wide enough (%d>=%d)",
00124                         indices[i],source->width());
00125     }
00126 
00127     virtual const map<string,real>& getStringToRealMapping(int col) const;
00128     virtual const map<real,string>& getRealToStringMapping(int col) const;
00129 
00130     virtual real getStringVal(int col, const string & str) const;
00131     virtual string getValString(int col, real val) const;
00132 
00135     virtual PP<Dictionary> getDictionary(int col) const;
00136 
00138     virtual void getValues(int row, int col, Vec& values) const;
00139 
00141     virtual void getValues(const Vec& input, int col, Vec& values) const;
00142 
00143 
00144 private:
00145     void build_();
00146 
00147 };
00148 
00149 DECLARE_OBJECT_PTR(SelectColumnsVMatrix);
00150 
00151 } // end of namespace PLearn
00152 #endif
00153 
00154 
00155 /*
00156   Local Variables:
00157   mode:c++
00158   c-basic-offset:4
00159   c-file-style:"stroustrup"
00160   c-file-offsets:((innamespace . 0)(inline-open . 0))
00161   indent-tabs-mode:nil
00162   fill-column:79
00163   End:
00164 */
00165 // 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