contrib/mul/mipa/mipa_l2norm_vector_normaliser.cxx
Go to the documentation of this file.
00001 //:
00002 // \file
00003 // \author Martin Roberts
00004 // \brief Normalise the sampled vector by its overall L2 norm
00005 
00006 #include "mipa_l2norm_vector_normaliser.h"
00007 #include <vnl/vnl_vector.h>
00008 #include <vsl/vsl_binary_loader.h>
00009 
00010 //=======================================================================
00011 
00012 void mipa_l2norm_vector_normaliser::normalise(vnl_vector<double>& v) const
00013 {
00014     // The mapping is g-> g/(L2norm(g)+epsilon)
00015 
00016     const double epsilon=1.0E-4;//lower bound to avoid divide by zero in flat regions
00017 
00018     double L2norm=vcl_sqrt(v.squared_magnitude()+epsilon);
00019     double L2inv=1.0/L2norm;
00020     v *= L2inv;
00021 }
00022 
00023 //=======================================================================
00024 
00025 vcl_string mipa_l2norm_vector_normaliser::is_a() const
00026 {
00027     return vcl_string("mipa_l2norm_vector_normaliser");
00028 }
00029 
00030 //: Create a copy on the heap and return base class pointer
00031 mipa_vector_normaliser* mipa_l2norm_vector_normaliser::clone() const
00032 {
00033     return new mipa_l2norm_vector_normaliser(*this);
00034 }
00035 
00036 //: Print class to os
00037 void mipa_l2norm_vector_normaliser::print_summary(vcl_ostream& os) const
00038 {
00039     os<<is_a()<<'\n';
00040 }
00041 
00042 const static short version_no = 1;
00043 
00044 //: Save class to binary file stream
00045 void mipa_l2norm_vector_normaliser::b_write(vsl_b_ostream& bfs) const
00046 {
00047     vsl_b_write(bfs,version_no);
00048 }
00049 
00050 
00051 //: Load class from binary file stream
00052 void mipa_l2norm_vector_normaliser::b_read(vsl_b_istream& bfs)
00053 {
00054     short version;
00055     vsl_b_read(bfs,version);
00056 }
00057 
00058