PLearn 0.1
|
00001 // -*- C++ -*- 00002 00003 // ShuffleColumnsVMatrix.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: ShuffleColumnsVMatrix.cc 8617 2008-03-03 17:45:54Z nouiz $ 00037 ******************************************************* */ 00038 00039 // Authors: Olivier Delalleau 00040 00044 #include "ShuffleColumnsVMatrix.h" 00045 #include <plearn/math/random.h> 00046 00047 namespace PLearn { 00048 using namespace std; 00049 00051 // ShuffleColumnsVMatrix // 00053 ShuffleColumnsVMatrix::ShuffleColumnsVMatrix() 00054 : only_shuffle_inputs(true), 00055 seed(0) 00056 {} 00057 00058 PLEARN_IMPLEMENT_OBJECT(ShuffleColumnsVMatrix, 00059 "Shuffle the columns of its source VMatrix.", 00060 "" 00061 ); 00062 00064 // declareOptions // 00066 void ShuffleColumnsVMatrix::declareOptions(OptionList& ol) 00067 { 00068 // ### Declare all of this object's options here 00069 // ### For the "flags" of each option, you should typically specify 00070 // ### one of OptionBase::buildoption, OptionBase::learntoption or 00071 // ### OptionBase::tuningoption. Another possible flag to be combined with 00072 // ### is OptionBase::nosave 00073 00074 declareOption(ol, "only_shuffle_inputs", &ShuffleColumnsVMatrix::only_shuffle_inputs, OptionBase::buildoption, 00075 "Whether we should only shuffle the input part, or also shuffle the target and weight parts."); 00076 00077 declareOption(ol, "seed", &ShuffleColumnsVMatrix::seed, OptionBase::buildoption, 00078 "The random generator seed (-1 = initialized from clock, 0 = no initialization)."); 00079 00080 // Now call the parent class' declareOptions 00081 inherited::declareOptions(ol); 00082 } 00083 00085 // build // 00087 void ShuffleColumnsVMatrix::build() 00088 { 00089 // ### Nothing to add here, simply calls build_ 00090 inherited::build(); 00091 build_(); 00092 } 00093 00095 // build_ // 00097 void ShuffleColumnsVMatrix::build_() 00098 { 00099 if (source) { 00100 updateMtime(source); 00101 int n_shuffle = source->width(); 00102 if (only_shuffle_inputs) { 00103 if (source->inputsize() < 0) 00104 PLERROR("In ShuffleColumnsVMatrix::build_ - Cannot find out the source inputsize"); 00105 n_shuffle = source->inputsize(); 00106 } 00107 indices = TVec<int>(0, n_shuffle - 1, 1); 00108 if (seed == -1) 00109 PLearn::seed(); 00110 else if (seed > 0) 00111 manual_seed(seed); 00112 else if (seed != 0) 00113 PLERROR("In ShuffleColumnsVMatrix::build_ - The seed must be either -1 or >= 0"); 00114 shuffleElements(indices); 00115 for (int i = 0; i < source->width() - n_shuffle; i++) { 00116 indices.append(i + n_shuffle); 00117 } 00118 } 00119 inherited::build(); 00120 } 00121 00123 // makeDeepCopyFromShallowCopy // 00125 void ShuffleColumnsVMatrix::makeDeepCopyFromShallowCopy(CopiesMap& copies) 00126 { 00127 inherited::makeDeepCopyFromShallowCopy(copies); 00128 00129 // ### Call deepCopyField on all "pointer-like" fields 00130 // ### that you wish to be deepCopied rather than 00131 // ### shallow-copied. 00132 // ### ex: 00133 // deepCopyField(trainvec, copies); 00134 00135 // ### Remove this line when you have fully implemented this method. 00136 PLERROR("ShuffleColumnsVMatrix::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!"); 00137 } 00138 00139 } // end of namespace PLearn 00140 00141 00142 /* 00143 Local Variables: 00144 mode:c++ 00145 c-basic-offset:4 00146 c-file-style:"stroustrup" 00147 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00148 indent-tabs-mode:nil 00149 fill-column:79 00150 End: 00151 */ 00152 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :