PLearn 0.1
|
00001 00002 00003 // -*- C++ -*- 00004 00005 // Binner.cc 00006 // 00007 // Copyright (C) *YEAR* *AUTHOR(S)* 00008 // ... 00009 // Copyright (C) *YEAR* *AUTHOR(S)* 00010 // 00011 // Redistribution and use in source and binary forms, with or without 00012 // modification, are permitted provided that the following conditions are met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. The name of the authors may not be used to endorse or promote 00022 // products derived from this software without specific prior written 00023 // permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00026 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00027 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00028 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00029 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00030 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00031 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00032 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00033 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00034 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00035 // 00036 // This file is part of the PLearn library. For more information on the PLearn 00037 // library, go to the PLearn Web site at www.plearn.org 00038 00039 /* ******************************************************* 00040 * $Id: Binner.cc 6861 2007-04-09 19:04:15Z saintmlx $ 00041 ******************************************************* */ 00042 00045 #include "Binner.h" 00046 #include <plearn/math/TVec.h> 00047 #include <plearn/vmat/MemoryVMatrix.h> 00048 00049 namespace PLearn { 00050 using namespace std; 00051 00052 Binner::Binner() 00053 :Object() 00054 {} 00055 00056 PLEARN_IMPLEMENT_OBJECT(Binner, 00057 "Divides a range into bins.", 00058 ""); 00059 00060 void Binner::declareOptions(OptionList& ol) 00061 { 00062 // ### Declare all of this object's options here 00063 // ### For the "flags" of each option, you should typically specify 00064 // ### one of OptionBase::buildoption, OptionBase::learntoption or 00065 // ### OptionBase::tuningoption. Another possible flag to be combined with 00066 // ### is OptionBase::nosave 00067 00068 // ### ex: 00069 // declareOption(ol, "myoption", &Binner::myoption, OptionBase::buildoption, 00070 // "Help text describing this option"); 00071 // ... 00072 00073 // Now call the parent class' declareOptions 00074 inherited::declareOptions(ol); 00075 } 00076 00077 void Binner::build_() 00078 { 00079 // ### This method should do the real building of the object, 00080 // ### according to set 'options', in *any* situation. 00081 // ### Typical situations include: 00082 // ### - Initial building of an object from a few user-specified options 00083 // ### - Building of a "reloaded" object: i.e. from the complete set of all serialised options. 00084 // ### - Updating or "re-building" of an object after a few "tuning" options have been modified. 00085 // ### You should assume that the parent class' build_() has already been called. 00086 } 00087 00088 // ### Nothing to add here, simply calls build_ 00089 void Binner::build() 00090 { 00091 inherited::build(); 00092 build_(); 00093 } 00094 00095 00096 void Binner::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("Binner::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!"); 00108 } 00109 00111 // getBinning // 00113 PP<RealMapping> Binner::getBinning(VMat v) const 00114 { PLERROR("getBinning not implemented for this Binner"); return 0; } 00115 00117 // getBins // 00119 TVec< TVec<int> > Binner::getBins(const Vec& v) const { 00120 PLWARNING("In Binner::getBins - This method has not been tested yet, remove this warning if it works fine"); 00121 VMat col = new MemoryVMatrix(columnmatrix(v)); 00122 PP<RealMapping> mapping = getBinning(col); 00123 TVec< TVec<int> > bins(mapping->length()); 00124 for (int i = 0; i < v.length(); i++) { 00125 bins[mapping->binnumber(v[i])].append(i); 00126 } 00127 return bins; 00128 } 00129 00131 // nBins // 00133 int Binner::nBins() const { 00134 PLERROR("In Binner::nBins - The nBins() method is not available for this Binner."); 00135 return 0; 00136 } 00137 00138 } // end of namespace PLearn 00139 00140 00141 /* 00142 Local Variables: 00143 mode:c++ 00144 c-basic-offset:4 00145 c-file-style:"stroustrup" 00146 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00147 indent-tabs-mode:nil 00148 fill-column:79 00149 End: 00150 */ 00151 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :