Sleipnir
src/svmi.h
00001 /*****************************************************************************
00002 * This file is provided under the Creative Commons Attribution 3.0 license.
00003 *
00004 * You are free to share, copy, distribute, transmit, or adapt this work
00005 * PROVIDED THAT you attribute the work to the authors listed below.
00006 * For more information, please see the following web page:
00007 * http://creativecommons.org/licenses/by/3.0/
00008 *
00009 * This file is a component of the Sleipnir library for functional genomics,
00010 * authored by:
00011 * Curtis Huttenhower (chuttenh@princeton.edu)
00012 * Mark Schroeder
00013 * Maria D. Chikina
00014 * Olga G. Troyanskaya (ogt@princeton.edu, primary contact)
00015 *
00016 * If you use this library, the included executable tools, or any related
00017 * code in your work, please cite the following publication:
00018 * Curtis Huttenhower, Mark Schroeder, Maria D. Chikina, and
00019 * Olga G. Troyanskaya.
00020 * "The Sleipnir library for computational functional genomics"
00021 *****************************************************************************/
00022 #ifndef SVMI_H
00023 #define SVMI_H
00024 
00025 namespace SVMPerf {
00026 
00027 extern "C" {
00028 #undef int64_t
00029 #include <svm_light/svm_common.h>
00030 }
00031 
00032 }
00033 using namespace SVMPerf;
00034 
00035 namespace Sleipnir {
00036 
00037 class CDat;
00038 class CDataPair;
00039 class CGenes;
00040 class CPCL;
00041 class CPCLSet;
00042 class IDataset;
00043 
00044 class CSVMImpl {
00045 protected:
00046     static const size_t c_iWords    = 512;
00047 
00048     struct SLearn : LEARN_PARM {
00049         SLearn( );
00050     };
00051 
00052     struct SKernel : KERNEL_PARM {
00053         SKernel( );
00054     };
00055 
00056     struct SData {
00057         enum {
00058             EPCL,
00059             EPCLs,
00060             EData,
00061             EFile
00062         }   m_eType;
00063         union {
00064             const CPCLSet*  m_pPCLs;
00065             const IDataset* m_pData;
00066             const char*     m_szFile;
00067             const CPCL*     m_pPCL;
00068         }   m_uData;
00069         union {
00070             const CDataPair*    m_pAnswers;
00071             const CGenes*       m_pGenes;
00072         }   m_uAnswers;
00073         const CGenes*   m_pNegative;
00074     };
00075 
00076     static SVMPerf::WORD    s_asWords[ c_iWords ];
00077 
00078     CSVMImpl( );
00079     ~CSVMImpl( );
00080 
00081     void Reset( bool, bool, bool );
00082     bool Initialize( const SData& );
00083     bool Evaluate( const SData&, const CGenes*, CDat& ) const;
00084     bool EvaluateFile( const char*, CDat& ) const;
00085     bool Learn( const SData& );
00086     size_t GetWords( const SData& ) const;
00087     DOC* CreateDoc( const SData&, size_t, size_t, size_t ) const;
00088     DOC* CreateDoc( const SData&, size_t ) const;
00089 
00090     MODEL*      m_pModel;
00091     DOC**       m_apDocs;
00092     uint32_t    m_iDocs;
00093     uint32_t    m_iWords;
00094     double*     m_adLabels;
00095     double*     m_adAlphas;
00096     size_t      m_iAlphas;
00097     SLearn      m_sLearn;
00098     SKernel     m_sKernel;
00099 };
00100 
00101 }
00102 
00103 #endif // SVMI_H