PLearn 0.1
ChemicalICP.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // ChemicalICP.h
00004 //
00005 // Copyright (C) 2006 Pascal Lamblin
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 Lamblin
00036 
00040 #ifndef ChemicalICP_INC
00041 #define ChemicalICP_INC
00042 
00043 #include <plearn/base/Object.h>
00044 #include <plearn/var/Var.h>
00045 #include <plearn/var/VarArray.h>
00046 #include "Molecule.h"
00047 #include "MoleculeTemplate.h"
00048 
00049 namespace PLearn {
00050 using namespace std;
00051 
00052 class ChemicalICP;
00053 typedef PP<ChemicalICP> ChemICP;
00054 
00060 class ChemicalICP : public Object
00061 {
00062     typedef Object inherited;
00063 
00064 public:
00065 
00070     Var mol_feat_indices, template_feat_indices;
00071 
00074     Var matching_neighbors;
00075 
00076     //#####  Public Build Options  ############################################
00077 
00080 
00082     MolTemplate mol_template;
00083 
00085     Mol molecule;
00086 
00089     TVec<string> feature_names;
00090 
00094     string weighting_method;
00095 
00097     Var weighting_params;
00098 
00101     string matching_method;
00102 
00103     string memory;
00104 
00106     real initial_angles_step;
00107 
00109     Mat initial_angles_list;
00110 
00111     // Stopping conditions
00112     int max_iter; 
00113     real error_t; 
00114     real angle_t; 
00115     real trans_t; 
00116 
00117     // Learned options
00118     Mat rotation; 
00119     Vec translation; 
00120 
00123     TVec<int> matching;
00124 
00126     Vec weights;
00127 
00130     real error;
00131 
00132     // not options
00133     VarArray used_properties;
00134     VarArray other_base_properties;
00135 
00136 protected:
00137 
00140     int every_x;
00141 
00142     // Memorized data. These variables are used when the memory option is not
00143     // set to 'none', in order to remember previous alignements.
00144 
00146     TVec< PP<Molecule> > mem_aligned_molecules;
00147 
00149     Vec mem_error;
00150 
00153     TVec<Mat> mem_rotation;
00154 
00157     TVec<Vec> mem_translation;
00158 
00161     TVec< TVec<int> > mem_matching;
00162 
00166     TVec<int> mem_count;
00167     
00168     //#####  Protected Options  ###############################################
00169 
00170     // ### Declare protected option fields (such as learned parameters) here
00171 
00173     //molecule->feature_names, mol_template->feature_names and feature_names
00174     TVec<string> used_feat_names;
00175 
00178     Mat feat_distances2;
00179 
00180 
00181 public: // for debug
00182     // variables that need to be added to the global parameter array
00183     // they form other_base_properties
00184     Var all_mol_features;
00185     Var all_template_features;
00186     Var all_template_feat_dev;
00187 
00188     // variables that will be used in SurfaceTemplateLearner,
00189     // they form used_properties
00190     Var mol_coordinates;
00191     Var used_mol_features;
00192     Var template_coordinates;
00193     Var template_geom_dev;
00194     Var used_template_features;
00195     Var used_template_feat_dev;
00196 
00197 
00198 public:
00199     //#####  Public Member Functions  #########################################
00200 
00202     ChemicalICP();
00203 
00204     ChemicalICP( const MolTemplate& the_template,
00205                  const Mol& the_molecule,
00206                  const TVec<string>& the_feature_names = TVec<string>(),
00207                  string the_weighting_method = "features_sigmoid",
00208                  const Var& the_weighting_params = Var( Vec(2,1) ),
00209                  string the_matching_method = "exhaustive" );
00210 
00213     virtual void setMolecule( const Mol& the_molecule );
00214 
00216     virtual void run();
00217 
00220     virtual void saveMatch( const PPath& filename );
00221 
00223     void forgetMemorizedAlignments();
00224 
00225     //#####  PLearn::Object Protocol  #########################################
00226 
00227     // Declares other standard object methods.
00228     PLEARN_DECLARE_OBJECT(ChemicalICP);
00229 
00230     // Simply calls inherited::build() then build_()
00231     virtual void build();
00232 
00234     virtual void makeDeepCopyFromShallowCopy(CopiesMap& copies);
00235 
00236 
00237 protected:
00238     //#####  Protected Member Functions  ######################################
00239 
00243     virtual void computeUsedFeatures();
00244 
00246     virtual void computeVariables();
00247 
00249     virtual void cacheFeatureDistances();
00250 
00253     virtual void matchNearestNeighbors( const Mat& tr_template_coords,
00254                                         const Mat& matched_mol_coords );
00255 
00257     virtual void minimizeWeightedDistance( const Mat& tr_template_coords,
00258                                            const Mat& matched_mol_coords,
00259                                            real& delta_rot_length,
00260                                            real& delta_trans_length );
00261 
00264     virtual real computeWeightedDistance( const Mat& tr_template_coords,
00265                                           const Mat& matched_mol_coords );
00266 
00268     virtual void computeWeights( const Mat& tr_template_coords,
00269                                  const Mat& matched_mol_coords );
00270 
00272     static void declareOptions(OptionList& ol);
00273 
00274 private:
00275     //#####  Private Member Functions  ########################################
00276 
00278     // (PLEASE IMPLEMENT IN .cc)
00279     void build_();
00280 
00281 private:
00282     //#####  Private Data Members  ############################################
00283 
00284     // The rest of the private stuff goes here
00285 };
00286 
00287 // Declares a few other classes and functions related to this class
00288 DECLARE_OBJECT_PTR(ChemicalICP);
00289 
00290 } // end of namespace PLearn
00291 
00292 #endif
00293 
00294 
00295 /*
00296   Local Variables:
00297   mode:c++
00298   c-basic-offset:4
00299   c-file-style:"stroustrup"
00300   c-file-offsets:((innamespace . 0)(inline-open . 0))
00301   indent-tabs-mode:nil
00302   fill-column:79
00303   End:
00304 */
00305 // 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