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

SequentialSplitter.cc

Go to the documentation of this file.
00001 // -*- C++ -*- 00002 00003 // SequentialSplitter.cc 00004 // 00005 // Copyright (C) 1998 Pascal Vincent 00006 // Copyright (C) 1999,2000 Pascal Vincent, Yoshua Bengio and University of Montreal 00007 // Copyright (C) 2002 Frederic Morin 00008 // Copyright (C) 2004 Rejean Ducharme 00009 // 00010 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are met: 00012 // 00013 // 1. Redistributions of source code must retain the above copyright 00014 // notice, this list of conditions and the following disclaimer. 00015 // 00016 // 2. Redistributions in binary form must reproduce the above copyright 00017 // notice, this list of conditions and the following disclaimer in the 00018 // documentation and/or other materials provided with the distribution. 00019 // 00020 // 3. The name of the authors may not be used to endorse or promote 00021 // products derived from this software without specific prior written 00022 // permission. 00023 // 00024 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00025 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00026 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00027 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00028 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00029 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00030 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00031 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00032 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00033 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 // 00035 // This file is part of the PLearn library. For more information on the PLearn 00036 // library, go to the PLearn Web site at www.plearn.org 00037 00038 /* ******************************************************* 00039 * $Id: SequentialSplitter.cc,v 1.7 2004/05/06 21:22:12 ducharme Exp $ 00040 ******************************************************* */ 00041 00043 #include "SequentialSplitter.h" 00044 00045 namespace PLearn { 00046 using namespace std; 00047 00048 SequentialSplitter::SequentialSplitter(int horizon_, int init_train_size_, bool return_entire_vmat_) 00049 : horizon(horizon_), init_train_size(init_train_size_), return_entire_vmat(return_entire_vmat_) 00050 {} 00051 00052 PLEARN_IMPLEMENT_OBJECT(SequentialSplitter, "ONE LINE DESCR", 00053 "SequentialSplitter implements several splits, TODO: Comments"); 00054 00055 void SequentialSplitter::declareOptions(OptionList& ol) 00056 { 00057 declareOption(ol, "horizon", &SequentialSplitter::horizon, OptionBase::buildoption, 00058 "How far in the future is the test set (split[1])"); 00059 00060 declareOption(ol, "init_train_size", &SequentialSplitter::init_train_size, OptionBase::buildoption, 00061 "Initial length of the train set (split[0])"); 00062 00063 declareOption(ol, "return_entire_vmat", &SequentialSplitter::return_entire_vmat, OptionBase::buildoption, 00064 "If true, the test split (split[1]) will start at t=0."); 00065 00066 inherited::declareOptions(ol); 00067 } 00068 00069 void SequentialSplitter::build_() 00070 { 00071 } 00072 00073 // ### Nothing to add here, simply calls build_ 00074 void SequentialSplitter::build() 00075 { 00076 inherited::build(); 00077 build_(); 00078 } 00079 00080 int SequentialSplitter::nSetsPerSplit() const 00081 { 00082 return 2; 00083 } 00084 00085 int SequentialSplitter::nsplits() const 00086 { 00087 if (dataset.isNull()) 00088 PLERROR("SequentialSplitter::nsplits() - Must call setDataSet()"); 00089 if (init_train_size < 1) 00090 PLERROR("SequentialSplitter::nsplits() - init_train_size must be stricktly positive (%d)", init_train_size); 00091 if (horizon < 1) 00092 PLERROR("SequentialSplitter::nsplits() - horizon must be stricktly positive (%d)", horizon); 00093 00094 return dataset.length() - init_train_size - horizon + 1; 00095 } 00096 00097 TVec<VMat> SequentialSplitter::getSplit(int k) 00098 { 00099 if (dataset.isNull()) 00100 PLERROR("SequentialSplitter::getSplit() - Must call setDataSet()"); 00101 00102 int n_splits = nsplits(); 00103 if (k >= n_splits) 00104 PLERROR("SequentialSplitter::getSplit() - k (%d) cannot be greater than K (%d)", k, n_splits); 00105 00106 int seq_length = dataset.length(); 00107 if (init_train_size >= seq_length) 00108 PLERROR("SequentialSplitter::getSplit() - init_train_size (%d) >= dataset.length() (%d)", init_train_size, seq_length); 00109 00110 int t = init_train_size + k; 00111 int start_test_t = return_entire_vmat ? 0 : t; 00112 int n_test = t + horizon - start_test_t; 00113 00114 TVec<VMat> split_(2); 00115 split_[0] = dataset.subMatRows(0, t); 00116 split_[1] = dataset.subMatRows(start_test_t, n_test); 00117 00118 return split_; 00119 } 00120 00121 00122 } // end of namespace PLearn

Generated on Tue Aug 17 16:05:26 2004 for PLearn by doxygen 1.3.7