PLearn 0.1
NormalizationLearner.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // NormalizationLearner.h
00004 //
00005 // Copyright (C) 2006 Pascal Vincent
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: Pascal Vincent
00036 
00040 #ifndef NormalizationLearner_INC
00041 #define NormalizationLearner_INC
00042 
00043 #include <plearn_learners/generic/PLearner.h>
00044 
00045 namespace PLearn {
00046 
00057 class NormalizationLearner : public PLearner
00058 {
00059     typedef PLearner inherited;
00060 
00061 public:
00062     //#####  Public Options  ############################################
00063 
00066 
00067     // Build options
00068     real min_allowed_stddev;
00069     double remove_components_with_stddev_smaller_than;
00070     double remove_components_whose_missing_proportion_exceeds;
00071     bool set_missing_to_zero;
00072     bool do_normalize;
00073 
00074     // Learnt option
00075     Vec meanvec;
00076     Vec inv_stddev;
00077     TVec<string> inputnames;
00078     TVec<int> kept_components;
00079 
00080 public:
00081     //#####  Public Member Functions  #########################################
00082 
00084     // ### Make sure the implementation in the .cc
00085     // ### initializes all fields to reasonable default values.
00086     NormalizationLearner();
00087 
00088 
00089     //#####  PLearner Member Functions  #######################################
00090 
00093     // (PLEASE IMPLEMENT IN .cc)
00094     virtual int outputsize() const;
00095 
00099     // (PLEASE IMPLEMENT IN .cc)
00100     virtual void forget();
00101 
00105     // (PLEASE IMPLEMENT IN .cc)
00106     virtual void train();
00107 
00109     // (PLEASE IMPLEMENT IN .cc)
00110     virtual void computeOutput(const Vec& input, Vec& output) const;
00111 
00113     // (PLEASE IMPLEMENT IN .cc)
00114     virtual void computeCostsFromOutputs(const Vec& input, const Vec& output,
00115                                          const Vec& target, Vec& costs) const;
00116 
00119     // (PLEASE IMPLEMENT IN .cc)
00120     virtual TVec<std::string> getTestCostNames() const;
00121 
00124     // (PLEASE IMPLEMENT IN .cc)
00125     virtual TVec<std::string> getTrainCostNames() const;
00126 
00128     virtual TVec<string> getOutputNames() const;
00129 
00130     // *** SUBCLASS WRITING: ***
00131     // While in general not necessary, in case of particular needs
00132     // (efficiency concerns for ex) you may also want to overload
00133     // some of the following methods:
00134     // virtual void computeOutputAndCosts(const Vec& input, const Vec& target,
00135     //                                    Vec& output, Vec& costs) const;
00136     // virtual void computeCostsOnly(const Vec& input, const Vec& target,
00137     //                               Vec& costs) const;
00138     // virtual void test(VMat testset, PP<VecStatsCollector> test_stats,
00139     //                   VMat testoutputs=0, VMat testcosts=0) const;
00140     // virtual int nTestCosts() const;
00141     // virtual int nTrainCosts() const;
00142     // virtual void resetInternalState();
00143     // virtual bool isStatefulLearner() const;
00144 
00145 
00146     //#####  PLearn::Object Protocol  #########################################
00147 
00148     // Declares other standard object methods.
00149     // ### If your class is not instantiatable (it has pure virtual methods)
00150     // ### you should replace this by PLEARN_DECLARE_ABSTRACT_OBJECT_METHODS
00151     PLEARN_DECLARE_OBJECT(NormalizationLearner);
00152 
00153     // Simply calls inherited::build() then build_()
00154     virtual void build();
00155 
00157     // (PLEASE IMPLEMENT IN .cc)
00158     virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies);
00159 
00160 protected:
00161     //#####  Protected Options  ###############################################
00162 
00163     // ### Declare protected option fields (such as learned parameters) here
00164     // ...
00165 
00166 protected:
00167     //#####  Protected Member Functions  ######################################
00168 
00170     // (PLEASE IMPLEMENT IN .cc)
00171     static void declareOptions(OptionList& ol);
00172 
00173 private:
00174     //#####  Private Member Functions  ########################################
00175 
00177     // (PLEASE IMPLEMENT IN .cc)
00178     void build_();
00179 
00180 private:
00181     //#####  Private Data Members  ############################################
00182 
00183     // The rest of the private stuff goes here
00184 };
00185 
00186 // Declares a few other classes and functions related to this class
00187 DECLARE_OBJECT_PTR(NormalizationLearner);
00188 
00189 } // end of namespace PLearn
00190 
00191 #endif
00192 
00193 
00194 /*
00195   Local Variables:
00196   mode:c++
00197   c-basic-offset:4
00198   c-file-style:"stroustrup"
00199   c-file-offsets:((innamespace . 0)(inline-open . 0))
00200   indent-tabs-mode:nil
00201   fill-column:79
00202   End:
00203 */
00204 // 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