ProteoWizard
Namespaces | Typedefs | Functions
ralab::base::filter Namespace Reference

Namespaces

 utilities
 

Typedefs

typedef boost::uint32_t uint32_t
 

Functions

template<typename TIterator , typename TFilterIterator , typename TOutputIterator >
void filter_sequence (TIterator dataBeg, TIterator dataEnd, TFilterIterator filterBeg, size_t fsize, TOutputIterator resBeg, bool circular=false, uint32_t sides=2)
 
template<typename TContainer >
void filter (const TContainer &data, const TContainer &filter, TContainer &result, bool circular=false, uint32_t sides=2)
 Applies linear convolution (filtering) to a univariate time series. More...
 
template<typename TReal >
TReal getGaussianFilter (std::vector< TReal > &gauss, TReal fwhm=20)
 generate the gauss filter function for filtering of peaks with fwhm (full width at half max) More...
 
template<typename TReal >
TReal getGaussianFilterQuantile (std::vector< TReal > &gauss, TReal fwhm=20, TReal quantile=0.01)
 generate the gauss filter function for filtering of peaks with fwhm (full width at half max) More...
 
template<typename TReal >
TReal getGaussian1DerFilter (std::vector< TReal > &gauss1d, TReal fwhm=20)
 generate first derivative Gauss More...
 
template<typename TReal >
TReal getGaussian1DerFilterQuantile (std::vector< TReal > &gauss1d, TReal fwhm=20, TReal quantile=0.1)
 

Typedef Documentation

§ uint32_t

typedef boost::uint32_t ralab::base::filter::uint32_t

Definition at line 47 of file filter.hpp.

Function Documentation

§ filter_sequence()

template<typename TIterator , typename TFilterIterator , typename TOutputIterator >
void ralab::base::filter::filter_sequence ( TIterator  dataBeg,
TIterator  dataEnd,
TFilterIterator  filterBeg,
size_t  fsize,
TOutputIterator  resBeg,
bool  circular = false,
uint32_t  sides = 2 
)
Parameters
[in]dataBega univariate time series.
[in]filterBega vector of filter coefficients in reverse time order (as for AR or MA coefficients). Lenght of filter must be odd.
[out]resBegresult
[in]circularIf TRUE, wrap the filter around the ends of the series, otherwise assume external values are missing (NA).
[in]sidescurrently only sides 2 supported....

Definition at line 49 of file filter.hpp.

References ralab::base::filter::utilities::prepareData().

Referenced by filter().

58  {
59  typedef typename std::iterator_traits<TOutputIterator>::value_type TReal;
60  if((fsize-1) % 2)
61  {
62  throw std::logic_error("filter size must be odd");
63  }
64  if(!circular)
65  {
66  //result.assign(data.size(), std::numeric_limits<TReal>::quiet_NaN() );
67 
68  size_t offset = static_cast<size_t>(fsize/2);
69  for(std::size_t i = 0 ; i< offset; ++i, ++resBeg)
70  {
71  *resBeg = std::numeric_limits<TReal>::quiet_NaN();
72  }
73 
74  for( ; dataBeg != dataEnd - (fsize -1) ; ++dataBeg, ++resBeg )
75  {
76  *resBeg = (std::inner_product(dataBeg , dataBeg + fsize, filterBeg ,0. ));
77  }
78  }
79  else
80  {
81 
82  std::vector<typename std::iterator_traits<TIterator>::value_type> tmp;
83  typename std::vector<typename std::iterator_traits<TIterator>::value_type>::iterator it;
84  it = utilities::prepareData( dataBeg, dataEnd, fsize , tmp );
85 
86  TIterator tbegin = tmp.begin();
87  TIterator tend = it;
88 
89  for( ; tbegin != tend - (fsize-1 ) ; ++tbegin, ++resBeg )
90  {
91  *resBeg = std::inner_product(tbegin , tbegin + fsize, filterBeg ,0. );
92  }
93  }
94  }// filter end
TContainer::iterator prepareData(TIterator dataBeg, TIterator dataEnd, size_t fsize, TContainer &res, bool mirror=false)
Example Sequence : 1 2 3 4 5; width 5 and mirror false: 4 5 1 2 3 4 5 1 2, if mirror true than: 2 1 1...
Definition: preparedata.hpp:40

§ filter()

template<typename TContainer >
void ralab::base::filter::filter ( const TContainer &  data,
const TContainer &  filter,
TContainer &  result,
bool  circular = false,
uint32_t  sides = 2 
)

Applies linear convolution (filtering) to a univariate time series.

The convolution filter is $ y[i] = f[1]*x[i+o] + ... + f[p]*x[i+o-(p-1)] $ where o is the offset: see sides for how it is determined.

Parameters
sidesfor convolution filters only. If sides=1 the filter coefficients are for past values only; if sides=2 they are centred around lag 0. In this case the length of the filter should be odd, but if it is even, more of the filter is forward in time than backward
Parameters
[in]dataa univariate time series.
[in]filtera vector of filter coefficients in reverse time order (as for AR or MA coefficients). Lenght of filter must be odd.
[out]resultresult
[in]circularIf TRUE, wrap the filter around the ends of the series, otherwise assume external values are missing (NA).
[in]sidescurrently only sides 2 supported....

Definition at line 112 of file filter.hpp.

References filter_sequence().

Referenced by pwiz::math::MatchedFilter::details::computeCorrelation(), pwiz::math::MatchedFilter::details::createFilter(), ralab::base::ms::PeakPicker< TReal, TIntegrator >::operator()(), test(), test_createFilter(), testEven(), testEvenMS2(), testHasBinaryData(), testIdSet(), testIndexSet(), testMassAnalyzerFilter(), testMS2Activation(), testMSLevelSet(), testMZPresentFilter(), testPrecursorMassRemoval(), testScanEventSet(), testScanNumberSet(), testScanTimeRange(), testSelectedIndices(), and testSpectrumIdentificationProtocol().

119  {
120  result.resize(data.size());
122  (
123  data.begin(),
124  data.end(),
125  filter.begin(),
126  filter.size(),
127  result.begin(),
128  circular,
129  sides
130  );
131  }// filter end
void filter_sequence(TIterator dataBeg, TIterator dataEnd, TFilterIterator filterBeg, size_t fsize, TOutputIterator resBeg, bool circular=false, uint32_t sides=2)
Definition: filter.hpp:49
void filter(const TContainer &data, const TContainer &filter, TContainer &result, bool circular=false, uint32_t sides=2)
Applies linear convolution (filtering) to a univariate time series.
Definition: filter.hpp:112

§ getGaussianFilter()

template<typename TReal >
TReal ralab::base::filter::getGaussianFilter ( std::vector< TReal > &  gauss,
TReal  fwhm = 20 
)

generate the gauss filter function for filtering of peaks with fwhm (full width at half max)

Postcondition
accumulate(gauss) == 1.
Returns
accumulate(gauss) == 1.
Parameters
[out]gaussGaussian for filtering
[in]fwhmfull width at half max in points

Definition at line 40 of file gaussfilter.hpp.

References getGaussianFilterQuantile(), ralab::base::filter::utilities::getGaussWorker(), and x.

44  {
45  std::vector<TReal> x;
46  ralab::base::base::seq<TReal>( -ceil(TReal(2*fwhm)), ceil(TReal(2*fwhm)) , x);
47  TReal sigma = fwhm/2.35;
48  //generate response
49  return utilities::getGaussWorker(sigma, gauss, x);
50  }
TReal getGaussWorker(TReal sigma, std::vector< TReal > &gauss, std::vector< TReal > &x)
Definition: gauss.hpp:94
KernelTraitsBase< Kernel >::space_type::abscissa_type x

§ getGaussianFilterQuantile()

template<typename TReal >
TReal ralab::base::filter::getGaussianFilterQuantile ( std::vector< TReal > &  gauss,
TReal  fwhm = 20,
TReal  quantile = 0.01 
)

generate the gauss filter function for filtering of peaks with fwhm (full width at half max)

Postcondition
accumulate(gauss) == 1.
Returns
accumulate(gauss) == 1.
Parameters
[out]gaussGaussian for filtering
[in]fwhmfull width at half max in points
quantilewould mean that the generated distribution covers at least 99.8 of mass

Definition at line 59 of file gaussfilter.hpp.

References ralab::base::filter::utilities::getGaussWorker(), ralab::base::base::seq(), and x.

Referenced by getGaussianFilter(), and ralab::base::ms::PeakPicker< TReal, TIntegrator >::PeakPicker().

64  {
65  if( quantile >= 0.5)
66  {
67  throw std::logic_error("quantile >= 0.5");
68  }
69  std::vector<TReal> x;
70 
71  TReal sigma = fwhm/2.35;
72  boost::math::normal_distribution<TReal> nd_(0,sigma);
73  TReal quant = floor(boost::math::quantile(nd_,quantile));
74  ralab::base::base::seq( quant , -quant , x);
75  return utilities::getGaussWorker(sigma, gauss, x);
76 
77  }
void seq(TReal from, TReal to, std::vector< TReal > &result)
generates the sequence from, from+/-1, ..., to (identical to from:to).
Definition: base.hpp:49
TReal getGaussWorker(TReal sigma, std::vector< TReal > &gauss, std::vector< TReal > &x)
Definition: gauss.hpp:94
KernelTraitsBase< Kernel >::space_type::abscissa_type x

§ getGaussian1DerFilter()

template<typename TReal >
TReal ralab::base::filter::getGaussian1DerFilter ( std::vector< TReal > &  gauss1d,
TReal  fwhm = 20 
)

generate first derivative Gauss

Postcondition
accumulate(gauss1d) == 0.
accumulate(fabs(gauss1d)) == 1.
Parameters
[out]gauss1dGaussian for filtering
[in]fwhmfull width at half max in points

Definition at line 87 of file gaussfilter.hpp.

References ralab::base::filter::utilities::getGaussian1DerWorker(), ralab::base::base::seq(), and x.

91  {
92  std::vector<TReal> x;
93  ralab::base::base::seq( - ceil(TReal(2*fwhm)), ceil(TReal(2*fwhm)) , x);
94  TReal sigma = fwhm/2.35;
95  //generate response
96  return utilities::getGaussian1DerWorker(sigma, gauss1d, x);
97  }
void seq(TReal from, TReal to, std::vector< TReal > &result)
generates the sequence from, from+/-1, ..., to (identical to from:to).
Definition: base.hpp:49
TReal getGaussian1DerWorker(TReal sigma, std::vector< TReal > &gauss1d, std::vector< TReal > &x)
Definition: gauss.hpp:130
KernelTraitsBase< Kernel >::space_type::abscissa_type x

§ getGaussian1DerFilterQuantile()

template<typename TReal >
TReal ralab::base::filter::getGaussian1DerFilterQuantile ( std::vector< TReal > &  gauss1d,
TReal  fwhm = 20,
TReal  quantile = 0.1 
)
Parameters
[out]gauss1dGaussian for filtering
[in]fwhmfull width at half max in points

Definition at line 102 of file gaussfilter.hpp.

References ralab::base::filter::utilities::getGaussian1DerWorker(), ralab::base::base::seq(), and x.

107  {
108  if( quantile >= 0.5)
109  {
110  throw std::logic_error("quantile >= 0.5");
111  }
112  std::vector<TReal> x;
113  TReal sigma = fwhm/2.35;
114  boost::math::normal_distribution<TReal> nd_(0,sigma);
115  TReal quant = floor(boost::math::quantile(nd_,quantile));
116  ralab::base::base::seq( quant , -quant , x);
117  //generate response
118  return utilities::getGaussian1DerWorker(sigma, gauss1d, x);
119  }
void seq(TReal from, TReal to, std::vector< TReal > &result)
generates the sequence from, from+/-1, ..., to (identical to from:to).
Definition: base.hpp:49
TReal getGaussian1DerWorker(TReal sigma, std::vector< TReal > &gauss1d, std::vector< TReal > &x)
Definition: gauss.hpp:130
KernelTraitsBase< Kernel >::space_type::abscissa_type x