PLearn 0.1
NeighborhoodConditionalMean.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // NeighborhoodConditionalMean.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 NeighborhoodConditionalMean_INC
00041 #define NeighborhoodConditionalMean_INC
00042 
00043 #include <plearn_learners/generic/PLearner.h>
00044 #include <plearn_learners/testers/PTester.h>
00045 #include <plearn/vmat/FileVMatrix.h>
00046 #include <plearn/vmat/MemoryVMatrix.h>
00047 #include <plearn/io/load_and_save.h>          
00048 #include <plearn/io/fileutils.h>              
00049 #include <plearn/math/random.h>               
00050 #include <plearn/vmat/ExplicitSplitter.h>     
00051 #include <plearn_learners/nearest_neighbors/BallTreeNearestNeighbors.h>
00052 #include <plearn_learners/second_iteration/CovariancePreservationImputationVMatrix.h>
00053 #include <plearn_learners/second_iteration/NeighborhoodImputationVMatrix.h>
00054 #include <plearn_learners/second_iteration/Experimentation.h>
00055 
00056 namespace PLearn {
00057 
00062 class NeighborhoodConditionalMean : public PLearner
00063 {
00064     typedef PLearner inherited;
00065 
00066 public:
00067 
00068     //#####  Public Build Options  ############################################
00069 
00072     
00074     VMat test_train_input_set;
00076     VMat test_train_target_set;
00078     int number_of_test_samples;
00080     int number_of_train_samples;
00082     TVec<string> target_field_names;
00083     PPath train_covariance_file_name;
00084     PPath test_train_covariance_file_name;    
00086     TVec<int> various_ks;
00088     Vec deletion_thresholds;
00090     string experiment_name;
00092     TVec< string > missing_indicator_field_names;
00094     PP< PTester > experiment_template;
00095 
00096 public:
00097     //#####  Public Member Functions  #########################################
00098 
00100     // ### Make sure the implementation in the .cc
00101     // ### initializes all fields to reasonable default values.
00102     NeighborhoodConditionalMean();
00103     int outputsize() const;
00104     void train();
00105     void computeOutput(const Vec&, Vec&) const;
00106     void computeCostsFromOutputs(const Vec&, const Vec&, const Vec&, Vec&) const;
00107     TVec<string> getTestCostNames() const;
00108     TVec<string> getTrainCostNames() const;
00109 
00110 
00111     //#####  PLearn::Object Protocol  #########################################
00112 
00113     // Declares other standard object methods.
00114     // ### If your class is not instantiatable (it has pure virtual methods)
00115     // ### you should replace this by PLEARN_DECLARE_ABSTRACT_OBJECT_METHODS
00116     PLEARN_DECLARE_OBJECT(NeighborhoodConditionalMean);
00117 
00118     // Simply calls inherited::build() then build_()
00119     virtual void build();
00120 
00122     // (PLEASE IMPLEMENT IN .cc)
00123     virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies);    
00124 
00125 protected:
00126     //#####  Protected Member Functions  ######################################
00127 
00129     static void declareOptions(OptionList& ol);
00130 
00131 private:
00132     //#####  Private Member Functions  ########################################
00133 
00135     void build_();
00136     void computeNeighborhood();
00137     void experimentWithVariousKs();
00138     void createMasterHeaderFile();
00139     void getMasterHeaderRecords();
00140     void updateMasterHeaderRecords(int row, int col);
00141 
00142 private:
00143     //#####  Private Data Members  ############################################
00144 
00145     // The rest of the private stuff goes here
00146     ProgressBar*                              pb;
00147     VMat                                      train_covariance_file;
00148     CovariancePreservationImputationVMatrix*  train_covariance_vmatrix;
00149     VMat                                      train_covariance_vmat;
00150     Vec                                       train_covariance_vector;
00151     VMat                                      test_train_covariance_file;
00152     CovariancePreservationImputationVMatrix*  test_train_covariance_vmatrix;
00153     VMat                                      test_train_covariance_vmat;
00154     Vec                                       test_train_covariance_vector;
00155     PPath                                     test_train_neighborhood_file_name;
00156     BallTreeNearestNeighbors*                 test_train_neighborhood_learner;
00157     VMat                                      test_train_neighborhood_file;
00158     Vec                                       test_train_neighborhood_vector;
00159     PPath                                     master_header_file_name;
00160     VMat                                      master_header_file;
00161     int                                       master_header_length;
00162     int                                       master_header_width;
00163     int                                       master_header_row;
00164     int                                       master_header_col;
00165     TVec<string>                              master_header_names;
00166     Mat                                       master_header_records;
00167     int                                       to_deal_with_k;
00168     string                                    to_deal_with_target;
00169     int                                       to_deal_with_ind;
00170     NeighborhoodImputationVMatrix*            test_train_neighbor_imputation_vmatrix;
00171     VMat                                      test_train_neighbor_imputation_vmat;
00172     VMat                                      test_train_neighbor_imputation_file;
00173     Vec                                       test_train_neighbor_imputation_vector;
00174     Experimentation*                          experimentation_learner;
00175     
00176  /*   
00177     int main_row;
00178     int main_col;
00179     int main_length;
00180     int main_width;
00181     Vec main_input;
00182     TVec<string> main_names;
00183     StatsCollector  main_stats;
00184     PPath main_metadata;
00185     TVec<int> main_ins;
00186     real main_total;
00187     real main_missing;
00188     real main_present;
00189     int targeted_length;
00190     int targeted_width;
00191     Vec targeted_input;
00192     TVec<string> targeted_names;
00193     StatsCollector  targeted_stats;
00194     PPath targeted_metadata;
00195     real targeted_missing;
00196     PPath header_file_name;
00197     VMat header_file;
00198     Vec header_record;
00199     int fields_col;
00200     int fields_width;
00201     TVec<int> fields_selected;
00202     int to_deal_with_total;
00203     int to_deal_with_next;
00204     real to_deal_with_value;
00205     string to_deal_with_name;
00206     int ind_next;
00207     int output_length;
00208     int output_width;
00209     int output_col;
00210     string output_path;
00211     TVec<string> output_names;
00212     Vec output_vec;
00213     TVec<int> output_variable_src;
00214     VMat output_file;
00215     int train_test_length;
00216     string train_test_path;
00217     TVec<int> train_test_variable_src;
00218     VMat train_test_file;
00219     PP<PTester> cond_mean;
00220     PPath results_file_name;
00221     VMat results_file;
00222     int results_length;
00223     real results_nstages;
00224     real results_mse;
00225     real results_std_err;
00226     PPath test_output_file_name;
00227     VMat test_output_file;
00228     int test_output_length;
00229 */    
00230 };
00231 
00232 // Declares a few other classes and functions related to this class
00233 DECLARE_OBJECT_PTR(NeighborhoodConditionalMean);
00234 
00235 } // end of namespace PLearn
00236 
00237 #endif
00238 
00239 
00240 /*
00241   Local Variables:
00242   mode:c++
00243   c-basic-offset:4
00244   c-file-style:"stroustrup"
00245   c-file-offsets:((innamespace . 0)(inline-open . 0))
00246   indent-tabs-mode:nil
00247   fill-column:79
00248   End:
00249 */
00250 // 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