PLearn 0.1
SplitWiseValidationVMatrix.cc
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // SplitWiseValidationVMatrix.cc
00004 //
00005 // Copyright (C) 2006 Hugo Larochelle
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 // Authors: Hugo Larochelle
00036 
00040 #include "SplitWiseValidationVMatrix.h"
00041 #include <plearn/db/getDataSet.h>
00042 #include <plearn/vmat/VMat.h>
00043 
00044 namespace PLearn {
00045 using namespace std;
00046 
00047 
00048 PLEARN_IMPLEMENT_OBJECT(
00049     SplitWiseValidationVMatrix,
00050     "VMatrix that takes several experiment split_stats.pmat to extract the split statistics and perform validation.",
00051     "It looks at the validation error, selects the best experiment\n"
00052     "and only report the associated statistics, for each split."
00053     );
00054 
00055 SplitWiseValidationVMatrix::SplitWiseValidationVMatrix()
00056     : validation_error_column(-1), add_column_average(false)
00057 {}
00058 
00059 void SplitWiseValidationVMatrix::getNewRow(int i, const Vec& v) const
00060 {
00061     v << data(i);
00062 }
00063 
00064 void SplitWiseValidationVMatrix::declareOptions(OptionList& ol)
00065 {
00066     declareOption(ol, "split_stats_ppaths", &SplitWiseValidationVMatrix::split_stats_ppaths,
00067                    OptionBase::buildoption,
00068                    "Help text describing this option");
00069     declareOption(ol, "validation_error_column", &SplitWiseValidationVMatrix::validation_error_column,
00070                   OptionBase::buildoption,
00071                   "Index of the validation error statistic column");
00072     declareOption(ol, "nsplits", &SplitWiseValidationVMatrix::nsplits,
00073                   OptionBase::buildoption,
00074                   "Number of splits to consider, starting from the first one.\n"
00075                   "If < 0, then all splits are considered (based on the number\n"
00076                   "of splits of the first expdir).");
00077     declareOption(ol, "add_column_average", &SplitWiseValidationVMatrix::add_column_average,
00078                   OptionBase::buildoption,
00079                   "Indication that the average of the columns should be added.");
00080 
00081     // Now call the parent class' declareOptions
00082     inherited::declareOptions(ol);
00083 }
00084 
00085 void SplitWiseValidationVMatrix::build_()
00086 {
00087     if(validation_error_column < 0)
00088         PLERROR("In SplitWiseValidationVMatrix::build_(): validation_error_column cannot be < 0");
00089     if(split_stats_ppaths.length() == 0)
00090         PLERROR("In SplitWiseValidationVMatrix::build_(): split_stats_ppaths is empty");
00091     TVec<Mat> stats(split_stats_ppaths.length());
00092     Mat stats_i;
00093     for(int i=0; i<stats.length(); i++)
00094     {
00095         VMat v = getDataSet(split_stats_ppaths[i]);
00096         updateMtime(v);
00097         stats_i = v->toMat();
00098         
00099         if(i==0)
00100         {
00101             if(nsplits<0) nsplits = stats_i.length();
00102             data.resize(nsplits,stats_i.width());
00103             data.fill(REAL_MAX);
00104         }
00105         if(stats_i.length() <nsplits)
00106         {
00107             PLWARNING("In SplitWiseValidationVMatrix::build_(): split_stats_ppaths[%d]=%s does not have enough splits, it will be ignored", i, split_stats_ppaths[i].c_str());
00108             continue;
00109         }
00110         for(int j=0; j<nsplits; j++)
00111         {
00112             if(data(j,validation_error_column) > stats_i(j,validation_error_column))
00113                 data(j) << stats_i(j);
00114         }
00115     }
00116     
00117     length_ = data.length();
00118     width_ = data.width();
00119     if(add_column_average)
00120     {
00121         data.resize(data.length()+1, data.width());
00122         data(data.length()-1).fill(0);
00123         length_++;
00124         for(int i=0; i<data.width(); i++)
00125         {
00126             for(int j=0; j<data.length()-1; j++)
00127                 data(data.length()-1,i) += data(j,i);
00128             data(data.length()-1,i) = data(data.length()-1,i)/(data.length()-1);
00129         }
00130     }
00131 }
00132 
00133 // ### Nothing to add here, simply calls build_
00134 void SplitWiseValidationVMatrix::build()
00135 {
00136     inherited::build();
00137     build_();
00138 }
00139 
00140 void SplitWiseValidationVMatrix::makeDeepCopyFromShallowCopy(CopiesMap& copies)
00141 {
00142     inherited::makeDeepCopyFromShallowCopy(copies);
00143 
00144     deepCopyField(split_stats_ppaths, copies);
00145     deepCopyField(data, copies);
00146 
00147     //PLERROR("SplitWiseValidationVMatrix::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!");
00148 }
00149 
00150 } // end of namespace PLearn
00151 
00152 
00153 /*
00154   Local Variables:
00155   mode:c++
00156   c-basic-offset:4
00157   c-file-style:"stroustrup"
00158   c-file-offsets:((innamespace . 0)(inline-open . 0))
00159   indent-tabs-mode:nil
00160   fill-column:79
00161   End:
00162 */
00163 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines