ChebyshewMetric.cpp

Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 2006-2009 Christian Gehl
00008  * Copyright (C) 2006-2009 Fraunhofer Institute FIRST
00009  */
00010 
00011 #include <shogun/lib/config.h>
00012 #include <shogun/lib/common.h>
00013 #include <shogun/io/SGIO.h>
00014 #include <shogun/distance/ChebyshewMetric.h>
00015 #include <shogun/features/Features.h>
00016 #include <shogun/features/SimpleFeatures.h>
00017 
00018 using namespace shogun;
00019 
00020 CChebyshewMetric::CChebyshewMetric() : CSimpleDistance<float64_t>()
00021 {
00022 }
00023 
00024 CChebyshewMetric::CChebyshewMetric(CSimpleFeatures<float64_t>* l, CSimpleFeatures<float64_t>* r)
00025 : CSimpleDistance<float64_t>()
00026 {
00027     init(l, r);
00028 }
00029 
00030 CChebyshewMetric::~CChebyshewMetric()
00031 {
00032     cleanup();
00033 }
00034 
00035 bool CChebyshewMetric::init(CFeatures* l, CFeatures* r)
00036 {
00037     return CSimpleDistance<float64_t>::init(l,r);
00038 }
00039 
00040 void CChebyshewMetric::cleanup()
00041 {
00042 }
00043 
00044 float64_t CChebyshewMetric::compute(int32_t idx_a, int32_t idx_b)
00045 {
00046     int32_t alen, blen;
00047     bool afree, bfree;
00048 
00049     float64_t* avec=
00050         ((CSimpleFeatures<float64_t>*) lhs)->get_feature_vector(idx_a, alen, afree);
00051     float64_t* bvec=
00052         ((CSimpleFeatures<float64_t>*) rhs)->get_feature_vector(idx_b, blen, bfree);
00053 
00054     ASSERT(alen==blen);
00055 
00056     float64_t result=DBL_MIN;
00057 
00058     for (int32_t i=0; i<alen; i++)
00059         result=CMath::max(result, fabs(avec[i]-bvec[i]));
00060 
00061     ((CSimpleFeatures<float64_t>*) lhs)->free_feature_vector(avec, idx_a, afree);
00062     ((CSimpleFeatures<float64_t>*) rhs)->free_feature_vector(bvec, idx_b, bfree);
00063 
00064     return result;
00065 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation