PLearn 0.1
ManualBinner.cc
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // ManualBinner.cc
00004 // 
00005 // Copyright (C) 2002 Xavier Saint-Mleux
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: ManualBinner.cc 6861 2007-04-09 19:04:15Z saintmlx $ 
00037  ******************************************************* */
00038 
00040 #include "ManualBinner.h"
00041 
00042 namespace PLearn {
00043 using namespace std;
00044 
00045 ManualBinner::ManualBinner() 
00046     :Binner(), the_mapping(0), bin_positions()
00047 {
00048     // ...
00049 
00050     // ### You may or may not want to call build_() to finish building the object
00051     // build_();
00052 }
00053 
00054 ManualBinner::ManualBinner(Vec bin_positions_) 
00055     :Binner(), the_mapping(0), bin_positions(bin_positions_.copy())
00056 {
00057     build_();
00058 }
00059 
00060 
00061 PLEARN_IMPLEMENT_OBJECT(ManualBinner, "Binner with predefined cut-points.", 
00062                         "ManualBinner implements a Binner for which cutpoints are predefined.  "
00063                         "It's getBinning function doesn't have to look at the data; it simply "
00064                         "builds a RealMapping from the supplied bin_positions.");
00065 
00066 void ManualBinner::declareOptions(OptionList& ol)
00067 {
00068     declareOption(ol, "bin_positions", &ManualBinner::bin_positions, OptionBase::buildoption,
00069                   "The supplied cut points; should be sorted in ascending order.");
00070 
00071     declareOption(ol, "the_mapping", &ManualBinner::the_mapping, OptionBase::learntoption,
00072                   "Pre-calculated RealMapping object that is returned by getBinning");
00073 
00074     // Now call the parent class' declareOptions
00075     inherited::declareOptions(ol);
00076 }
00077 
00078 void ManualBinner::build_()
00079 {
00080     // create the pre-calculated RealMapping from bin_position
00081     if(the_mapping == 0)
00082         the_mapping= new RealMapping();
00083     the_mapping->clear();
00084     for(int i= 1; i < bin_positions.length(); ++i)
00085         the_mapping->addMapping(RealRange(']', bin_positions[i-1], bin_positions[i], ']'), i-1);
00086 }
00087 
00088 // ### Nothing to add here, simply calls build_
00089 void ManualBinner::build()
00090 {
00091     inherited::build();
00092     build_();
00093 }
00094 
00095 
00096 void ManualBinner::makeDeepCopyFromShallowCopy(CopiesMap& copies)
00097 {
00098     inherited::makeDeepCopyFromShallowCopy(copies);
00099 
00100     // ### Call deepCopyField on all "pointer-like" fields 
00101     // ### that you wish to be deepCopied rather than 
00102     // ### shallow-copied.
00103     // ### ex:
00104     // deepCopyField(trainvec, copies);
00105 
00106     // ### Remove this line when you have fully implemented this method.
00107     PLERROR("ManualBinner::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!");
00108 }
00109 
00110 
00112 PP<RealMapping> ManualBinner::getBinning(VMat v) const
00113 { return the_mapping; }
00114 
00115 PP<RealMapping> ManualBinner::getBinning() const
00116 { return the_mapping; }
00117 
00118 
00119 } // end of namespace PLearn
00120 
00121 
00122 /*
00123   Local Variables:
00124   mode:c++
00125   c-basic-offset:4
00126   c-file-style:"stroustrup"
00127   c-file-offsets:((innamespace . 0)(inline-open . 0))
00128   indent-tabs-mode:nil
00129   fill-column:79
00130   End:
00131 */
00132 // 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