Sleipnir
src/measurei.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 MEASUREI_H
00023 #define MEASUREI_H
00024 
00025 #include "fullmatrix.h"
00026 
00027 namespace Sleipnir {
00028 
00029 class CMeasureImpl {
00030 protected:
00031     friend class CMeasureKendallsTau;
00032     friend class CMeasureKolmogorovSmirnov;
00033     friend class CMeasureSpearman;
00034 
00035     static double MeasureTrim( const IMeasure*, const float*, size_t, const float*, size_t, const IMeasure::EMap,
00036         const float*, const float*, bool );
00037     static bool IsNaN( const float*, size_t );
00038 
00039     CMeasureImpl( const IMeasure*, bool );
00040     virtual ~CMeasureImpl( );
00041 
00042     IMeasure*   m_pMeasure;
00043     bool        m_fMemory;
00044 };
00045 
00046 class CMeasureSigmoidImpl : protected CMeasureImpl {
00047 protected:
00048     CMeasureSigmoidImpl( const IMeasure* pMeasure, bool fMemory, float dMult ) :
00049         m_dMult(dMult), CMeasureImpl( pMeasure, fMemory ) { }
00050 
00051     float   m_dMult;
00052 };
00053 
00054 class CMeasureSpearmanImpl {
00055 protected:
00056     CMeasureSpearmanImpl( bool fTransformed ) : m_fTransformed(fTransformed) { }
00057 
00058     bool    m_fTransformed;
00059 };
00060 
00061 class CMeasureKendallsTauImpl {
00062 protected:
00063     struct SKendallsFirst {
00064         const float*    m_adX;
00065         const float*    m_adY;
00066 
00067         SKendallsFirst( const float* adX, const float* adY ) : m_adX(adX), m_adY(adY) { }
00068 
00069         bool operator( )( size_t iX, size_t iY ) const {
00070             float   dX, dY;
00071 
00072             dX = m_adX[ iX ];
00073             dY = m_adX[ iY ];
00074             if( dX > dY )
00075                 return true;
00076             if( dX < dY )
00077                 return false;
00078 
00079             dX = m_adY[ iX ];
00080             dY = m_adY[ iY ];
00081             return ( dX > dY ); }
00082     };
00083 
00084     struct SKendallsSecond {
00085         const float*    m_adX;
00086         const float*    m_adY;
00087 
00088         SKendallsSecond( const float* adX, const float* adY ) : m_adX(adX), m_adY(adY) { }
00089 
00090         char operator( )( size_t iX, size_t iY ) const {
00091             float   dX, dY;
00092 
00093             dX = m_adY[ iX ];
00094             dY = m_adY[ iY ];
00095             return ( ( dX > dY ) ? -1 : ( ( dX < dY ) ? 1 : 0 ) ); }
00096     };
00097 
00098     static double MeasureWeighted( const float*, const float*, size_t, const float*,
00099         const float* );
00100     static double MeasureUnweighted( const float*, const float*, size_t );
00101     static size_t CountExchanges( size_t*, size_t, size_t*, const SKendallsSecond&,
00102         size_t = 0 );
00103 };
00104 
00105 class CMeasurePearNormImpl {
00106 protected:
00107     CMeasurePearNormImpl( double dAve, double dStd ) : m_dAverage(dAve), m_dStdDev(dStd) { }
00108 
00109     double  m_dAverage;
00110     double  m_dStdDev;
00111 };
00112 
00113 }
00114 
00115 #endif // MEASUREI_H