/***************************************************************************** Copyright (c) 2005, Uwe Schmitt (http://www.procoders.net) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of procoders.net nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ #ifndef _SVMPP_QUADOPTIMDATA_H #define _SVMPP_QUADOPTIMDATA_H #include "Problem.hpp" #include "Kernel.hpp" namespace pcsvm { using namespace pcsvm; // template class QuadOptimDataI { // liefert daten fuer das von Q, b, y abhängende optimierungsproblem // // min .5 alpha^T Q alpha + b^T alpha // // bez. alpha // // wobei y^t alpha = 0 // _yi in { -1, 1} // 0 <= _alphai <= cp fuer _yi = +1 // 0 <= _alphai <= cn fuer _yi = -1 // // Q, b, y werden bestimmt anhand problemdaten und algorithmus (CSVM, SVR, ...) // public: //xx: achim fragen: besser pointer ??? //QuadOptimDataI(const KernelI *kernel, float Cp, float Cn): _prob(prob), _kernel(kernel), _Cp(Cp), _Cn(Cn) {}; virtual ~QuadOptimDataI()=0; virtual float Q(unsigned int, unsigned int)=0; virtual float b(unsigned int)=0; virtual signed char y(unsigned int) = 0; float getCp() { return _Cp; } float getCn() { return _Cn; } virtual int size() = 0; protected: // const Problem & _prob; const KernelI * _kernel; float _Cp, _Cn; //private: QuadOptimDataI(const KernelI * kernel, float Cp, float Cn): _kernel(kernel), _Cp(Cp), _Cn(Cn) {}; }; template class QuadOptimData: public QuadOptimDataI // { public: QuadOptimData(const Problem * prob, const KernelI * kernel, float Cp, float Cn): _sparse_prob(0), _full_prob(prob), QuadOptimDataI(kernel, Cp, Cn) { }; QuadOptimData(const Problem* prob, const KernelI * kernel, float Cp, float Cn): _sparse_prob(prob), _full_prob(0), QuadOptimDataI(kernel, Cp, Cn) { }; virtual float Q(unsigned int i, unsigned int j) =0; virtual float b(unsigned int i) = 0; virtual signed char y(unsigned int i) = 0; virtual int size() { return _sparse_prob ? _sparse_prob->size() : _full_prob.size(); } protected: const Problem * _sparse_prob; const Problem * _full_prob; }; class CSVMOptimData: public QuadOptimData { public: CSVMOptimData(const Problem * prob, const KernelI * kernel, float Cp, float Cn): QuadOptimData(prob, kernel, Cp, Cn) { }; CSVMOptimData(const Problem * prob, const KernelI * kernel, float Cp, float Cn): QuadOptimData(prob, kernel, Cp, Cn) { }; virtual float Q(unsigned int i, unsigned int j); virtual float b(unsigned int i); virtual signed char y(unsigned int i); }; } // Namepspace #endif