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

Namespaces

namespace  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).
 
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.
 
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.
 
template<typename T1 , typename T2 >
void seq (std::vector< T1 > &ref, std::vector< T2 > &res)
 generates the sequence [1, 2, ..., length(ref)] (as if argument along.with had been specified), unless the argument is numeric of length 1 when it is interpreted as 1:from (even for seq(0) for compatibility with S).
 
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 .
 
template<typename InputIterator >
std::iterator_traits< InputIterator >::value_type mean (InputIterator begin, InputIterator end)
 MEAN Trimmed arithmetic mean.
 
template<typename TReal >
TReal mean (const std::vector< TReal > &x)
 mean
 
template<typename TReal >
TReal mean (const std::vector< TReal > &x, TReal trim)
 mean
 
template<class Iter_T >
std::iterator_traits< Iter_T >::value_type geometricMean (Iter_T first, Iter_T last)
 computes the mean
 
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.
 
template<typename T >
double max3 (T a, T b, T c)
 maximum of 3 numbers
 
template<typename TReal >
TReal log2 (TReal test)
 log base 2
 
template<typename InputIterator , typename OutputIterator , typename TN >
OutputIterator diff (InputIterator begin, InputIterator end, OutputIterator destBegin, TN lag)
 lagged differences
 
template<typename InputIterator , typename TN >
InputIterator diff (InputIterator begin, InputIterator end, TN lag, TN differences)
 lagged difference
 
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.
 
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.
 
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.
 
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.
 

Function Documentation

◆ seq() [1/4]

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.

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

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

◆ seq() [2/4]

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 74 of file base.hpp.

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

◆ seq_length()

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 111 of file base.hpp.

117 {
118 TReal by = ( ( to - from ) / ( static_cast<TReal>( length ) - 1. ) );
119 seq(from, to, by, result);
120
121 //this is required because of machine precision...
122 // sometimes by does not add's up to precisely _to_ nad
123 if(result.size() < length)
124 {
125 result.push_back(result[result.size()-1] + by );
126 }
127 else
128 {
129 result.resize(length);
130 }
131 }
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

References seq().

◆ seq() [3/4]

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)] (as if argument along.with had been specified), 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.

144 {
145 T2 t(1);
146 res.assign(ref.size() , t );
147 std::partial_sum( res.begin() , res.end() , res.begin() );
148 }

◆ seq() [4/4]

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 156 of file base.hpp.

160 {
161 TReal t(1);
162 res.assign(length , t );
163 std::partial_sum(res.begin(),res.end(),res.begin());
164 }

◆ mean() [1/3]

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 187 of file base.hpp.

191 {
192 typedef typename std::iterator_traits<InputIterator>::value_type TReal;
193 TReal size = static_cast<TReal>(std::distance(begin,end));
194 TReal sum = std::accumulate(begin , end, 0. );
195 return(sum/size);
196 }

Referenced by ralab::base::stats::scale().

◆ mean() [2/3]

template<typename TReal >
TReal ralab::base::base::mean ( const std::vector< TReal > &  x)
inline

mean

Definition at line 200 of file base.hpp.

201 {
202 TReal size = static_cast<TReal>(x.size());
203 TReal sum = std::accumulate(x.begin() , x.end(), 0. );
204 return ( sum / size ) ;
205 }
KernelTraitsBase< Kernel >::space_type::abscissa_type x

References x.

◆ mean() [3/3]

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 209 of file base.hpp.

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

References x.

◆ geometricMean()

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 229 of file base.hpp.

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

◆ Range()

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 255 of file base.hpp.

259 {
260 TReal min = * std::min_element(values.begin(),values.end());
261 TReal max = * std::max_element(values.begin(),values.end());
262 range.first = min;
263 range.second = max;
264 }

◆ max3()

template<typename T >
double ralab::base::base::max3 ( a,
b,
c 
)
inline

maximum of 3 numbers

Definition at line 268 of file base.hpp.

269 {
270 T max;
271 if(a>b)
272 max=a;
273 else
274 max=b;
275 if(max<c)
276 max=c;
277 return(max);
278 }

◆ log2()

template<typename TReal >
TReal ralab::base::base::log2 ( TReal  test)
inline

log base 2

Definition at line 282 of file base.hpp.

283 {
284 if(test==0)
285 return(0);
286 else
287 return( log10( test ) / log10( static_cast<TReal>(2.) ));
288 }

References test().

◆ diff() [1/2]

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 57 of file diff.hpp.

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 }

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

◆ diff() [2/2]

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!
          \return - .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 82 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 }

◆ interpolate_linear()

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.

68 {
69 typedef typename std::iterator_traits<OutputIterator>::value_type TReal;
71 utilities::interpolateLinearCosine(begY , endY , begX , endX , out , functor , start_index);
72 }// end interpolate cubic
const double epsilon
Definition DiffTest.cpp:41

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

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

◆ interpolate_cosine()

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.

91 {
92 typedef typename std::iterator_traits<OutputIterator>::value_type TReal;
94 utilities::interpolateLinearCosine(begY,endY ,begX,endX, out,functor, start_index);
95 }// end interpolate cubic
CosineInterpolate Functor Linear interpolation results in discontinuities at each point.

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

◆ interpolate_cubic()

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.

115 {
116 typedef typename std::iterator_traits<OutputIterator>::value_type TReal;
118 utilities::interpolateCubicHermite(begY,endY ,begX,endX, out,functor, start_index);
119 }// end interpolate cubic

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

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

◆ interpolate_Hermite()

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.

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

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