/* * mp_SVMWeights * * Author: Andrew Salamon * Date: Tue May 9 2006 * * Copyright (c) 2006 Machine Perception Laboratory * University of California San Diego. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * 2. 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. * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 __MP_SVMWEIGHTS_H__ #define __MP_SVMWEIGHTS_H__ #include #include #include // For std::pair #include /** This class loads and holds SVM weight values for the CERT AU detector. * Use the factory method to get a pointer to the singleton object, which * could be of a sub-class (system specific, perhaps). */ class mp_SVMWeights { public: static const std::string defaultWeights; /// Factory method for getting the SVMWeights object. Don't delete the returned pointer. static mp_SVMWeights *getSVMWeights( std::string _prefix = defaultWeights ); virtual const double *getWeights( int ni, int mu ); // Which directory (if any) we should look in to find data files void setDirectory( const std::string &dir ); const std::string &getDirectory(); void clearWeights(); bool getLoadError(); ///< Will be true if any errors occured during loading. void loadAllWeights( int niMax = 9, int muMax = 8 ); ///< Pre-load all weights files. Probably best if called without arguments so the defaults are used. unsigned int getCount() { return count; } ///< Number of 'Action Units'. Was eight for the first version of CERT std::string getCategory() { return prefix; }; ///< Name of the Matlab data file used to generate the weights files std::string getSourceFile() { return sourceFile; }; ///< Name of the Matlab data file used to generate the weights files std::string getCreateDate() { return createDate; }; ///< Date the weights files were created std::string getCertVersion() { return certVersion; }; ///< SVN revision number of the data and source used to generate the weights files private: /// Private constructor since we want this class to be a Singleton mp_SVMWeights( std::string _prefix = defaultWeights ); virtual ~mp_SVMWeights(); private: int ni; int mu; unsigned int count; std::vector buf; ///< Input buffer std::string directory; bool loadError; ///< Will be set if any files failed to load. Temporary error handling typedef std::pair mpSVMIndex; typedef std::map< mpSVMIndex, const double * > mpSVMWeightMap; // a map of currently loaded weights mpSVMWeightMap weights; const std::string prefix; std::string sourceFile; std::string createDate; std::string certVersion; const double *loadWeights( int ni, int mu ); const double *loadWeightsBinary( int ni, int mu ); const double *loadWeightsXML( int ni, int mu ); }; #endif