Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

RemoveDuplicateVMatrix.cc

Go to the documentation of this file.
00001 // -*- C++ -*- 00002 00003 // RemoveDuplicateVMatrix.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: RemoveDuplicateVMatrix.cc,v 1.3 2004/08/03 19:05:31 tihocan Exp $ 00037 ******************************************************* */ 00038 00039 // Authors: Olivier Delalleau 00040 00044 #include <plearn/ker/DistanceKernel.h> 00045 #include "RemoveDuplicateVMatrix.h" 00046 00047 namespace PLearn { 00048 using namespace std; 00049 00051 // RemoveDuplicateVMatrix // 00053 RemoveDuplicateVMatrix::RemoveDuplicateVMatrix() 00054 : epsilon(1e-6), 00055 verbosity(1) 00056 { 00057 // ... 00058 // ### You may or may not want to call build_() to finish building the object 00059 // build_(); 00060 } 00061 00062 PLEARN_IMPLEMENT_OBJECT(RemoveDuplicateVMatrix, 00063 "A VMatrix that removes any duplicated entry in its source VMat.", 00064 "" 00065 ); 00066 00068 // declareOptions // 00070 void RemoveDuplicateVMatrix::declareOptions(OptionList& ol) 00071 { 00072 // ### Declare all of this object's options here 00073 // ### For the "flags" of each option, you should typically specify 00074 // ### one of OptionBase::buildoption, OptionBase::learntoption or 00075 // ### OptionBase::tuningoption. Another possible flag to be combined with 00076 // ### is OptionBase::nosave 00077 00078 declareOption(ol, "epsilon", &RemoveDuplicateVMatrix::epsilon, OptionBase::buildoption, 00079 "Two points will be considered equal iff their square distance is < epsilon."); 00080 00081 declareOption(ol, "verbosity", &RemoveDuplicateVMatrix::verbosity, OptionBase::buildoption, 00082 "Controls the amount of output."); 00083 00084 // Now call the parent class' declareOptions 00085 inherited::declareOptions(ol); 00086 00087 redeclareOption(ol, "indices", &RemoveDuplicateVMatrix::indices, OptionBase::nosave, 00088 "The indices will be computed at build time."); 00089 } 00090 00092 // build // 00094 void RemoveDuplicateVMatrix::build() 00095 { 00096 // ### Nothing to add here, simply calls build_ 00097 inherited::build(); 00098 build_(); 00099 } 00100 00102 // build_ // 00104 void RemoveDuplicateVMatrix::build_() 00105 { 00106 if (source) { 00107 DistanceKernel dk; 00108 dk.pow_distance = true; 00109 if (verbosity >= 1) 00110 dk.report_progress = true; 00111 else 00112 dk.report_progress = false; 00113 dk.build(); 00114 dk.setDataForKernelMatrix(source); 00115 int n = source.length(); 00116 Mat distances(n,n); 00117 dk.computeGramMatrix(distances); 00118 TVec<bool> removed(n); 00119 removed.fill(false); 00120 for (int i = 0; i < n; i++) { 00121 if (!removed[i]) { 00122 for (int j = i + 1; j < n; j++) { 00123 if (!removed[j] && distances(i,j) < epsilon) { 00124 removed[j] = true; 00125 } 00126 } 00127 } 00128 } 00129 indices.resize(0); 00130 for (int i = 0; i < n; i++) 00131 if (!removed[i]) 00132 indices.append(i); 00133 inherited::build(); 00134 } 00135 } 00136 00138 // makeDeepCopyFromShallowCopy // 00140 void RemoveDuplicateVMatrix::makeDeepCopyFromShallowCopy(map<const void*, void*>& copies) 00141 { 00142 inherited::makeDeepCopyFromShallowCopy(copies); 00143 00144 // ### Call deepCopyField on all "pointer-like" fields 00145 // ### that you wish to be deepCopied rather than 00146 // ### shallow-copied. 00147 // ### ex: 00148 // deepCopyField(trainvec, copies); 00149 00150 // ### Remove this line when you have fully implemented this method. 00151 PLERROR("RemoveDuplicateVMatrix::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!"); 00152 } 00153 00154 } // end of namespace PLearn 00155

Generated on Tue Aug 17 16:04:00 2004 for PLearn by doxygen 1.3.7