PLearn 0.1
|
The first sentence should be a BRIEF DESCRIPTION of what the class does. More...
#include <ChemicalICP.h>
Public Member Functions | |
ChemicalICP () | |
Default constructor. | |
ChemicalICP (const MolTemplate &the_template, const Mol &the_molecule, const TVec< string > &the_feature_names=TVec< string >(), string the_weighting_method="features_sigmoid", const Var &the_weighting_params=Var(Vec(2, 1)), string the_matching_method="exhaustive") | |
virtual void | setMolecule (const Mol &the_molecule) |
Use this function to set the molecule and update every parameter that depends on it without having to call build(). | |
virtual void | run () |
Performs the alignment. | |
virtual void | saveMatch (const PPath &filename) |
Saves the alignment parameters: rotation, translation, matching... | |
void | forgetMemorizedAlignments () |
Forget any previously memorized alignment. | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual ChemicalICP * | deepCopy (CopiesMap &copies) const |
virtual void | build () |
Post-constructor. | |
virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
Transforms a shallow copy into a deep copy. | |
Static Public Member Functions | |
static string | _classname_ () |
static OptionList & | _getOptionList_ () |
static RemoteMethodMap & | _getRemoteMethodMap_ () |
static Object * | _new_instance_for_typemap_ () |
static bool | _isa_ (const Object *o) |
static void | _static_initialize_ () |
static const PPath & | declaringFile () |
Public Attributes | |
Var | mol_feat_indices |
Indices of the used features, for the molecule and the template. | |
Var | template_feat_indices |
Var | matching_neighbors |
Variable that has the same content as the 'matching' vector after an ICP run. | |
MolTemplate | mol_template |
### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //! | |
Mol | molecule |
The molecule. | |
TVec< string > | feature_names |
Names of features to use during alignment. | |
string | weighting_method |
Method used to compute the weight of a pair of point. | |
Var | weighting_params |
Parameters used during weighting. Meaning depends on "weighting_method". | |
string | matching_method |
Method used to find the nearest neighbors. | |
string | memory |
real | initial_angles_step |
Tries initial rotations every "initial_angles_step" degrees. | |
Mat | initial_angles_list |
Explicit list of initial rotations angles. | |
int | max_iter |
Maximum number of iterations to perform during alignment. | |
real | error_t |
Stop alignment if error falls below this threshold. | |
real | angle_t |
Stop alignment if angles falls below this threshold. | |
real | trans_t |
Stop alignment if translation falls below this threshold. | |
Mat | rotation |
Learned rotation matrix. | |
Vec | translation |
Learned translation vector. | |
TVec< int > | matching |
matching[i] is the index of the molecule point being the nearest neighbor of template point i | |
Vec | weights |
Weight of the pair of points (i, matching[i]) | |
real | error |
Weigted error of the alignment (equal to the 'distance' part of 'score', as computed in ComputeScoreVariable) | |
VarArray | used_properties |
VarArray | other_base_properties |
Var | all_mol_features |
Var | all_template_features |
Var | all_template_feat_dev |
Var | mol_coordinates |
Var | used_mol_features |
Var | template_coordinates |
Var | template_geom_dev |
Var | used_template_features |
Var | used_template_feat_dev |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Protected Member Functions | |
virtual void | computeUsedFeatures () |
computes the intersection of feature_names, molecule->feature_names and mol_template->feature_names, stores it in used_feat_names, and computes correspondance index for mol and mol_template | |
virtual void | computeVariables () |
updates the 'used_...' variables' fields | |
virtual void | cacheFeatureDistances () |
fills feat_distances2 matrix | |
virtual void | matchNearestNeighbors (const Mat &tr_template_coords, const Mat &matched_mol_coords) |
fills matching, and compute matched_mol_coords as the list of coordinates of transformed template's nearest neighbors | |
virtual void | minimizeWeightedDistance (const Mat &tr_template_coords, const Mat &matched_mol_coords, real &delta_rot_length, real &delta_trans_length) |
finds transformation minimizing weighted distance between matched points | |
virtual real | computeWeightedDistance (const Mat &tr_template_coords, const Mat &matched_mol_coords) |
computes the alignment error: sum over every matched pairs of (weighted geometrical distance) + feature distance | |
virtual void | computeWeights (const Mat &tr_template_coords, const Mat &matched_mol_coords) |
computes weights for every pair of matched points (fills weights) | |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares the class options. | |
Protected Attributes | |
int | every_x |
When the memory option is set to 'every-X', this variable contains the value of X. | |
TVec< PP< Molecule > > | mem_aligned_molecules |
List of molecules previously aligned. | |
Vec | mem_error |
List of errors corresponding to molecules in 'mem_aligned_molecules'. | |
TVec< Mat > | mem_rotation |
List of rotation matrices corresponding to molecules in 'mem_aligned_molecules'. | |
TVec< Vec > | mem_translation |
List of translation vectors corresponding to molecules in 'mem_aligned_molecules'. | |
TVec< TVec< int > > | mem_matching |
List of matching vectors corresponding to molecules in 'mem_aligned_molecules'. | |
TVec< int > | mem_count |
Indicates the number of time each molecule in 'mem_aligned_molecules' has been aligned (regardless of whether or not this alignement has been recomputed or obtained from a previous alignemnt). | |
TVec< string > | used_feat_names |
feature names really used during alignment: intersection between | |
Mat | feat_distances2 |
Cache of feature distances : feat_distances2(i,j) is feature distance between point i of the template and point j of the molecule. | |
Private Types | |
typedef Object | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. |
The first sentence should be a BRIEF DESCRIPTION of what the class does.
Place the rest of the class programmer documentation here. Doxygen supports Javadoc-style comments. See http://www.doxygen.org/manual.html
Definition at line 60 of file ChemicalICP.h.
typedef Object PLearn::ChemicalICP::inherited [private] |
Reimplemented from PLearn::Object.
Definition at line 62 of file ChemicalICP.h.
PLearn::ChemicalICP::ChemicalICP | ( | ) |
Default constructor.
Definition at line 56 of file ChemicalICP.cc.
: mol_feat_indices( new UnaryVariable() ), template_feat_indices( new UnaryVariable() ), matching_neighbors( new UnaryVariable() ), weighting_method( "features_sigmoid" ), weighting_params( Vec(2,1) ), matching_method( "exhaustive" ), memory( "none" ), initial_angles_step( 0 ), max_iter( 50 ), error_t( 0 ), angle_t( 0.5 ), trans_t( 0 ), rotation( 3, 3 ), translation( 3 ), all_mol_features( 0 ), all_template_features( 0 ), all_template_feat_dev( 0 ), mol_coordinates( 0 ), used_mol_features( new VarColumnsVariable( all_mol_features, mol_feat_indices ) ), template_coordinates( 0 ), template_geom_dev( 0 ), used_template_features( new VarColumnsVariable(all_template_features, template_feat_indices) ), used_template_feat_dev( new VarColumnsVariable(all_template_feat_dev, template_feat_indices) ) {}
PLearn::ChemicalICP::ChemicalICP | ( | const MolTemplate & | the_template, |
const Mol & | the_molecule, | ||
const TVec< string > & | the_feature_names = TVec<string>() , |
||
string | the_weighting_method = "features_sigmoid" , |
||
const Var & | the_weighting_params = Var( Vec(2,1) ) , |
||
string | the_matching_method = "exhaustive" |
||
) |
Definition at line 85 of file ChemicalICP.cc.
References build().
: mol_feat_indices( new UnaryVariable() ), template_feat_indices( new UnaryVariable() ), matching_neighbors( new UnaryVariable() ), mol_template(the_template), molecule(the_molecule), feature_names(the_feature_names), weighting_method(the_weighting_method), weighting_params(the_weighting_params), matching_method( the_matching_method ), memory( "none" ), initial_angles_step( 0 ), max_iter( 50 ), error_t( 0 ), angle_t( 0.5 ), trans_t( 0 ), rotation( 3, 3 ), translation( 3 ), all_mol_features( 0 ), // calls SourceVariable() all_template_features( 0 ), all_template_feat_dev( 0 ), mol_coordinates( 0 ), used_mol_features( new VarColumnsVariable( all_mol_features, mol_feat_indices ) ), template_coordinates( 0 ), template_geom_dev( 0 ), used_template_features( new VarColumnsVariable(all_template_features, template_feat_indices) ), used_template_feat_dev( new VarColumnsVariable(all_template_feat_dev, template_feat_indices) ) { //pout << "Big constructor called" << endl; build(); }
string PLearn::ChemicalICP::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 54 of file ChemicalICP.cc.
OptionList & PLearn::ChemicalICP::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 54 of file ChemicalICP.cc.
RemoteMethodMap & PLearn::ChemicalICP::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 54 of file ChemicalICP.cc.
Reimplemented from PLearn::Object.
Definition at line 54 of file ChemicalICP.cc.
Object * PLearn::ChemicalICP::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 54 of file ChemicalICP.cc.
StaticInitializer ChemicalICP::_static_initializer_ & PLearn::ChemicalICP::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 54 of file ChemicalICP.cc.
void PLearn::ChemicalICP::build | ( | ) | [virtual] |
Post-constructor.
The normal implementation should call simply inherited::build(), then this class's build_(). This method should be callable again at later times, after modifying some option fields to change the "architecture" of the object.
Reimplemented from PLearn::Object.
Definition at line 610 of file ChemicalICP.cc.
References PLearn::Object::build(), and build_().
Referenced by ChemicalICP().
{ inherited::build(); build_(); }
void PLearn::ChemicalICP::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::Object.
Definition at line 765 of file ChemicalICP.cc.
References all_mol_features, all_template_feat_dev, all_template_features, cacheFeatureDistances(), computeUsedFeatures(), computeVariables(), every_x, feature_names, PLearn::lowerstring(), matching_method, matching_neighbors, memory, mol_coordinates, mol_template, molecule, other_base_properties, PLERROR, PLWARNING, PLearn::TVec< T >::resize(), PLearn::TVec< T >::size(), template_coordinates, template_geom_dev, used_mol_features, used_properties, used_template_feat_dev, used_template_features, weighting_method, weighting_params, and x.
Referenced by build().
{ #ifdef BOUNDCHECK // Variable names for debugging. used_mol_features->setName("used_mol_features"); used_template_features->setName("used_template_features"); used_template_feat_dev->setName("used_template_feat_dev"); #endif if (memory == "none") { // A negative value for 'every_x' means it is not used. every_x = -1; } else if (memory.find("every-") == 0) { string x = memory.substr(6); every_x = atoi(x.c_str()); if (every_x <= 0) PLERROR("In ChemicalICP::build_ - The X value in 'every-X' (option" " 'memory') must be positive"); } else PLERROR("In ChemicalICP::build_ - Invalid value for option 'memory'"); if( feature_names.size() > 0 && lowerstring( feature_names[0] ) == "none" ) { // no feature will be used during the alignment nor score computation feature_names[0] = "none"; if( feature_names.size() > 1 ) { PLWARNING("First element of 'feature_names' is 'none', but" " other features are present.\n" "Resizing 'feature_names' to 1.\n"); feature_names.resize( 1 ); } } if( lowerstring( weighting_method ) == "none" || weighting_method == "" ) { weighting_method = "none"; weighting_params->resize(0, 0); } else if( lowerstring( weighting_method ) == "features_sigmoid" ) { weighting_method = "features_sigmoid"; weighting_params->resize(2, 1); } else PLERROR( "ChemicalICP::build_ - weighting_method '%s' is unknown.\n", weighting_method.c_str() ); if( lowerstring( matching_method ) == "exhaustive" ) matching_method = "exhaustive"; else PLERROR( "ChemicalICP::build_ - matching_method '%s' is unknown.\n", matching_method.c_str() ); if( mol_template ) { // make the Var's relative to the template have the right storage template_coordinates->defineValueLocation( mol_template->coordinates ); template_geom_dev->defineValueLocation( mol_template->geom_dev.toMat( mol_template->n_points(), 1 ) ); all_template_features->defineValueLocation( mol_template->features ); all_template_feat_dev->defineValueLocation( mol_template->feat_dev ); if( molecule ) { // make as if 'setMolecule' were called computeUsedFeatures(); computeVariables(); if( matching_method == "exhaustive" ) cacheFeatureDistances(); } // Resize 'matching_neighbors' so that it has the correct size (i.e. // the number of points in the template). matching_neighbors->resize(mol_template->n_points(), 1); } // build VarArray used_properties = mol_coordinates & template_coordinates & template_geom_dev & used_mol_features & used_template_features & used_template_feat_dev; other_base_properties = all_mol_features & all_template_features & all_template_feat_dev; //pout << "end build_()" << endl; }
void PLearn::ChemicalICP::cacheFeatureDistances | ( | ) | [protected, virtual] |
fills feat_distances2 matrix
Definition at line 214 of file ChemicalICP.cc.
References PLearn::diff(), feat_distances2, PLearn::TMat< T >::fill(), i, j, PLearn::TMat< T >::length(), PLearn::TMat< T >::resize(), used_mol_features, used_template_feat_dev, used_template_features, and PLearn::TMat< T >::width().
Referenced by build_(), and setMolecule().
{ //pout << "cacheFeatureDistances()" << endl; Mat t_features = used_template_features->matValue; Mat t_feat_dev = used_template_feat_dev->matValue; Mat m_features = used_mol_features->matValue; int n_template_points = t_features.length(); int n_mol_points = m_features.length(); int n_features = m_features.width(); feat_distances2.resize( n_template_points, n_mol_points ); feat_distances2.fill(0); for( int i=0 ; i<n_template_points ; i++ ) { for( int j=0 ; j<n_mol_points ; j++ ) { for( int k=0 ; k<n_features ; k++ ) { real diff = (t_features(i, k) - m_features(j, k)) / t_feat_dev(i, k); feat_distances2(i, j) += diff * diff; } } } /*pout << "t_features(0) = " << t_features(0) << endl; pout << "t_feat_dev(0) = " << t_feat_dev(0) << endl; pout << "feat_distances2(0) = " << feat_distances2(0) << endl;*/ }
string PLearn::ChemicalICP::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 54 of file ChemicalICP.cc.
void PLearn::ChemicalICP::computeUsedFeatures | ( | ) | [protected, virtual] |
computes the intersection of feature_names, molecule->feature_names and mol_template->feature_names, stores it in used_feat_names, and computes correspondance index for mol and mol_template
Definition at line 135 of file ChemicalICP.cc.
References PLearn::TVec< T >::append(), PLearn::TVec< T >::copy(), feature_names, PLearn::TVec< T >::find(), i, PLearn::TVec< T >::length(), mol_feat_indices, mol_template, molecule, PLearn::TVec< T >::resize(), PLearn::TVec< T >::size(), template_feat_indices, PLearn::TVec< T >::toMat(), and used_feat_names.
Referenced by build_(), and setMolecule().
{ // compute intersection between mol_template->feature_names and // feature_names TVec<string> template_names = mol_template->feature_names; TVec<string> common_names; TVec<int> common_indices; if( feature_names.length() == 0 ) { common_names = template_names.copy(); common_indices = TVec<int>( 0, template_names.length() - 1, 1 ); } else if( feature_names[0] == "none" ) { used_feat_names.resize( 0 ); mol_feat_indices->resize( 0, 0 ); template_feat_indices->resize( 0, 0 ); return; } else { common_names.resize(0, feature_names.length()); // to have some space common_indices.resize(0, feature_names.length()); TVec<int> indices = feature_names.find( template_names ); for( int i=0 ; i<indices.length() ; i++ ) { if( indices[i] >= 0 ) { // template_names[i] is present in feature_names common_names.append( template_names[i] ); common_indices.append( i ); } } } // then compute intersection with molecule->feature_names TVec<string> mol_names = molecule->feature_names; used_feat_names.resize(0, common_names.length()); // storage for indices Vec template_feat_indices_; Vec mol_feat_indices_; TVec<int> indices = mol_names.find( common_names ); for( int i=0 ; i<indices.length() ; i++ ) { if( indices[i] >= 0 ) { // common_names[i] is present in mol_names at position indices[i] used_feat_names.append( common_names[i] ); template_feat_indices_.append( common_indices[i] ); mol_feat_indices_.append( indices[i] ); } } // update Var's value template_feat_indices->defineValueLocation( template_feat_indices_.toMat( template_feat_indices_.size(), 1 ) ); mol_feat_indices->defineValueLocation( mol_feat_indices_.toMat( mol_feat_indices_.size(), 1 ) ); }
void PLearn::ChemicalICP::computeVariables | ( | ) | [protected, virtual] |
updates the 'used_...' variables' fields
Definition at line 200 of file ChemicalICP.cc.
References all_mol_features, mol_coordinates, molecule, used_mol_features, used_template_feat_dev, and used_template_features.
Referenced by build_(), and setMolecule().
{ // make mol_coordinates point to the new molecule's coordinates mol_coordinates->defineValueLocation( molecule->coordinates ); // make mol_features point to the new molecule's features all_mol_features->defineValueLocation( molecule->features ); // update used_... Var's so they have the right size used_mol_features->sizefprop(); used_template_features->sizefprop(); used_template_feat_dev->sizefprop(); }
real PLearn::ChemicalICP::computeWeightedDistance | ( | const Mat & | tr_template_coords, |
const Mat & | matched_mol_coords | ||
) | [protected, virtual] |
computes the alignment error: sum over every matched pairs of (weighted geometrical distance) + feature distance
Definition at line 532 of file ChemicalICP.cc.
References feat_distances2, i, PLearn::TMat< T >::length(), matching, matching_method, PLearn::powdistance(), PLearn::sqrt(), and weights.
Referenced by run().
{ //pout << "computeWeightedDistance()" << endl; real err = 0; int n_points = tr_template_coords.length(); if( matching_method == "exhaustive" ) { for( int i=0 ; i<n_points ; i++ ) { real diff2 = feat_distances2( i, matching[i] ) + powdistance( tr_template_coords(i), matched_mol_coords(i), 2 ); err += weights[i] * sqrt( diff2 ); /*pout << "i = " << i << endl << "tr_template_coords = " << tr_template_coords(i) << endl << "matched_mol_coords = " << matched_mol_coords(i) << endl << "weights = " << weights[i] << endl << "delta_err = " << weights[i] * sqrt( diff2 ) << endl << endl;*/ } } return err; }
void PLearn::ChemicalICP::computeWeights | ( | const Mat & | tr_template_coords, |
const Mat & | matched_mol_coords | ||
) | [protected, virtual] |
computes weights for every pair of matched points (fills weights)
Definition at line 556 of file ChemicalICP.cc.
References feat_distances2, PLearn::TVec< T >::fill(), i, PLearn::TMat< T >::length(), matching, matching_method, PLearn::sigmoid(), PLearn::sqrt(), weighting_method, weighting_params, and weights.
Referenced by minimizeWeightedDistance().
{ //pout << "computeWeights()" << endl; int n_points = tr_template_coords.length(); //pout << "n_points = " << n_points << endl; if( weighting_method == "none" ) { //pout << "pouet!" << endl; weights.fill( 1. / real( n_points ) ); //pout << "1. / real( n_points ) = " << 1. / real( n_points ) << endl; //pout << "weights[0] = " << weights[0] << endl; } else if( weighting_method == "features_sigmoid" ) { //pout << "plouf!" << endl; real total_weight = 0; real mid = weighting_params->value[0]; real slope = weighting_params->value[1]; if( matching_method == "exhaustive" ) { for( int i=0 ; i<n_points ; i++ ) { real diff2 = feat_distances2( i, matching[i] ); weights[i] = sigmoid( slope * (mid - sqrt(diff2)) ); total_weight += weights[i]; /*pout << "i = " << i << endl << "diff2 = " << diff2 << endl << "slope = " << slope << endl << "mid = " << mid << endl << "weights = " << weights[i] << endl << endl;*/ } weights /= total_weight; //pout << "total_weight = " << total_weight << endl; } } }
void PLearn::ChemicalICP::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares the class options.
Reimplemented from PLearn::Object.
Definition at line 662 of file ChemicalICP.cc.
References angle_t, PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::Object::declareOptions(), error, error_t, feature_names, initial_angles_list, initial_angles_step, PLearn::OptionBase::learntoption, matching, matching_method, max_iter, memory, mol_template, molecule, rotation, trans_t, translation, weighting_method, weighting_params, and weights.
{ // declareOption(ol, "myoption", &ChemicalICP::myoption, OptionBase::buildoption, // "Help text describing this option"); // ... declareOption(ol, "mol_template", &ChemicalICP::mol_template, OptionBase::buildoption, "The template we try to align on the molecule"); declareOption(ol, "molecule", &ChemicalICP::molecule, OptionBase::buildoption, "The molecule"); declareOption(ol, "feature_names", &ChemicalICP::feature_names, OptionBase::buildoption, "Names of features to use during alignment.\n" "Empty TVec means 'use all available features.\n" "Use '[ \"none\" ]' if you don't want to use any feature.\n" ); declareOption(ol, "weighting_method", &ChemicalICP::weighting_method, OptionBase::buildoption, "Method used to compute the weight of a pair of point." " One of:\n" " - \"features_sigmoid\": sigmoid of feature distance,\n" " - \"none\": same weight for each pair.\n" ); declareOption(ol, "weighting_params", &ChemicalICP::weighting_params, OptionBase::buildoption, "Var containing parameters used during weighting.\n" "Size and meaning depends on value of 'weighting_method'.\n" ); declareOption(ol, "matching_method", &ChemicalICP::matching_method, OptionBase::buildoption, "Method used to find the nearest neighbors. For the moment," " only one:\n" " - \"exhaustive\": exhaustive search (caching feature" " distances).\n" ); declareOption(ol, "memory", &ChemicalICP::memory, OptionBase::buildoption, "The kind of memory allowing ICP to re-use previous alignments:\n" "- 'none' : no memory\n" "- 'every-X': the alignment for a given molecule is re-computed only\n" " once every X times it is asked\n" ); declareOption(ol, "initial_angles_step", &ChemicalICP::initial_angles_step, OptionBase::buildoption, "Tries initial rotations every \"initial_angles_step\"" " degrees"); declareOption(ol, "initial_angles_list", &ChemicalICP::initial_angles_list, OptionBase::buildoption, "Explicit list of initial rotations angles"); declareOption(ol, "max_iter", &ChemicalICP::max_iter, OptionBase::buildoption, "Maximum number of iterations to perform during alignment"); declareOption(ol, "error_t", &ChemicalICP::error_t, OptionBase::buildoption, "Stop alignment if error falls below this threshold"); declareOption(ol, "angle_t", &ChemicalICP::angle_t, OptionBase::buildoption, "Stop alignment if angles falls below this threshold"); declareOption(ol, "trans_t", &ChemicalICP::trans_t, OptionBase::buildoption, "Stop alignment if translation falls below this threshold"); declareOption(ol, "rotation", &ChemicalICP::rotation, OptionBase::learntoption, "Learned rotation matrix"); declareOption(ol, "translation", &ChemicalICP::translation, OptionBase::learntoption, "Learned translation vector"); declareOption(ol, "matching", &ChemicalICP::matching, OptionBase::learntoption, "matching[i] is the index of the molecule point being\n" "the nearest neighbor of template point i.\n"); declareOption(ol, "weights", &ChemicalICP::weights, OptionBase::learntoption, "Weight of the pair of points (i, matching[i])"); declareOption(ol, "error", &ChemicalICP::error, OptionBase::learntoption, "Weigted error of the alignment"); // Now call the parent class' declareOptions inherited::declareOptions(ol); }
static const PPath& PLearn::ChemicalICP::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::Object.
Definition at line 228 of file ChemicalICP.h.
:
//##### Protected Member Functions ######################################
ChemicalICP * PLearn::ChemicalICP::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 54 of file ChemicalICP.cc.
void PLearn::ChemicalICP::forgetMemorizedAlignments | ( | ) |
Forget any previously memorized alignment.
Definition at line 248 of file ChemicalICP.cc.
References mem_aligned_molecules, mem_count, mem_error, mem_matching, mem_rotation, mem_translation, and PLearn::TVec< T >::resize().
{ mem_aligned_molecules.resize(0); mem_error.resize(0); mem_rotation.resize(0); mem_translation.resize(0); mem_matching.resize(0); mem_count.resize(0); }
OptionList & PLearn::ChemicalICP::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 54 of file ChemicalICP.cc.
OptionMap & PLearn::ChemicalICP::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 54 of file ChemicalICP.cc.
RemoteMethodMap & PLearn::ChemicalICP::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 54 of file ChemicalICP.cc.
void PLearn::ChemicalICP::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::Object.
Definition at line 619 of file ChemicalICP.cc.
References all_mol_features, all_template_feat_dev, all_template_features, PLearn::deepCopyField(), feat_distances2, feature_names, initial_angles_list, PLearn::Object::makeDeepCopyFromShallowCopy(), matching, matching_neighbors, mem_aligned_molecules, mem_count, mem_error, mem_matching, mem_rotation, mem_translation, mol_coordinates, mol_feat_indices, mol_template, molecule, other_base_properties, rotation, template_coordinates, template_feat_indices, template_geom_dev, translation, used_feat_names, used_mol_features, used_properties, used_template_feat_dev, used_template_features, PLearn::varDeepCopyField(), weighting_params, and weights.
{ inherited::makeDeepCopyFromShallowCopy(copies); varDeepCopyField(mol_feat_indices, copies); varDeepCopyField(template_feat_indices, copies); varDeepCopyField(matching_neighbors, copies); deepCopyField(mol_template, copies); deepCopyField(molecule, copies); deepCopyField(feature_names, copies); varDeepCopyField(weighting_params, copies); deepCopyField(initial_angles_list, copies); deepCopyField(rotation, copies); deepCopyField(translation, copies); deepCopyField(matching, copies); deepCopyField(weights, copies); deepCopyField(used_properties, copies); deepCopyField(other_base_properties, copies); deepCopyField(mem_aligned_molecules, copies); deepCopyField(mem_error, copies); deepCopyField(mem_rotation, copies); deepCopyField(mem_translation, copies); deepCopyField(mem_matching, copies); deepCopyField(mem_count, copies); deepCopyField(used_feat_names, copies); deepCopyField(feat_distances2, copies); varDeepCopyField(all_mol_features, copies); varDeepCopyField(all_template_features, copies); varDeepCopyField(all_template_feat_dev, copies); varDeepCopyField(mol_coordinates, copies); varDeepCopyField(used_mol_features, copies); varDeepCopyField(template_coordinates, copies); varDeepCopyField(template_geom_dev, copies); varDeepCopyField(used_template_features, copies); varDeepCopyField(used_template_feat_dev, copies); }
void PLearn::ChemicalICP::matchNearestNeighbors | ( | const Mat & | tr_template_coords, |
const Mat & | matched_mol_coords | ||
) | [protected, virtual] |
fills matching, and compute matched_mol_coords as the list of coordinates of transformed template's nearest neighbors
Definition at line 447 of file ChemicalICP.cc.
References feat_distances2, i, j, PLearn::TMat< T >::length(), matching, matching_method, mol_coordinates, and PLearn::powdistance().
Referenced by run().
{ //pout << "matchNearestNeighbors()" << endl; Mat mol_coords = mol_coordinates->matValue; int n_template_points = tr_template_coords.length(); int n_mol_points = mol_coords.length(); if( matching_method == "exhaustive" ) { // bruteforce searche for( int i=0 ; i<n_template_points ; i++ ) { Vec t_point = tr_template_coords( i ); //pout << "tr_template_coords(" << i << ") = " << t_point << endl; Vec dists( n_template_points ); real closest_dist2 = REAL_MAX; //pout << "closest_dist2 = " << closest_dist2 << endl; for( int j=0 ; j<n_mol_points ; j++ ) { // compute distance Vec m_point = mol_coords( j ); real dist2 = powdistance( t_point, m_point, 2 ) + feat_distances2(i, j); /*pout << "m_point = " << m_point << endl; pout << "powdistance( t_point, m_point, 2 ) = " << powdistance( t_point, m_point, 2 ) << endl; pout << "feat_distances2(" << i << "," << j << ") = " << feat_distances2(i, j) << endl; pout << "dist2 = " << dist2 << endl;*/ // keep the smallest if( dist2 < closest_dist2 ) { //pout << "beep " << endl; //pout << " matching[" << i << "] = " << j << endl; closest_dist2 = dist2; matching[i] = j; } } matched_mol_coords( i ) << mol_coords( matching[i] ); } } }
void PLearn::ChemicalICP::minimizeWeightedDistance | ( | const Mat & | tr_template_coords, |
const Mat & | matched_mol_coords, | ||
real & | delta_rot_length, | ||
real & | delta_trans_length | ||
) | [protected, virtual] |
finds transformation minimizing weighted distance between matched points
Definition at line 493 of file ChemicalICP.cc.
References PLearn::anglesFromRotationMatrix(), computeWeights(), PLearn::norm(), PLearn::product(), PLearn::productAcc(), rotation, PLearn::rotationMatrixFromAngles(), PLearn::transformationFromWeightedMatchedPoints(), translation, and weights.
Referenced by run().
{ Mat delta_rot( 3, 3 ); Vec delta_trans( 3 ); real err = REAL_MAX; //pout << "before computeWeights()" << endl // << tr_template_coords(0) << endl; computeWeights( tr_template_coords, matched_mol_coords ); //pout << "after computeWeights() / before transformationFromWeightedMatchedPoints" << endl // << tr_template_coords(0) << endl; transformationFromWeightedMatchedPoints( tr_template_coords, matched_mol_coords, weights, delta_rot, delta_trans, err ); /*pout << "after transformationFromWeightedMatchedPoints" << endl << tr_template_coords(0) << endl; pout << "weights = " << weights << endl << "delta_rot = " << endl << delta_rot << endl << "delta_trans = " << delta_trans << endl;*/ delta_rot_length = norm( anglesFromRotationMatrix( delta_rot ), 2 ); delta_trans_length = norm( delta_trans ); // accumulate transformation ensuring normalization Vec angles = anglesFromRotationMatrix( product( rotation, delta_rot ) ); rotation << rotationMatrixFromAngles( angles ); // translation = delta_trans + delta_rot * translation productAcc( delta_trans, delta_rot, translation ); translation << delta_trans; //pout << "rotation = " << endl << rotation << endl // << "translation = " << translation << endl; }
void PLearn::ChemicalICP::run | ( | ) | [virtual] |
Performs the alignment.
Reimplemented from PLearn::Object.
Definition at line 261 of file ChemicalICP.cc.
References angle_t, PLearn::TVec< T >::append(), PLearn::TMat< T >::appendRow(), PLearn::applyGeomTransformation(), computeWeightedDistance(), PLearn::TVec< T >::copy(), PLearn::endl(), error, error_t, every_x, EXTREME_NAMED_LOG, PLearn::fast_is_equal(), PLearn::TVec< T >::fill(), PLearn::TVec< T >::find(), i, initial_angles_list, initial_angles_step, PLearn::TVec< T >::length(), PLearn::TMat< T >::length(), matching, matching_neighbors, matchNearestNeighbors(), max_iter, mem_aligned_molecules, mem_count, mem_error, mem_matching, mem_rotation, mem_translation, memory, minimizeWeightedDistance(), mol_template, molecule, PLASSERT, PLERROR, PLWARNING, PLearn::TVec< T >::resize(), PLearn::TMat< T >::resize(), rotation, PLearn::rotationMatrixFromAngles(), template_coordinates, trans_t, translation, weights, and PLearn::TMat< T >::width().
{ if( initial_angles_list.length() > 0 ) { if( initial_angles_step > 0 ) { PLWARNING( "ChemicalICP::run - both 'initial_angles_step' and" " 'initial_angles_list'\n" "are provided. Setting 'initial_angles_step' to 0.\n" ); initial_angles_step = 0; } } else { if( fast_is_equal( initial_angles_step, 0. ) ) initial_angles_step = 360; initial_angles_list.resize( 0, 3 ); for( real rx=0. ; rx<360. ; rx += initial_angles_step ) for( real ry=0. ; ry<360. ; ry += initial_angles_step ) for( real rz=0. ; rz<180. ; rz += initial_angles_step ) { Vec angles( 3 ); angles[0] = rx; angles[1] = ry; angles[2] = rz; initial_angles_list.appendRow( angles ); } } EXTREME_NAMED_LOG("ICP+NNet") << "begin run()" << endl; // Only perform the alignment if we do not just obtain the result from a // previously memorized alignment. bool realign = true; int find_mol = -1; if (memory != "none") { find_mol = mem_aligned_molecules.find(molecule); if (find_mol == -1) { // This molecule had not been previously aligned. find_mol = mem_aligned_molecules.length(); mem_aligned_molecules.append(molecule); // Dummy additions just to resize the vectors correctly. mem_error.append(0); mem_rotation.append(Mat()); mem_translation.append(Vec()); mem_matching.append(TVec<int>()); mem_count.append(0); } } if (every_x > 0) { PLASSERT( find_mol >= 0 ); if (mem_count[find_mol] % every_x != 0) realign = false; } if (realign) { int n_points = mol_template->n_points(); if( n_points < 3 ) PLERROR( "ChemicalICP::run() - not enough points in template (%d).\n", n_points ); Mat best_rotation(3, 3); Vec best_translation(3); TVec<int> best_matching( n_points ); Vec best_weights( n_points ); real best_error = REAL_MAX; // transformed template coordinates Mat tr_template_coords( n_points, 3 ); // coordinates of molecule points matched to template ones Mat matched_mol_coords( n_points, 3 ); int n_initial_angles = initial_angles_list.length(); EXTREME_NAMED_LOG("ICP+NNet") << n_initial_angles << " initial angles to try" << endl; for( int i=0 ; i<n_initial_angles ; i++ ) { EXTREME_NAMED_LOG("ICP+NNet") << "global iteration number " << i << endl; // initialization rotation = rotationMatrixFromAngles( initial_angles_list(i) ); translation.fill(0); matching = TVec<int>( n_points, -1 ); weights = Vec( n_points ); int n_iter = 0; real delta_rot_length = REAL_MAX; real delta_trans_length = REAL_MAX; applyGeomTransformation( rotation, translation, template_coordinates->matValue, tr_template_coords ); EXTREME_NAMED_LOG("ICPDEBUG") << "beginning ICP:" << endl << "rotation = " << endl << rotation << endl << "translation = " << translation << endl << "template_coordinates->matValue = " << endl << template_coordinates->matValue << endl << "tr_template_coords = " << endl << tr_template_coords << endl << endl; // main loop do { EXTREME_NAMED_LOG("ICPDEBUG") << " beginning of main loop" << endl; EXTREME_NAMED_LOG("ICPDEBUG") << " matchNearestNeighbors()" << endl; matchNearestNeighbors( tr_template_coords, matched_mol_coords ); EXTREME_NAMED_LOG("ICPDEBUG") << " minimizeWeightedDistance()" << endl; minimizeWeightedDistance( tr_template_coords, matched_mol_coords, delta_rot_length, delta_trans_length ); EXTREME_NAMED_LOG("ICPDEBUG") << " applyGeomTransformation()" << endl; applyGeomTransformation( rotation, translation, template_coordinates->matValue, tr_template_coords ); EXTREME_NAMED_LOG("ICPDEBUG") << "tr_template_coords = " << endl << tr_template_coords << endl; error = computeWeightedDistance( tr_template_coords, matched_mol_coords ); n_iter++; EXTREME_NAMED_LOG("ICPDEBUG") << "end of main loop" << endl; EXTREME_NAMED_LOG("ICPDEBUG") << " iteration = " << n_iter << " / " << max_iter << endl << " error = " << error << " / " << error_t << endl << " delta_rot_length = " << delta_rot_length << " / " << angle_t << endl << " delta_trans_length = " << delta_trans_length << " / " << trans_t << endl << endl; } while( n_iter < max_iter && error > error_t && delta_rot_length > angle_t && delta_trans_length > trans_t ); // keep the best one if( error < best_error ) { best_error = error; best_rotation << rotation; best_translation << translation; best_matching << matching; } EXTREME_NAMED_LOG("ICP+NNet") << "end global iteration number " << i << endl; } // get best parameters error = best_error; rotation = best_rotation; translation = best_translation; matching = best_matching; if (memory != "none") { // Remember this alignment. PLASSERT( find_mol >= 0 ); mem_error[find_mol] = error; mem_rotation[find_mol].resize(rotation.length(), rotation.width()); mem_rotation[find_mol] << rotation; mem_translation[find_mol].resize(translation.length()); mem_translation[find_mol] << translation; mem_matching[find_mol].resize(matching.length()); mem_matching[find_mol] << matching; } } else { PLASSERT( find_mol >= 0 ); error = mem_error[find_mol]; // Copies make the code simpler, though it would be slightly more // efficient to use resize and the << operator. rotation = mem_rotation[find_mol].copy(); translation = mem_translation[find_mol].copy(); matching = mem_matching[find_mol].copy(); } if (find_mol >= 0) // Increment counter of alignments for this molecule. mem_count[find_mol]++; // Update the 'matching_neighbors' variable. matching_neighbors->resize(matching.length(), 1); for (int i = 0; i < matching.length(); i++) matching_neighbors->value[i] = matching[i]; if( !fast_is_equal( initial_angles_step, 0. ) ) initial_angles_list.resize( 0, 3 ); }
void PLearn::ChemicalICP::saveMatch | ( | const PPath & | filename | ) | [virtual] |
Saves the alignment parameters: rotation, translation, matching...
in a file (in plearn format)
Definition at line 597 of file ChemicalICP.cc.
References PLearn::endl(), error, matching, PLearn::openFile(), PLearn::PStream::plearn_ascii, rotation, and translation.
{ PStream file = openFile( filename, PStream::plearn_ascii, "w" ); file<< "rotation =" << endl << rotation << endl << "translation =" << endl << translation << endl << "matching =" << endl << matching << endl << "error = " << error << endl; }
void PLearn::ChemicalICP::setMolecule | ( | const Mol & | the_molecule | ) | [virtual] |
Use this function to set the molecule and update every parameter that depends on it without having to call build().
Definition at line 125 of file ChemicalICP.cc.
References cacheFeatureDistances(), computeUsedFeatures(), computeVariables(), matching_method, and molecule.
{ molecule = the_molecule; computeUsedFeatures(); computeVariables(); if( matching_method == "exhaustive" ) cacheFeatureDistances(); }
Reimplemented from PLearn::Object.
Definition at line 228 of file ChemicalICP.h.
Definition at line 184 of file ChemicalICP.h.
Referenced by build_(), computeVariables(), and makeDeepCopyFromShallowCopy().
Definition at line 186 of file ChemicalICP.h.
Referenced by build_(), and makeDeepCopyFromShallowCopy().
Definition at line 185 of file ChemicalICP.h.
Referenced by build_(), and makeDeepCopyFromShallowCopy().
Stop alignment if angles falls below this threshold.
Definition at line 114 of file ChemicalICP.h.
Referenced by declareOptions(), and run().
Weigted error of the alignment (equal to the 'distance' part of 'score', as computed in ComputeScoreVariable)
Definition at line 130 of file ChemicalICP.h.
Referenced by declareOptions(), run(), and saveMatch().
Stop alignment if error falls below this threshold.
Definition at line 113 of file ChemicalICP.h.
Referenced by declareOptions(), and run().
int PLearn::ChemicalICP::every_x [protected] |
When the memory option is set to 'every-X', this variable contains the value of X.
Definition at line 140 of file ChemicalICP.h.
Mat PLearn::ChemicalICP::feat_distances2 [protected] |
Cache of feature distances : feat_distances2(i,j) is feature distance between point i of the template and point j of the molecule.
Definition at line 178 of file ChemicalICP.h.
Referenced by cacheFeatureDistances(), computeWeightedDistance(), computeWeights(), makeDeepCopyFromShallowCopy(), and matchNearestNeighbors().
Names of features to use during alignment.
Empty TVec means "use all available features" use "none" if you don't want to use any feature.
Definition at line 89 of file ChemicalICP.h.
Referenced by build_(), computeUsedFeatures(), declareOptions(), and makeDeepCopyFromShallowCopy().
Explicit list of initial rotations angles.
Definition at line 109 of file ChemicalICP.h.
Referenced by declareOptions(), makeDeepCopyFromShallowCopy(), and run().
Tries initial rotations every "initial_angles_step" degrees.
Definition at line 106 of file ChemicalICP.h.
Referenced by declareOptions(), and run().
matching[i] is the index of the molecule point being the nearest neighbor of template point i
Definition at line 123 of file ChemicalICP.h.
Referenced by computeWeightedDistance(), computeWeights(), declareOptions(), makeDeepCopyFromShallowCopy(), matchNearestNeighbors(), run(), and saveMatch().
Method used to find the nearest neighbors.
For the moment, only one:
Definition at line 101 of file ChemicalICP.h.
Referenced by build_(), computeWeightedDistance(), computeWeights(), declareOptions(), matchNearestNeighbors(), and setMolecule().
Variable that has the same content as the 'matching' vector after an ICP run.
Definition at line 74 of file ChemicalICP.h.
Referenced by build_(), makeDeepCopyFromShallowCopy(), and run().
Maximum number of iterations to perform during alignment.
Definition at line 112 of file ChemicalICP.h.
Referenced by declareOptions(), and run().
TVec< PP<Molecule> > PLearn::ChemicalICP::mem_aligned_molecules [protected] |
List of molecules previously aligned.
Definition at line 146 of file ChemicalICP.h.
Referenced by forgetMemorizedAlignments(), makeDeepCopyFromShallowCopy(), and run().
TVec<int> PLearn::ChemicalICP::mem_count [protected] |
Indicates the number of time each molecule in 'mem_aligned_molecules' has been aligned (regardless of whether or not this alignement has been recomputed or obtained from a previous alignemnt).
Definition at line 166 of file ChemicalICP.h.
Referenced by forgetMemorizedAlignments(), makeDeepCopyFromShallowCopy(), and run().
Vec PLearn::ChemicalICP::mem_error [protected] |
List of errors corresponding to molecules in 'mem_aligned_molecules'.
Definition at line 149 of file ChemicalICP.h.
Referenced by forgetMemorizedAlignments(), makeDeepCopyFromShallowCopy(), and run().
TVec< TVec<int> > PLearn::ChemicalICP::mem_matching [protected] |
List of matching vectors corresponding to molecules in 'mem_aligned_molecules'.
Definition at line 161 of file ChemicalICP.h.
Referenced by forgetMemorizedAlignments(), makeDeepCopyFromShallowCopy(), and run().
TVec<Mat> PLearn::ChemicalICP::mem_rotation [protected] |
List of rotation matrices corresponding to molecules in 'mem_aligned_molecules'.
Definition at line 153 of file ChemicalICP.h.
Referenced by forgetMemorizedAlignments(), makeDeepCopyFromShallowCopy(), and run().
TVec<Vec> PLearn::ChemicalICP::mem_translation [protected] |
List of translation vectors corresponding to molecules in 'mem_aligned_molecules'.
Definition at line 157 of file ChemicalICP.h.
Referenced by forgetMemorizedAlignments(), makeDeepCopyFromShallowCopy(), and run().
string PLearn::ChemicalICP::memory |
Definition at line 103 of file ChemicalICP.h.
Referenced by build_(), declareOptions(), and run().
Definition at line 190 of file ChemicalICP.h.
Referenced by build_(), computeVariables(), makeDeepCopyFromShallowCopy(), and matchNearestNeighbors().
Indices of the used features, for the molecule and the template.
They are UnaryVariable, so that their parent may be set to a Var that runs an ICP (in order to make sure they are not used before the ICP is run).
Definition at line 70 of file ChemicalICP.h.
Referenced by computeUsedFeatures(), and makeDeepCopyFromShallowCopy().
### declare public option fields (such as build options) here Start your comments with Doxygen-compatible comments such as //!
The template we try to align on the molecule
Definition at line 82 of file ChemicalICP.h.
Referenced by build_(), computeUsedFeatures(), declareOptions(), makeDeepCopyFromShallowCopy(), and run().
The molecule.
Definition at line 85 of file ChemicalICP.h.
Referenced by build_(), computeUsedFeatures(), computeVariables(), declareOptions(), makeDeepCopyFromShallowCopy(), run(), and setMolecule().
Definition at line 134 of file ChemicalICP.h.
Referenced by build_(), and makeDeepCopyFromShallowCopy().
Learned rotation matrix.
Definition at line 118 of file ChemicalICP.h.
Referenced by declareOptions(), makeDeepCopyFromShallowCopy(), minimizeWeightedDistance(), run(), and saveMatch().
Definition at line 192 of file ChemicalICP.h.
Referenced by build_(), makeDeepCopyFromShallowCopy(), and run().
Definition at line 70 of file ChemicalICP.h.
Referenced by computeUsedFeatures(), and makeDeepCopyFromShallowCopy().
Definition at line 193 of file ChemicalICP.h.
Referenced by build_(), and makeDeepCopyFromShallowCopy().
Stop alignment if translation falls below this threshold.
Definition at line 115 of file ChemicalICP.h.
Referenced by declareOptions(), and run().
Learned translation vector.
Definition at line 119 of file ChemicalICP.h.
Referenced by declareOptions(), makeDeepCopyFromShallowCopy(), minimizeWeightedDistance(), run(), and saveMatch().
TVec<string> PLearn::ChemicalICP::used_feat_names [protected] |
feature names really used during alignment: intersection between
Definition at line 174 of file ChemicalICP.h.
Referenced by computeUsedFeatures(), and makeDeepCopyFromShallowCopy().
Definition at line 191 of file ChemicalICP.h.
Referenced by build_(), cacheFeatureDistances(), computeVariables(), and makeDeepCopyFromShallowCopy().
Definition at line 133 of file ChemicalICP.h.
Referenced by build_(), and makeDeepCopyFromShallowCopy().
Definition at line 195 of file ChemicalICP.h.
Referenced by build_(), cacheFeatureDistances(), computeVariables(), and makeDeepCopyFromShallowCopy().
Definition at line 194 of file ChemicalICP.h.
Referenced by build_(), cacheFeatureDistances(), computeVariables(), and makeDeepCopyFromShallowCopy().
Method used to compute the weight of a pair of point.
One of:
Definition at line 94 of file ChemicalICP.h.
Referenced by build_(), computeWeights(), and declareOptions().
Parameters used during weighting. Meaning depends on "weighting_method".
Definition at line 97 of file ChemicalICP.h.
Referenced by build_(), computeWeights(), declareOptions(), and makeDeepCopyFromShallowCopy().
Weight of the pair of points (i, matching[i])
Definition at line 126 of file ChemicalICP.h.
Referenced by computeWeightedDistance(), computeWeights(), declareOptions(), makeDeepCopyFromShallowCopy(), minimizeWeightedDistance(), and run().