inverse_pow_dist_kernel.h

00001 /* MLPACK 0.2
00002  *
00003  * Copyright (c) 2008, 2009 Alexander Gray,
00004  *                          Garry Boyer,
00005  *                          Ryan Riegel,
00006  *                          Nikolaos Vasiloglou,
00007  *                          Dongryeol Lee,
00008  *                          Chip Mappus, 
00009  *                          Nishant Mehta,
00010  *                          Hua Ouyang,
00011  *                          Parikshit Ram,
00012  *                          Long Tran,
00013  *                          Wee Chin Wong
00014  *
00015  * Copyright (c) 2008, 2009 Georgia Institute of Technology
00016  *
00017  * This program is free software; you can redistribute it and/or
00018  * modify it under the terms of the GNU General Public License as
00019  * published by the Free Software Foundation; either version 2 of the
00020  * License, or (at your option) any later version.
00021  *
00022  * This program is distributed in the hope that it will be useful, but
00023  * WITHOUT ANY WARRANTY; without even the implied warranty of
00024  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00025  * General Public License for more details.
00026  *
00027  * You should have received a copy of the GNU General Public License
00028  * along with this program; if not, write to the Free Software
00029  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00030  * 02110-1301, USA.
00031  */
00032 #ifndef INVERSE_POW_DIST_KERNEL_H
00033 #define INVERSE_POW_DIST_KERNEL_H
00034 
00035 #include "fastlib/fastlib.h"
00036 
00037 class InversePowDistGradientKernel {
00038 
00039  public:
00040   double lambda_;
00041   
00042   index_t dimension_;
00043 
00044  public:
00045   
00046   void Init(double lambda_in, index_t dimension_in) {
00047     lambda_ = lambda_in;
00048     dimension_ = dimension_in;
00049   }
00050 
00051   double EvalUnnorm(const double *point) const {
00052     double sqdist = la::Dot(dimension_, point, point);
00053     return point[dimension_] / pow(sqdist, lambda_ / 2.0);
00054   }
00055 };
00056 
00057 class InversePowDistKernel {
00058   
00059  public:
00060   double lambda_;
00061   
00062   index_t dimension_;
00063 
00064  public:
00065 
00066   void Init(double lambda_in, index_t dimension_in) {
00067     lambda_ = lambda_in;
00068     dimension_ = dimension_in;
00069   }
00070 
00071   double EvalUnnorm(const double *point) const {
00072     double sqdist = la::Dot(dimension_, point, point);
00073 
00074     if(lambda_ > 0) {
00075       return 1.0 / pow(sqdist, lambda_ / 2.0);
00076     }
00077     else {
00078       return pow(sqdist, -lambda_ / 2.0);
00079     }
00080   }
00081 
00082   double EvalUnnorm(double dist) const {
00083     return EvalUnnormOnSq(dist * dist);
00084   }
00085 
00086   double EvalUnnormOnSq(double sqdist) const {
00087     if(lambda_ > 0) {
00088       return 1.0 / pow(sqdist, lambda_ / 2.0);
00089     }
00090     else {
00091       return pow(sqdist, -lambda_ / 2.0);
00092     }
00093   }
00094 
00095   DRange RangeUnnormOnSq(const DRange &range) const {
00096     return DRange(EvalUnnormOnSq(range.hi), EvalUnnormOnSq(range.lo));
00097   }
00098 
00099 };
00100 
00101 #endif
Generated on Mon Jan 24 12:04:38 2011 for FASTlib by  doxygen 1.6.3