PLearn 0.1
TestImputations.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // TestImputations.h
00004 //
00005 // Copyright (C) 2006 Dan Popovici
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: Dan Popovici
00036 
00040 #ifndef TestImputations_INC
00041 #define TestImputations_INC
00042 
00043 #include <cstdarg>
00044 
00045 #include <plearn_learners/generic/PLearner.h>
00046 #include <plearn_learners/testers/PTester.h>
00047 #include <plearn/vmat/FileVMatrix.h>
00048 #include <plearn/vmat/MemoryVMatrix.h>
00049 #include <plearn/io/load_and_save.h>          
00050 #include <plearn/io/fileutils.h>              
00051 #include <plearn/math/random.h>               
00052 #include <plearn/vmat/ExplicitSplitter.h>     
00053 #include <plearn_learners/nearest_neighbors/BallTreeNearestNeighbors.h>
00054 #include <plearn_learners/nearest_neighbors/ExhaustiveNearestNeighbors.h>
00055 #include <plearn_learners/cgi/CovariancePreservationImputationVMatrix.h>
00056 #include <plearn_learners/cgi/NeighborhoodImputationVMatrix.h>
00057 #include <plearn_learners/cgi/WeightedDistance.h>
00058 
00059 namespace PLearn {
00060 
00065 class TestImputations : public PLearner
00066 {
00067     typedef PLearner inherited;
00068 
00069 public:
00070 
00071     //#####  Public Build Options  ############################################
00072 
00075     
00077     int min_number_of_samples;
00079     int max_number_of_samples;
00081     PPath mean_median_mode_file_name;
00083     PPath tree_conditional_mean_directory;
00085     PPath covariance_preservation_file_name;
00087     VMat reference_set_with_covpres;
00089     VMat reference_set_with_missing;
00091     TVec<string> missing_indicators;
00092     
00093 public:
00094     //#####  Public Member Functions  #########################################
00095 
00097     // ### Make sure the implementation in the .cc
00098     // ### initializes all fields to reasonable default values.
00099     TestImputations();
00100     int outputsize() const;
00101     void train();
00102     void computeOutput(const Vec&, Vec&) const;
00103     void computeCostsFromOutputs(const Vec&, const Vec&, const Vec&, Vec&) const;
00104     TVec<string> getTestCostNames() const;
00105     TVec<string> getTrainCostNames() const;
00106 
00107 
00108     //#####  PLearn::Object Protocol  #########################################
00109 
00110     // Declares other standard object methods.
00111     // ### If your class is not instantiatable (it has pure virtual methods)
00112     // ### you should replace this by PLEARN_DECLARE_ABSTRACT_OBJECT_METHODS
00113     PLEARN_DECLARE_OBJECT(TestImputations);
00114 
00115     // Simply calls inherited::build() then build_()
00116     virtual void build();
00117 
00119     // (PLEASE IMPLEMENT IN .cc)
00120     virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies);    
00121 
00122 protected:
00123     //#####  Protected Member Functions  ######################################
00124 
00126     static void declareOptions(OptionList& ol);
00127 
00128 private:
00129     //#####  Private Member Functions  ########################################
00130 
00132     void build_();
00133     void build_ball_tree(int nb_neighbors);
00134     void initialize();
00135     void computeMeanMedianModeStats();
00136     void computeTreeCondMeanStats();
00137     void computeCovPresStats();
00138     real covariancePreservationValue(int col);
00139     void computeNeighborhoodStats(int nb_neighbors,int max_miss_neigbors);
00140     void createHeaderFile();
00141     void getHeaderRecord();
00142     void updateHeaderRecord(int var_col);
00143     void createOutputFile();
00144     void getOutputRecord(int var_col);
00145     void updateOutputRecord(int var_col);
00146     void endtestimputation(const char* msg, ...);
00147 private:
00148     //#####  Private Data Members  ############################################
00149 
00150     // The rest of the private stuff goes here
00151     ExhaustiveNearestNeighbors* ball_tree;
00152     Mat ref_cov;
00153     Mat ref_mis;
00154     int train_length;
00155     int train_width;
00156     Vec train_input;
00157     TVec<string> train_names;
00158     PPath train_metadata;
00159     StatsCollector train_stats;
00160     int train_total;
00161     int train_missing;
00162     int train_present;
00163     PPath header_file_name;
00164     VMat header_file;
00165     Vec header_record;
00166     int to_deal_with_total;
00167     int to_deal_with_next;
00168     string to_deal_with_name;
00169     real to_deal_with_value;
00170     VMat test_samples_set;
00171     TVec<int> indices;
00172     int test_length;
00173     int test_width;
00174     real mmmf_mean_err;
00175     real mmmf_median_err;
00176     real mmmf_mode_err;
00177     PPath tcmf_file_name;
00178     VMat tcmf_file;
00179     real tcmf_mean_err;
00180     Mat cvpf_cov;
00181     Vec cvpf_mu;
00182     real cvpf_mean_err;
00183     Vec knnf_input;
00184     Vec knnf_neighbors;
00185     Vec knnf_mean_cov_err;
00186     Vec knnf_mean_miss_err;
00187     Vec knnf_nmiss_value_count;
00188     Vec weights;
00189     WeightedDistance* weighted_distance_kernel;
00190     PPath output_file_name;
00191     VMat output_file;
00192     Vec output_record;
00193     TVec<string> output_names;
00194 };
00195 
00196 // Declares a few other classes and functions related to this class
00197 DECLARE_OBJECT_PTR(TestImputations);
00198 
00199 } // end of namespace PLearn
00200 
00201 #endif
00202 
00203 
00204 /*
00205   Local Variables:
00206   mode:c++
00207   c-basic-offset:4
00208   c-file-style:"stroustrup"
00209   c-file-offsets:((innamespace . 0)(inline-open . 0))
00210   indent-tabs-mode:nil
00211   fill-column:79
00212   End:
00213 */
00214 // 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