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

Namespaces

 utilities
 

Functions

template<typename TReal >
void seq (TReal from, TReal to, std::vector< TReal > &result)
 generates the sequence from, from+/-1, ..., to (identical to from:to). More...
 
template<typename TReal >
void seq (TReal from, TReal to, TReal by, std::vector< TReal > &result)
 generates sequence: from, from+by, from + 2*by, ..., up to a sequence value less than, or equal than to. More...
 
template<typename TReal >
void seq_length (TReal from, TReal to, unsigned int length, std::vector< TReal > &result)
 generates sequence: from, to of length calls seq with $[ by = ( ( to - from ) / ( length - 1. More...
 
template<typename T1 , typename T2 >
void seq (std::vector< T1 > &ref, std::vector< T2 > &res)
 generates the sequence 1, 2, ..., length(ref), unless the argument is numeric of length 1 when it is interpreted as 1:from (even for seq(0) for compatibility with S). More...
 
template<typename TSize , typename TReal >
boost::enable_if
< boost::is_integral< TSize >
, void >::type 
seq (TSize length, std::vector< TReal > &res)
 Generates Sequence 1,2,3,....length . More...
 
template<typename InputIterator >
std::iterator_traits
< InputIterator >::value_type 
mean (InputIterator begin, InputIterator end)
 MEAN Trimmed arithmetic mean. More...
 
template<typename TReal >
TReal mean (const std::vector< TReal > &x)
 mean More...
 
template<typename TReal >
TReal mean (const std::vector< TReal > &x, TReal trim)
 mean More...
 
template<class Iter_T >
std::iterator_traits< Iter_T >
::value_type 
geometricMean (Iter_T first, Iter_T last)
 computes the mean More...
 
template<typename TReal >
void Range (const std::vector< TReal > &values, std::pair< TReal, TReal > &range)
 Range of Values range returns a std::pair containing minimum and maximum of all the given values. More...
 
template<typename T >
double max3 (T a, T b, T c)
 maximum of 3 numbers More...
 
template<typename TReal >
TReal log2 (TReal test)
 log base 2 More...
 
template<typename InputIterator , typename OutputIterator , typename TN >
OutputIterator diff (InputIterator begin, InputIterator end, OutputIterator destBegin, TN lag)
 lagged differences More...
 
template<typename InputIterator , typename TN >
InputIterator diff (InputIterator begin, InputIterator end, TN lag, TN differences)
 lagged difference More...
 
template<typename YInputIterator , typename XInputIterator , typename OutputIterator >
void interpolate_linear (YInputIterator begY, YInputIterator endY, XInputIterator begX, XInputIterator endX, OutputIterator out, int start_index=0, typename std::iterator_traits< OutputIterator >::value_type epsilon=std::numeric_limits< typename std::iterator_traits< OutputIterator >::value_type >::epsilon())
 affine interpolation on equidistantly spaced y. More...
 
template<typename YInputIterator , typename XInputIterator , typename OutputIterator >
void interpolate_cosine (YInputIterator begY, YInputIterator endY, XInputIterator begX, XInputIterator endX, OutputIterator out, int start_index=0)
 cosine interpolation on equidistantly spaced y. More...
 
template<typename YInputIterator , typename XInputIterator , typename OutputIterator >
void interpolate_cubic (YInputIterator begY, YInputIterator endY, XInputIterator begX, XInputIterator endX, OutputIterator out, int start_index=0, typename std::iterator_traits< OutputIterator >::value_type epsilon=std::numeric_limits< typename std::iterator_traits< OutputIterator >::value_type >::epsilon())
 cubic interpolation on equidistantly spaced y's. More...
 
template<typename YInputIterator , typename XInputIterator , typename OutputIterator >
void interpolate_Hermite (YInputIterator begY, YInputIterator endY, XInputIterator begX, XInputIterator endX, OutputIterator out, double tension=0, double bias=0, int start_index=0, typename std::iterator_traits< OutputIterator >::value_type epsilon=std::numeric_limits< typename std::iterator_traits< OutputIterator >::value_type >::epsilon())
 Hermite interpolation on equidistantly spaced y's. More...
 

Function Documentation

template<typename TReal >
void ralab::base::base::seq ( TReal  from,
TReal  to,
std::vector< TReal > &  result 
)

generates the sequence from, from+/-1, ..., to (identical to from:to).

Parameters
[in]fromthe starting value of the sequence
[in]tothe end value of the sequence
[out]resultresult sequence

Definition at line 48 of file base.hpp.

Referenced by ralab::base::filter::getGaussian1DerFilter(), ralab::base::filter::getGaussian1DerFilterQuantile(), ralab::base::filter::getGaussianFilterQuantile(), and seq_length().

53  {
54  result.clear();
55  typedef typename std::vector<TReal>::size_type size_type;
56  if( from <= to )
57  {
58  size_type length = static_cast<size_type>(to - from) + 1;
59  result.resize(length);
60  std::generate(result.begin() , result.end() , utilities::SeqPlus<TReal>(from));
61  }
62  else
63  {
64  size_type length = static_cast<size_type>(from - to) + 1 ;
65  result.resize(length);
66  std::generate(result.begin() , result.end() , utilities::SeqMinus<TReal>(from));
67  }
68  }
template<typename TReal >
void ralab::base::base::seq ( TReal  from,
TReal  to,
TReal  by,
std::vector< TReal > &  result 
)

generates sequence: from, from+by, from + 2*by, ..., up to a sequence value less than, or equal than to.

Specifying to < from and by of positive sign is an error.

Parameters
[in]fromthe starting value of the sequence
[in]tothe end value of the sequence
[in]bynumber: increment of the sequence
[out]resultresult sequence

Definition at line 73 of file base.hpp.

79  {
80  result.clear();
81  typedef typename std::vector<TReal>::size_type size_type;
82  size_type size = static_cast<size_type>( (to - from) / by ) + 1u ;
83  result.reserve( size );
84 
85  if(from <= to)
86  {
87  if(!(by > 0)){
88  throw std::logic_error(std::string( "by > 0" ));
89  }
90  for(; from <= to; from += by)
91  {
92  result.push_back(from);
93  }
94  }
95  else
96  {
97  if(! (by < 0) ){
98  throw std::logic_error(std::string( "by < 0" ));
99  }
100  for(; from >= to; from += by)
101  {
102  result.push_back(from);
103  }
104  }
105  }
template<typename TReal >
void ralab::base::base::seq_length ( TReal  from,
TReal  to,
unsigned int  length,
std::vector< TReal > &  result 
)

generates sequence: from, to of length calls seq with $[ by = ( ( to - from ) / ( length - 1.

) ) $]

Parameters
[in]fromthe starting value of the sequence
[in]tothe end value of the sequence
[in]lengthlength of sequence
[out]resultresult sequence

Definition at line 110 of file base.hpp.

References seq().

116  {
117  TReal by = ( ( to - from ) / ( static_cast<TReal>( length ) - 1. ) );
118  seq(from, to, by, result);
119 
120  //this is required because of machine precision...
121  // sometimes by does not add's up to precisely _to_ nad
122  if(result.size() < length)
123  {
124  result.push_back(result[result.size()-1] + by );
125  }
126  else
127  {
128  result.resize(length);
129  }
130  }
boost::enable_if< boost::is_integral< TSize >, void >::type seq(TSize length, std::vector< TReal > &res)
Generates Sequence 1,2,3,....length .
Definition: base.hpp:155
template<typename T1 , typename T2 >
void ralab::base::base::seq ( std::vector< T1 > &  ref,
std::vector< T2 > &  res 
)

generates the sequence 1, 2, ..., length(ref), unless the argument is numeric of length 1 when it is interpreted as 1:from (even for seq(0) for compatibility with S).

Parameters
[in]reftake the length from the length of this argument.
[out]resresult sequence

Definition at line 139 of file base.hpp.

143  {
144  T2 t(1);
145  res.assign(ref.size() , t );
146  std::partial_sum( res.begin() , res.end() , res.begin() );
147  }
template<typename TSize , typename TReal >
boost::enable_if<boost::is_integral<TSize>, void>::type ralab::base::base::seq ( TSize  length,
std::vector< TReal > &  res 
)

Generates Sequence 1,2,3,....length .

Generates 1, 2, ..., length unless length.out = 0, when it generates integer(0).

Parameters
[in]lengthlength of sequence
[out]resresult sequence

Definition at line 155 of file base.hpp.

159  {
160  TReal t(1);
161  res.assign(length , t );
162  std::partial_sum(res.begin(),res.end(),res.begin());
163  }
template<typename InputIterator >
std::iterator_traits<InputIterator>::value_type ralab::base::base::mean ( InputIterator  begin,
InputIterator  end 
)
inline

MEAN Trimmed arithmetic mean.

Default S3 method:

mean(x, trim = 0, na.rm = FALSE, ...) Arguments x An R object. Currently there are methods for numeric data frames, numeric vectors and dates. A complex vector is allowed for trim = 0, only. trim the fraction (0 to 0.5) of observations to be trimmed from each end of x before the mean is computed. Values outside that range are taken as the nearest endpoint. na.rm a logical value indicating whether NA values should be stripped before the computation proceeds. ... further arguments passed to or from other methods. Value For a data frame, a named vector with the appropriate method being applied column by column. If trim is zero (the default), the arithmetic mean of the values in x is computed, as a numeric or complex vector of length one. If x is not logical (coerced to numeric), integer, numeric or complex, NA is returned, with a warning. If trim is non-zero, a symmetrically trimmed mean is computed with a fraction of trim observations deleted from each end before the mean is computed.

Parameters
[in]begin
[in]end

Definition at line 186 of file base.hpp.

Referenced by ralab::base::stats::scale(), and test().

190  {
191  typedef typename std::iterator_traits<InputIterator>::value_type TReal;
192  TReal size = static_cast<TReal>(std::distance(begin,end));
193  TReal sum = std::accumulate(begin , end, 0. );
194  return(sum/size);
195  }
template<typename TReal >
TReal ralab::base::base::mean ( const std::vector< TReal > &  x)
inline

mean

Definition at line 199 of file base.hpp.

200  {
201  TReal size = static_cast<TReal>(x.size());
202  TReal sum = std::accumulate(x.begin() , x.end(), 0. );
203  return ( sum / size ) ;
204  }
template<typename TReal >
TReal ralab::base::base::mean ( const std::vector< TReal > &  x,
TReal  trim 
)

mean

Parameters
[in]x
[in]trimtrim 0 - 0.5

Definition at line 208 of file base.hpp.

212  {
213  if(trim >= 0.5)
214  {
215  trim = 0.4999999;
216  }
217  TReal size = static_cast<TReal>(x.size());
218  std::vector<TReal> wc(x); //working copy
219  std::sort(wc.begin(),wc.end());
220  size_t nrelemstrim = static_cast<size_t>(round( size * trim )) ;
221  size_t nrelems = std::distance(wc.begin() + nrelemstrim, wc.end() - nrelemstrim );
222  TReal sum = std::accumulate(wc.begin() + nrelemstrim , wc.end() - nrelemstrim, 0. );
223  return ( sum / static_cast<TReal>( nrelems ) ); //static_cast will be required with boost::math::round
224  }
template<class Iter_T >
std::iterator_traits<Iter_T>::value_type ralab::base::base::geometricMean ( Iter_T  first,
Iter_T  last 
)

computes the mean

Definition at line 228 of file base.hpp.

229  {
230  typedef typename std::iterator_traits<Iter_T>::value_type TReal;
231  size_t cnt = distance(first, last);
232  std::vector<TReal> copyOfInput(first, last);
233 
234  // ln(x)
235  typename std::vector<TReal>::iterator inputIt;
236 
237  for(inputIt = copyOfInput.begin(); inputIt != copyOfInput.end() ; ++inputIt)
238  {
239  *inputIt = std::log(*inputIt);
240  }
241 
242  // sum(ln(x))
243  TReal sum( std::accumulate(copyOfInput.begin(), copyOfInput.end(), TReal() ));
244 
245  // e^(sum(ln(x))/N)
246  TReal geomean( std::exp(sum / cnt) );
247  return geomean;
248  }
template<typename TReal >
void ralab::base::base::Range ( const std::vector< TReal > &  values,
std::pair< TReal, TReal > &  range 
)

Range of Values range returns a std::pair containing minimum and maximum of all the given values.

Parameters
[in]valuesdata
[out]rangerange

Definition at line 254 of file base.hpp.

258  {
259  TReal min = * std::min_element(values.begin(),values.end());
260  TReal max = * std::max_element(values.begin(),values.end());
261  range.first = min;
262  range.second = max;
263  }
template<typename T >
double ralab::base::base::max3 ( a,
b,
c 
)
inline

maximum of 3 numbers

Definition at line 267 of file base.hpp.

268  {
269  T max;
270  if(a>b)
271  max=a;
272  else
273  max=b;
274  if(max<c)
275  max=c;
276  return(max);
277  }
template<typename TReal >
TReal ralab::base::base::log2 ( TReal  test)
inline

log base 2

Definition at line 281 of file base.hpp.

282  {
283  if(test==0)
284  return(0);
285  else
286  return( log10( test ) / log10( static_cast<TReal>(2.) ));
287  }
void test()
template<typename InputIterator , typename OutputIterator , typename TN >
OutputIterator ralab::base::base::diff ( InputIterator  begin,
InputIterator  end,
OutputIterator  destBegin,
TN  lag 
)

lagged differences

DIFF Lagged and iterated differences.

         for more detials see R::base::diff <br>
         diff(x, ...) <br>
         ## Default S3 method: <br>
         diff(x, lag = 1, differences = 1, ...) <br>
          \return .end() Iterator in destination container.
Parameters
[in]beginbegin
[in]endend
[out]destBegindest begin
[in]lagan integer indicating which lag to use.

Definition at line 58 of file diff.hpp.

Referenced by ralab::base::resample::SamplingWith::operator()().

64  {
65  typedef typename InputIterator::value_type vtype;
66  return( std::transform(begin + lag
67  , end
68  , begin
69  , destBegin
70  , std::minus< vtype >())
71  );
72  }
template<typename InputIterator , typename TN >
InputIterator ralab::base::base::diff ( InputIterator  begin,
InputIterator  end,
TN  lag,
TN  differences 
)

lagged difference

The result of the computation is performed in place!

Returns
- .end() in result container.
Parameters
beginbegin
endend
lagAn integer indicating which lag to use.
differencesAn integer indicating the order of the difference.

Definition at line 83 of file diff.hpp.

89  {
90  if(std::distance( begin,end ) <= static_cast<int>(lag * differences) ){
91  return(begin);
92  }
93  else{
94  TN i = TN();
95  InputIterator itmp(end) ;
96  while(differences > i )
97  {
98 
99  itmp = std::transform(
100  begin + lag ,
101  itmp ,
102  begin ,
103  begin ,
104  std::minus<typename InputIterator::value_type >()
105  ) ;
106  ++i ;
107  }
108  return(itmp);
109  }
110  }
template<typename YInputIterator , typename XInputIterator , typename OutputIterator >
void ralab::base::base::interpolate_linear ( YInputIterator  begY,
YInputIterator  endY,
XInputIterator  begX,
XInputIterator  endX,
OutputIterator  out,
int  start_index = 0,
typename std::iterator_traits< OutputIterator >::value_type  epsilon = std::numeric_limits<typename std::iterator_traits<OutputIterator>::value_type>::epsilon() 
)

affine interpolation on equidistantly spaced y.

The y's are located at 0,1,2....,len(y). For x's < 0 or x's > len(y) y[0] or y[len(y) -1 ] is used.

Parameters
begYy values equidistantly spaced. spacing is [0,1,2, .... ,len(y)]
begXpoints to interpolate at
outinterpolated values, same length as x.
start_indexif y values are placed on a grid with start_index != 0

Definition at line 58 of file interpolate.hpp.

References epsilon, and ralab::base::base::utilities::interpolateLinearCosine().

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

68  {
69  typedef typename std::iterator_traits<OutputIterator>::value_type TReal;
70  utilities::LinearInterpolate<TReal> functor(epsilon);
71  utilities::interpolateLinearCosine(begY , endY , begX , endX , out , functor , start_index);
72  }// end interpolate cubic
const double epsilon
Definition: DiffTest.cpp:41
static void interpolateLinearCosine(YInputIterator y_p, YInputIterator endY, XInputIterator x_p, XInputIterator endX, OutputIterator out_p, TFunctor &interpolator, int start_index=0)
Linear cubic interpolator worker.
template<typename YInputIterator , typename XInputIterator , typename OutputIterator >
void ralab::base::base::interpolate_cosine ( YInputIterator  begY,
YInputIterator  endY,
XInputIterator  begX,
XInputIterator  endX,
OutputIterator  out,
int  start_index = 0 
)

cosine interpolation on equidistantly spaced y.

The y's are located at 0,1,2....,len(y). For x's < 0 or x's > len(y) y[0] or y[len(y) -1 ] is used.

Parameters
begYy values equidistantly spaced. spacing is [0,1,2, .... ,len(y)]
begXpoints to interpolate at
outinterpolated values, same length as x.
start_indexif y values are placed on a grid with start_index != 0

Definition at line 83 of file interpolate.hpp.

References ralab::base::base::utilities::interpolateLinearCosine().

91  {
92  typedef typename std::iterator_traits<OutputIterator>::value_type TReal;
93  utilities::CosineInterpolate<TReal> functor;
94  utilities::interpolateLinearCosine(begY,endY ,begX,endX, out,functor, start_index);
95  }// end interpolate cubic
static void interpolateLinearCosine(YInputIterator y_p, YInputIterator endY, XInputIterator x_p, XInputIterator endX, OutputIterator out_p, TFunctor &interpolator, int start_index=0)
Linear cubic interpolator worker.
template<typename YInputIterator , typename XInputIterator , typename OutputIterator >
void ralab::base::base::interpolate_cubic ( YInputIterator  begY,
YInputIterator  endY,
XInputIterator  begX,
XInputIterator  endX,
OutputIterator  out,
int  start_index = 0,
typename std::iterator_traits< OutputIterator >::value_type  epsilon = std::numeric_limits<typename std::iterator_traits<OutputIterator>::value_type>::epsilon() 
)

cubic interpolation on equidistantly spaced y's.

The y's are located at 0,1,2....,len(y). For x's < 0 or x's > len(y) y[0] or y[len(y) -1 ] is used.

Parameters
begYy values equidistantly spaced. spacing is [0,1,2, .... ,len(y)]
begXpoints to interpolate at
outinterpolated values, same length as x.
start_indexif y values are placed on a grid with start_index != 0

Definition at line 105 of file interpolate.hpp.

References epsilon, and ralab::base::base::utilities::interpolateCubicHermite().

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

115  {
116  typedef typename std::iterator_traits<OutputIterator>::value_type TReal;
117  utilities::CubicInterpolate<TReal> functor(epsilon);
118  utilities::interpolateCubicHermite(begY,endY ,begX,endX, out,functor, start_index);
119  }// end interpolate cubic
const double epsilon
Definition: DiffTest.cpp:41
static void interpolateCubicHermite(YInputIterator begY, YInputIterator endY, XInputIterator begX, XInputIterator endX, OutputIterator out, TFunctor &functor, int start_index=0)
Cubic or Hermite interpolation worker.
template<typename YInputIterator , typename XInputIterator , typename OutputIterator >
void ralab::base::base::interpolate_Hermite ( YInputIterator  begY,
YInputIterator  endY,
XInputIterator  begX,
XInputIterator  endX,
OutputIterator  out,
double  tension = 0,
double  bias = 0,
int  start_index = 0,
typename std::iterator_traits< OutputIterator >::value_type  epsilon = std::numeric_limits<typename std::iterator_traits<OutputIterator>::value_type>::epsilon() 
)

Hermite interpolation on equidistantly spaced y's.

The y's are located at 0,1,2....,len(y). For x's < 0 or x's > len(y) y[0] or y[len(y) -1 ] is used.

Parameters
begYy values equidistantly spaced. spacing is [0,1,2, .... ,len(y)]
begXpoints to interpolate at
outinterpolated values, same length as x.
tension1 is high, 0 normal, -1 is low
bias0 is even, positive is towards first segment, negative towards the other
start_indexif y values are placed on a grid with start_index != 0

Definition at line 130 of file interpolate.hpp.

References epsilon, and ralab::base::base::utilities::interpolateCubicHermite().

142  {
143  typedef typename std::iterator_traits<OutputIterator>::value_type TReal;
144  utilities::HermiteInterpolate<TReal> functor(tension, bias, epsilon);
145  utilities::interpolateCubicHermite( begY , endY , begX , endX , out , functor , start_index );
146  }// end interpolate cubic
const double epsilon
Definition: DiffTest.cpp:41
static void interpolateCubicHermite(YInputIterator begY, YInputIterator endY, XInputIterator begX, XInputIterator endX, OutputIterator out, TFunctor &functor, int start_index=0)
Cubic or Hermite interpolation worker.