indii/ml/aux/Almost2Norm.hpp

00001 #ifndef INDII_ML_AUX_ALMOST2NORM_HPP
00002 #define INDII_ML_AUX_ALMOST2NORM_HPP
00003 
00004 #include "Norm.hpp"
00005 
00006 namespace indii {
00007   namespace ml {
00008     namespace aux {
00009 /**
00010  * Vector 2-norm without square root, i.e. inner product.
00011  *
00012  * @author Lawrence Murray <lawrence@indii.org>
00013  * @version $Rev: 489 $
00014  * @date $Date: 2008-07-31 12:13:05 +0100 (Thu, 31 Jul 2008) $
00015  *
00016  * Almost2Norm is not strictly a norm, as it does not satisfy the property
00017  * of scalar multiplication. Combining with AlmostGaussianKernel, however,
00018  * produces the same result as using PNorm<2> and GaussianKernel, but is
00019  * much more efficient, as the square root in the norm and square in the 
00020  * exponent of the Gaussian are cancelled.
00021  *
00022  * @see AlmostGaussianKernel
00023  */
00024 class Almost2Norm : public Norm {
00025 public:
00026   /**
00027    * Destructor.
00028    */
00029   virtual ~Almost2Norm();
00030 
00031   virtual double operator()(const vector& x) const;
00032 
00033   virtual vector sample(const unsigned int N) const;
00034 
00035 private:
00036   /**
00037    * Serialize.
00038    */
00039   template<class Archive>
00040   void serialize(Archive& ar, const unsigned int version);
00041 
00042   /*
00043    * Boost.Serialization requirements.
00044    */
00045   friend class boost::serialization::access;
00046     
00047 };
00048 
00049     }
00050   }
00051 }
00052 
00053 #include "Random.hpp"
00054 #include "vector.hpp"
00055 
00056 #include <set>
00057 
00058 using namespace indii::ml::aux;
00059 
00060 inline double indii::ml::aux::Almost2Norm::operator()(const vector& x)
00061     const {
00062   return inner_prod(x,x);
00063 }
00064 
00065 inline indii::ml::aux::vector indii::ml::aux::Almost2Norm::sample(
00066     const unsigned int N) const {   
00067   return Random::unitVector(N);
00068 }
00069 
00070 template<class Archive>
00071 void indii::ml::aux::Almost2Norm::serialize(Archive& ar,
00072     const unsigned int version) {  
00073   ar & boost::serialization::base_object<Norm>(*this);
00074 }
00075 
00076 #endif
00077 

Generated on Wed Dec 17 15:11:57 2008 for dysii Dynamical Systems Library by  doxygen 1.5.3