PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // BinSplitter.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: BinSplitter.cc 6861 2007-04-09 19:04:15Z saintmlx $ 00037 ******************************************************* */ 00038 00039 // Authors: Olivier Delalleau 00040 00044 #include "BinSplitter.h" 00045 #include <plearn/vmat/SelectRowsVMatrix.h> 00046 00047 namespace PLearn { 00048 using namespace std; 00049 00051 // BinSplitter // 00053 BinSplitter::BinSplitter() 00054 : column(0), 00055 column_spec("") 00056 { 00057 } 00058 00059 PLEARN_IMPLEMENT_OBJECT(BinSplitter, 00060 "Split a dataset into bins given by a Binner object.", 00061 "" 00062 ); 00063 00065 // declareOptions // 00067 void BinSplitter::declareOptions(OptionList& ol) 00068 { 00069 declareOption(ol, "binner", &BinSplitter::binner, OptionBase::buildoption, 00070 "The binner used to create the bins."); 00071 00072 declareOption(ol, "column", &BinSplitter::column, OptionBase::buildoption, 00073 "The column used to defined the bins."); 00074 00075 declareOption(ol, "column_spec", &BinSplitter::column_spec, OptionBase::buildoption, 00076 "Alternatively, this option can be used to override the 'column' option:\n" 00077 " - 'first_input' : the first input column\n" 00078 " - 'last_input' : the last input column\n" 00079 " - 'first_target': the first target column\n" 00080 " - 'last_target' : the last target column"); 00081 00082 // Now call the parent class' declareOptions 00083 inherited::declareOptions(ol); 00084 } 00085 00087 // build_ // 00089 void BinSplitter::build_() 00090 { 00091 } 00092 00094 // build // 00096 void BinSplitter::build() 00097 { 00098 inherited::build(); 00099 build_(); 00100 } 00101 00102 void BinSplitter::makeDeepCopyFromShallowCopy(CopiesMap& copies) 00103 { 00104 inherited::makeDeepCopyFromShallowCopy(copies); 00105 00106 // ### Call deepCopyField on all "pointer-like" fields 00107 // ### that you wish to be deepCopied rather than 00108 // ### shallow-copied. 00109 // ### ex: 00110 // deepCopyField(trainvec, copies); 00111 00112 // ### Remove this line when you have fully implemented this method. 00113 PLERROR("BinSplitter::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!"); 00114 } 00115 00117 // nsplits // 00119 int BinSplitter::nsplits() const 00120 { 00121 return 1; 00122 } 00123 00125 // nSetsPerSplit // 00127 int BinSplitter::nSetsPerSplit() const 00128 { 00129 return binner->nBins(); 00130 } 00131 00133 // getSplit // 00135 TVec<VMat> BinSplitter::getSplit(int k) 00136 { 00137 TVec<VMat> sets(nSetsPerSplit()); 00138 for (int i = 0; i < sets.length(); i++) { 00139 sets[i] = new SelectRowsVMatrix(dataset, bins[i]); 00140 } 00141 return sets; 00142 } 00143 00145 // setDataSet // 00147 void BinSplitter::setDataSet(VMat the_dataset) { 00148 inherited::setDataSet(the_dataset); 00149 int col = column; 00150 if (column_spec != "") { 00151 if (column_spec == "first_input") 00152 col = 0; 00153 else if (column_spec == "last_input") 00154 col = the_dataset->inputsize() - 1; 00155 else if (column_spec == "first_target") 00156 col = the_dataset->inputsize(); 00157 else if (column_spec == "last_target") 00158 col = the_dataset->inputsize() + the_dataset->targetsize() - 1; 00159 else 00160 PLERROR("In BinSplitter::setDataSet - Wrong value for 'column_spec'"); 00161 if (col < 0) 00162 PLERROR("In BinSplitter::setDataSet - Found a negative column, check the dataset sizes are correctly defined"); 00163 } 00164 else if (column >= the_dataset->width()) 00165 PLERROR("In BinSplitter::setDataSet - The column number is higher than available"); 00166 Vec col_vec = the_dataset.column(col)->toMat().toVec(); 00167 if (!binner) 00168 PLERROR("In BinSplitter::setDataSet - You must provide a binner first."); 00169 bins = binner->getBins(col_vec); 00170 } 00171 00172 } // end of namespace PLearn 00173 00174 00175 /* 00176 Local Variables: 00177 mode:c++ 00178 c-basic-offset:4 00179 c-file-style:"stroustrup" 00180 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00181 indent-tabs-mode:nil 00182 fill-column:79 00183 End: 00184 */ 00185 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :