Sleipnir
|
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 SVM_H 00023 #define SVM_H 00024 00025 #ifndef NO_SVM_PERF 00026 00027 #include "svmi.h" 00028 00029 namespace Sleipnir { 00030 00043 class CSVM : CSVMImpl { 00044 public: 00049 enum EKernel { 00054 EKernelLinear = 0, 00059 EKernelPolynomial = EKernelLinear + 1, 00064 EKernelRBF = EKernelPolynomial + 1 00065 }; 00066 00067 bool OpenAlphas( std::istream& istm ); 00068 bool Open( std::istream& istm ); 00069 bool Save( std::ostream& ostm ) const; 00070 bool Learn( const CPCL& PCL, const CGenes& GenesPositive ); 00071 bool Learn( const CPCL& PCL, const CGenes& GenesPositive, const CGenes& GenesNegative ); 00072 bool Evaluate( const CPCL& PCL, std::vector<float>& vecdResults ) const; 00073 00100 bool Learn( const char* szData ) { 00101 SData sData; 00102 00103 sData.m_eType = SData::EFile; 00104 sData.m_uData.m_szFile = szData; 00105 00106 return CSVMImpl::Learn( sData ); } 00107 00133 bool Learn( const CPCLSet& PCLs, const CDataPair& Answers ) { 00134 SData sData; 00135 00136 sData.m_eType = SData::EPCLs; 00137 sData.m_uData.m_pPCLs = &PCLs; 00138 sData.m_uAnswers.m_pAnswers = &Answers; 00139 00140 return CSVMImpl::Learn( sData ); } 00141 00164 bool Learn( const IDataset* pData, const CDataPair& Answers ) { 00165 SData sData; 00166 00167 sData.m_eType = SData::EData; 00168 sData.m_uData.m_pData = pData; 00169 sData.m_uAnswers.m_pAnswers = &Answers; 00170 00171 return CSVMImpl::Learn( sData ); } 00172 00208 bool Evaluate( const char* szFile, CDat& DatResults ) const { 00209 SData sData; 00210 00211 sData.m_eType = SData::EFile; 00212 sData.m_uData.m_szFile = szFile; 00213 00214 return CSVMImpl::Evaluate( sData, NULL, DatResults ); } 00215 00240 bool Evaluate( const CPCLSet& PCLs, CDat& DatResults ) const { 00241 SData sData; 00242 00243 sData.m_eType = SData::EPCLs; 00244 sData.m_uData.m_pPCLs = &PCLs; 00245 00246 return CSVMImpl::Evaluate( sData, NULL, DatResults ); } 00247 00268 bool Evaluate( const IDataset* pData, CDat& DatResults ) const { 00269 SData sData; 00270 00271 sData.m_eType = SData::EData; 00272 sData.m_uData.m_pData = pData; 00273 00274 return CSVMImpl::Evaluate( sData, NULL, DatResults ); } 00275 00298 bool Evaluate( const CPCLSet& PCLs, const CGenes& GenesInclude, CDat& DatResults ) const { 00299 SData sData; 00300 00301 sData.m_eType = SData::EPCLs; 00302 sData.m_uData.m_pPCLs = &PCLs; 00303 00304 return CSVMImpl::Evaluate( sData, &GenesInclude, DatResults ); } 00305 00328 bool Evaluate( const IDataset* pData, const CGenes& GenesInclude, CDat& DatResults ) const { 00329 SData sData; 00330 00331 sData.m_eType = SData::EData; 00332 sData.m_uData.m_pData = pData; 00333 00334 return CSVMImpl::Evaluate( sData, &GenesInclude, DatResults ); } 00335 00346 void SetIterations( size_t iIterations ) { 00347 00348 m_sLearn.maxiter = (long)iIterations; } 00349 00360 void SetCache( size_t iMegabytes ) { 00361 00362 m_sLearn.kernel_cache_size = (long)iMegabytes; } 00363 00374 void SetTradeoff( float dTradeoff ) { 00375 00376 m_sLearn.svm_c = dTradeoff; } 00377 00388 void SetGamma( float dGamma ) { 00389 00390 m_sKernel.rbf_gamma = dGamma; } 00391 00402 void SetDegree( size_t iDegree ) { 00403 00404 m_sKernel.poly_degree = (long)iDegree; } 00405 00416 void SetKernel( EKernel eKernel ) { 00417 00418 m_sKernel.kernel_type = eKernel; } 00419 00430 void SetVerbosity( size_t iVerbosity ) { 00431 00432 verbosity = (long)iVerbosity; } 00433 }; 00434 00435 } 00436 00437 #endif // NO_SVM_PERF 00438 00439 #endif // SVM_H