PLearn 0.1
SpectralClustering.cc
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // SpectralClustering.cc
00004 //
00005 // Copyright (C) 2004 Olivier Delalleau 
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: SpectralClustering.cc 3994 2005-08-25 13:35:03Z chapados $ 
00037  ******************************************************* */
00038 
00039 // Authors: Olivier Delalleau
00040 
00043 #include <plearn/ker/DivisiveNormalizationKernel.h>
00044 #include "SpectralClustering.h"
00045 
00046 namespace PLearn {
00047 using namespace std;
00048 
00050 // SpectralClustering //
00052 SpectralClustering::SpectralClustering() 
00053     : remove_bias(false)
00054 {
00055     // Usually, one will want only positive eigenvalues.
00056     min_eigenvalue = 0;
00057 }
00058 
00059 PLEARN_IMPLEMENT_OBJECT(SpectralClustering,
00060                         "Spectral Clustering dimensionality reduction.",
00061                         "The current code only performs dimensionality reduction, and does not do\n"
00062                         "clustering."
00063     );
00064 
00066 // declareOptions //
00068 void SpectralClustering::declareOptions(OptionList& ol)
00069 {
00070     declareOption(ol, "remove_bias", &SpectralClustering::remove_bias, OptionBase::buildoption,
00071                   "If set to 1, the (divisively) normalized kernel will not take into account terms\n"
00072                   "of the form K(x_i,x_i), in order to remove bias induced by those terms.");
00073 
00074     // Now call the parent class' declareOptions
00075     inherited::declareOptions(ol);
00076 
00077     // Redirect the 'kernel' option toward sc_kernel.
00078     redeclareOption(ol, "kernel", &SpectralClustering::sc_kernel, OptionBase::buildoption,
00079                     "The kernel used to (implicitly) project the data in feature space.");
00080 
00081     redeclareOption(ol, "ignore_n_first", &SpectralClustering::ignore_n_first, OptionBase::nosave,
00082                     "In Spectral clustering, no eigenvector is ignored.");
00083 
00084     // And declare the normalized kernel so that it can be saved.
00085     declareOption(ol, "normalized_kernel", &KernelProjection::kernel, OptionBase::learntoption,
00086                   "The normalized kernel.");
00087 }
00088 
00090 // build //
00092 void SpectralClustering::build()
00093 {
00094     inherited::build();
00095     build_();
00096 }
00097 
00099 // build_ //
00101 void SpectralClustering::build_()
00102 {
00103     // Obtain the "real" kernel by divisive normalization of 'sc_kernel'.
00104     // We have to do this iff:
00105     // 1. A 'sc_kernel' is provided, and
00106     // 2. either:
00107     //    2.a. the 'kernel' option is not set, or
00108     //    2.b. the 'kernel' option is not a DivisiveNormalizationKernel acting on 'sc_kernel'.
00109     // This is to ensure that a loaded 'kernel' won't be overwritten.
00110     if (sc_kernel &&
00111         (!kernel ||
00112          (dynamic_cast<DivisiveNormalizationKernel*>((Kernel*) kernel))->source_kernel != sc_kernel)) {
00113         this->kernel = new DivisiveNormalizationKernel
00114             (sc_kernel, remove_bias);
00115     }
00116 }
00117 
00119 // forget //
00121 void SpectralClustering::forget()
00122 {
00123     inherited::forget();
00124 }
00125     
00127 // makeDeepCopyFromShallowCopy //
00129 void SpectralClustering::makeDeepCopyFromShallowCopy(CopiesMap& copies)
00130 {
00131     inherited::makeDeepCopyFromShallowCopy(copies);
00132 
00133     // ### Call deepCopyField on all "pointer-like" fields 
00134     // ### that you wish to be deepCopied rather than 
00135     // ### shallow-copied.
00136     // ### ex:
00137     // deepCopyField(trainvec, copies);
00138 
00139     // ### Remove this line when you have fully implemented this method.
00140     PLERROR("SpectralClustering::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!");
00141 }
00142 
00143 } // end of namespace PLearn
00144 
00145 
00146 /*
00147   Local Variables:
00148   mode:c++
00149   c-basic-offset:4
00150   c-file-style:"stroustrup"
00151   c-file-offsets:((innamespace . 0)(inline-open . 0))
00152   indent-tabs-mode:nil
00153   fill-column:79
00154   End:
00155 */
00156 // 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