PLearn 0.1
AutoVMatrix.cc
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // AutoVMatrix.cc
00004 // Copyright (C) 2002 Pascal Vincent
00005 //
00006 
00007 // Redistribution and use in source and binary forms, with or without
00008 // modification, are permitted provided that the following conditions are met:
00009 //
00010 //  1. Redistributions of source code must retain the above copyright
00011 //     notice, this list of conditions and the following disclaimer.
00012 //
00013 //  2. Redistributions in binary form must reproduce the above copyright
00014 //     notice, this list of conditions and the following disclaimer in the
00015 //     documentation and/or other materials provided with the distribution.
00016 //
00017 //  3. The name of the authors may not be used to endorse or promote
00018 //     products derived from this software without specific prior written
00019 //     permission.
00020 //
00021 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
00022 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00023 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
00024 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00025 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
00026 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00027 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00028 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00029 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00030 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031 //
00032 // This file is part of the PLearn library. For more information on the PLearn
00033 // library, go to the PLearn Web site at www.plearn.org
00034 
00035 
00036 
00037 
00038 /* *******************************************************
00039  * $Id: AutoVMatrix.cc 8669 2008-03-12 18:00:10Z tihocan $
00040  * This file is part of the PLearn library.
00041  ******************************************************* */
00042 
00043 
00044 #include "AutoVMatrix.h"
00045 #include "MemoryVMatrix.h"
00046 #include <plearn/db/getDataSet.h>
00047 
00048 namespace PLearn {
00049 using namespace std;
00050 
00051 PLEARN_IMPLEMENT_OBJECT(AutoVMatrix,
00052                         "Automatically builds an appropriate VMat given a"
00053                         "filename.",
00054                         "AutoVMatrix tries to load the given 'filename'"
00055                         " (it will call getDataSet) and\n"
00056                         "will be a wrapper around the appropriate VMatrix"
00057                         " type, simply forwarding\n"
00058                         "calls to it.\n"
00059                         "Note that AutoVMatrix can NOT be used to access the"
00060                         " UCI databases anymore.\n"
00061                         "Consider using UCIDataVMatrix for that purpose.\n");
00062 
00063 AutoVMatrix::AutoVMatrix(const PPath& the_filename, bool load_in_memory)
00064     :filename(the_filename), load_data_in_memory(load_in_memory)
00065 { build_(); }
00066 
00067 void AutoVMatrix::declareOptions(OptionList& ol)
00068 {
00069     declareOption(ol, "specification", &AutoVMatrix::filename,
00070                   (OptionBase::learntoption | OptionBase::nosave),
00071                   "DEPRECATED - Use 'filename' instead.");
00072 
00073     declareOption(ol, "filename", &AutoVMatrix::filename,
00074                   OptionBase::buildoption,
00075                   "This is a file or directory path understood by getDataSet.\n"
00076                   + getDataSetHelp());
00077 
00078     declareOption(ol, "load_in_memory", &AutoVMatrix::load_data_in_memory,
00079                   OptionBase::buildoption,
00080                   "Specify if we want to store data in memory"
00081                   " (in a MemoryVMatrix).\n"
00082                   "Default=false.\n");
00083     // Now call the parent class' declareOptions
00084     inherited::declareOptions(ol);
00085 
00086     // Hide the 'vm' option, that is overwritten at build time anyway.
00087     redeclareOption(ol, "vm", &AutoVMatrix::vm, OptionBase::nosave, "");
00088 }
00089 
00090 void AutoVMatrix::build_()
00091 {
00092     if(filename.isEmpty())
00093         setVMat(VMat());
00094     else if (load_data_in_memory)
00095     {
00096         VMat data = getDataSet(filename);
00097         VMat memdata = new MemoryVMatrix(data);
00098         setVMat(memdata);
00099     }
00100     else
00101         setVMat(getDataSet(filename));
00102 }
00103 
00104 void AutoVMatrix::build()
00105 {
00106     inherited::build();
00107     build_();
00108 }
00109 
00111 // makeDeepCopyFromShallowCopy //
00113 void AutoVMatrix::makeDeepCopyFromShallowCopy(CopiesMap& copies) {
00114     inherited::makeDeepCopyFromShallowCopy(copies);
00115 }
00116 
00117 }
00118 
00119 
00120 /*
00121   Local Variables:
00122   mode:c++
00123   c-basic-offset:4
00124   c-file-style:"stroustrup"
00125   c-file-offsets:((innamespace . 0)(inline-open . 0))
00126   indent-tabs-mode:nil
00127   fill-column:79
00128   End:
00129 */
00130 // 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