PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // ConcatSetsSplitter.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: ConcatSetsSplitter.cc 8135 2007-10-03 16:59:53Z nouiz $ 00037 ******************************************************* */ 00038 00039 // Authors: Olivier Delalleau 00040 00044 #include "ConcatSetsSplitter.h" 00045 00046 namespace PLearn { 00047 using namespace std; 00048 00050 // ConcatSetsSplitter // 00052 ConcatSetsSplitter::ConcatSetsSplitter() 00053 { 00054 } 00055 00056 PLEARN_IMPLEMENT_OBJECT(ConcatSetsSplitter, 00057 "Concatenates the sets of many splitters.", 00058 "The concatenated splitters must have the same number of splits." 00059 ); 00060 00062 // declareOptions // 00064 void ConcatSetsSplitter::declareOptions(OptionList& ol) 00065 { 00066 declareOption(ol, "splitters", &ConcatSetsSplitter::splitters, OptionBase::buildoption, 00067 "The splitters whose sets we want to concatenate."); 00068 00069 // Now call the parent class' declareOptions 00070 inherited::declareOptions(ol); 00071 } 00072 00074 // build_ // 00076 void ConcatSetsSplitter::build_() 00077 { 00078 if (splitters.length() > 0) { 00079 int nsplits = splitters[0]->nsplits(); 00080 for (int i = 1; i < splitters.length(); i++) 00081 if (splitters[i]->nsplits() != nsplits) 00082 PLERROR("In ConcatSetsSplitter::build_ - All concatenated splitters must return the same number of splits"); 00083 } 00084 } 00085 00087 // build // 00089 void ConcatSetsSplitter::build() 00090 { 00091 inherited::build(); 00092 build_(); 00093 } 00094 00095 void ConcatSetsSplitter::makeDeepCopyFromShallowCopy(CopiesMap& copies) 00096 { 00097 inherited::makeDeepCopyFromShallowCopy(copies); 00098 deepCopyField(splitters, copies); 00099 00100 } 00101 00103 // nsplits // 00105 int ConcatSetsSplitter::nsplits() const 00106 { 00107 return splitters[0]->nsplits(); 00108 } 00109 00111 // nSetsPerSplit // 00113 int ConcatSetsSplitter::nSetsPerSplit() const 00114 { 00115 int count = 0; 00116 for (int i = 0; i < splitters.length(); i++) 00117 count += splitters[i]->nSetsPerSplit(); 00118 return count; 00119 } 00120 00122 // getSplit // 00124 TVec<VMat> ConcatSetsSplitter::getSplit(int k) 00125 { 00126 TVec<VMat> sets; 00127 for (int i = 0; i < splitters.length(); i++) { 00128 sets.append(splitters[i]->getSplit(k)); 00129 } 00130 return sets; 00131 } 00132 00134 // setDataSet // 00136 void ConcatSetsSplitter::setDataSet(VMat the_dataset) { 00137 inherited::setDataSet(the_dataset); 00138 for (int i = 0; i < splitters.length(); i++) { 00139 splitters[i]->setDataSet(the_dataset); 00140 } 00141 } 00142 00143 } // end of namespace PLearn 00144 00145 00146 /* 00147 Local Variables: 00148 mode:c++ 00149 c-basic-offset:4 00150 c-file-style:"stroustrup" 00151 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00152 indent-tabs-mode:nil 00153 fill-column:79 00154 End: 00155 */ 00156 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :