Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

BootstrapSplitter.cc

Go to the documentation of this file.
00001 // -*- C++ -*- 00002 00003 // BootstrapSplitter.cc 00004 // 00005 // Copyright (C) 2003 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: BootstrapSplitter.cc,v 1.3 2004/04/05 22:47:08 morinf Exp $ 00037 ******************************************************* */ 00038 00041 #include "BootstrapSplitter.h" 00042 #include "BootstrapVMatrix.h" 00043 00044 namespace PLearn { 00045 using namespace std; 00046 00047 BootstrapSplitter::BootstrapSplitter() 00048 :Splitter(), 00049 frac(0.6667), 00050 n_splits(0) 00051 /* ### Initialise all fields to their default value */ 00052 { 00053 } 00054 00055 PLEARN_IMPLEMENT_OBJECT(BootstrapSplitter, 00056 "A splitter whose splits are bootstrap samples of the original dataset", 00057 "BootstrapSplitter implements a ..."); 00058 00059 void BootstrapSplitter::declareOptions(OptionList& ol) 00060 { 00061 // ### Declare all of this object's options here 00062 // ### For the "flags" of each option, you should typically specify 00063 // ### one of OptionBase::buildoption, OptionBase::learntoption or 00064 // ### OptionBase::tuningoption. Another possible flag to be combined with 00065 // ### is OptionBase::nosave 00066 00067 declareOption(ol, "n_splits", &BootstrapSplitter::n_splits, OptionBase::buildoption, 00068 "the number of splits wanted"); 00069 00070 declareOption(ol, "frac", &BootstrapSplitter::frac, OptionBase::buildoption, 00071 "the fraction of elements to take in each bootstrap"); 00072 00073 // Now call the parent class' declareOptions 00074 inherited::declareOptions(ol); 00075 } 00076 00077 void BootstrapSplitter::build_() 00078 { 00079 // ### This method should do the real building of the object, 00080 // ### according to set 'options', in *any* situation. 00081 // ### Typical situations include: 00082 // ### - Initial building of an object from a few user-specified options 00083 // ### - Building of a "reloaded" object: i.e. from the complete set of all serialised options. 00084 // ### - Updating or "re-building" of an object after a few "tuning" options have been modified. 00085 // ### You should assume that the parent class' build_() has already been called. 00086 if (dataset) { 00087 bootstrapped_sets.resize(0,0); // First clear the current sets. 00088 bootstrapped_sets.resize(n_splits,1); 00089 for (int i = 0; i < n_splits; i++) { 00090 // Construct a new bootstrap sample from the dataset. 00091 bootstrapped_sets(i,0) = new BootstrapVMatrix(dataset,frac); 00092 } 00093 } else { 00094 bootstrapped_sets.resize(0,0); 00095 } 00096 } 00097 00098 // ### Nothing to add here, simply calls build_ 00099 void BootstrapSplitter::build() 00100 { 00101 inherited::build(); 00102 build_(); 00103 } 00104 00105 void BootstrapSplitter::makeDeepCopyFromShallowCopy(map<const void*, void*>& copies) 00106 { 00107 Splitter::makeDeepCopyFromShallowCopy(copies); 00108 00109 // ### Call deepCopyField on all "pointer-like" fields 00110 // ### that you wish to be deepCopied rather than 00111 // ### shallow-copied. 00112 // ### ex: 00113 // deepCopyField(trainvec, copies); 00114 00115 // ### Remove this line when you have fully implemented this method. 00116 PLERROR("BootstrapSplitter::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!"); 00117 } 00118 00119 int BootstrapSplitter::nsplits() const 00120 { 00121 // ### Return the number of available splits 00122 return n_splits; 00123 } 00124 00125 int BootstrapSplitter::nSetsPerSplit() const 00126 { 00127 // ### Return the number of sets per split 00128 return 1; 00129 } 00130 00131 TVec<VMat> BootstrapSplitter::getSplit(int k) 00132 { 00133 // ### Build and return the kth split 00134 if (k >= n_splits) { 00135 PLERROR("BootstrapSplitter::getSplit: k is too high"); 00136 } else if (k >= bootstrapped_sets.length()) { 00137 PLERROR("BootstrapSplitter::getSplit: you asked for a split but they're not ready yet"); 00138 } 00139 return bootstrapped_sets(k); 00140 } 00141 00143 // setDataSet // 00145 void BootstrapSplitter::setDataSet(VMat the_dataset) { 00146 inherited::setDataSet(the_dataset); 00147 build(); // necessary to recompute the bootstrap samples. 00148 } 00149 00150 } // end of namespace PLearn

Generated on Tue Aug 17 15:49:02 2004 for PLearn by doxygen 1.3.7