PLearn 0.1
SourceVMatrixSplitter.cc
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // SourceVMatrixSplitter.cc
00004 //
00005 // Copyright (C) 2004 Olivier Delalleau
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  * $Id: SourceVMatrixSplitter.cc 6861 2007-04-09 19:04:15Z saintmlx $
00037  ******************************************************* */
00038 
00039 // Authors: Olivier Delalleau
00040 
00044 #include "SourceVMatrixSplitter.h"
00045 
00046 namespace PLearn {
00047 using namespace std;
00048 
00050 // SourceVMatrixSplitter //
00052 SourceVMatrixSplitter::SourceVMatrixSplitter()
00053     : to_apply(0)
00054 {
00055 }
00056 
00057 PLEARN_IMPLEMENT_OBJECT(SourceVMatrixSplitter,
00058                         "Returns the splits of an underlying splitter, seen by a SourceVMatrix.",
00059                         "Not all sets have to be modified: the 'sets_to_modify' option allows one\n"
00060                         "to choose on which sets we apply the SourceVMatrix, which will be deep-copied\n"
00061                         "on each set.\n"
00062                         "Note that the provided SourceVMatrix may be modified in the process.\n"
00063     );
00064 
00066 // declareOptions //
00068 void SourceVMatrixSplitter::declareOptions(OptionList& ol)
00069 {
00070     declareOption(ol, "source_vm", &SourceVMatrixSplitter::source_vm, OptionBase::buildoption,
00071                   "The VMatrix to apply.");
00072 
00073     declareOption(ol, "source_splitter", &SourceVMatrixSplitter::source_splitter, OptionBase::buildoption,
00074                   "The underlying splitter.");
00075 
00076     declareOption(ol, "to_apply", &SourceVMatrixSplitter::to_apply, OptionBase::buildoption,
00077                   "Deprecated: the index of the returned set where we apply source_vm.");
00078 
00079     declareOption(ol, "sets_to_modify", &SourceVMatrixSplitter::sets_to_modify, OptionBase::buildoption,
00080                   "The indices of the returned sets on which we apply source_vm ([-1] means all sets).\n"
00081                   "This option will override 'to_apply' if it is also provided.");
00082 
00083     // Now call the parent class' declareOptions
00084     inherited::declareOptions(ol);
00085 }
00086 
00088 // build_ //
00090 void SourceVMatrixSplitter::build_()
00091 {
00092     if (to_apply != 0)
00093         // This deprecated option is being used.
00094         PLDEPRECATED("In SourceVMatrixSplitter::build_ - Use 'sets_to_modify' instead of the deprecated "
00095                      "'to_apply' option.");
00096 }
00097 
00099 // build //
00101 void SourceVMatrixSplitter::build()
00102 {
00103     inherited::build();
00104     build_();
00105 }
00106 
00108 // makeDeepCopyFromShallowCopy //
00110 void SourceVMatrixSplitter::makeDeepCopyFromShallowCopy(CopiesMap& copies)
00111 {
00112     inherited::makeDeepCopyFromShallowCopy(copies);
00113 
00114     // ### Call deepCopyField on all "pointer-like" fields
00115     // ### that you wish to be deepCopied rather than
00116     // ### shallow-copied.
00117     // ### ex:
00118     // deepCopyField(trainvec, copies);
00119 
00120     // ### Remove this line when you have fully implemented this method.
00121     PLERROR("SourceVMatrixSplitter::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!");
00122 }
00123 
00125 // nsplits //
00127 int SourceVMatrixSplitter::nsplits() const
00128 {
00129     return source_splitter->nsplits();
00130 }
00131 
00133 // nSetsPerSplit //
00135 int SourceVMatrixSplitter::nSetsPerSplit() const
00136 {
00137     return source_splitter->nSetsPerSplit();
00138 }
00139 
00141 // getSplit //
00143 TVec<VMat> SourceVMatrixSplitter::getSplit(int k)
00144 {
00145     TVec<VMat> result = source_splitter->getSplit(k);
00146     if (sets_to_modify.isEmpty()) {
00147         // Old code, to remove when the deprecated option 'to_apply' is removed.
00148         PLDEPRECATED("In SourceVMatrixSplitter::getSplit - Use 'sets_to_modify' instead of the deprecated "
00149                      "'to_apply' option.");
00150         source_vm->source = result[to_apply];
00151         source_vm->build();
00152         VMat the_vm = static_cast<SourceVMatrix*>(source_vm);
00153         result[to_apply] = the_vm;
00154     } else {
00155         TVec<int> sets_indices = sets_to_modify;
00156         if (sets_indices.length() == 1 && sets_indices[0] == -1) {
00157             // -1 means we apply it on all sets.
00158             sets_indices = TVec<int>(0, source_splitter->nSetsPerSplit() - 1, 1);
00159         }
00160         for (int i = 0; i < sets_indices.length(); i++) {
00161             int set = sets_indices[i];
00162             // Clear the source of 'source_vm' since we do not want to deep-copy it.
00163             source_vm->source = 0;
00164             // Copy 'source_vm' and fill 'result' accordingly.
00165             PP<SourceVMatrix> vm_copy = PLearn::deepCopy(source_vm);
00166             vm_copy->source = result[set];
00167             vm_copy->build();
00168             result[set] = (SourceVMatrix*) vm_copy;
00169         }
00170     }
00171     return result;
00172 }
00173 
00175 // setDataSet //
00177 void SourceVMatrixSplitter::setDataSet(VMat the_dataset) {
00178     inherited::setDataSet(the_dataset);
00179     source_splitter->setDataSet(the_dataset);
00180 }
00181 
00182 } // end of namespace PLearn
00183 
00184 
00185 /*
00186   Local Variables:
00187   mode:c++
00188   c-basic-offset:4
00189   c-file-style:"stroustrup"
00190   c-file-offsets:((innamespace . 0)(inline-open . 0))
00191   indent-tabs-mode:nil
00192   fill-column:79
00193   End:
00194 */
00195 // 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