35 #include <boost/utility/enable_if.hpp> 36 #include <boost/type_traits/is_integral.hpp> 47 template<
typename TReal>
52 std::vector<TReal> &result
56 typedef typename std::vector<TReal>::size_type size_type;
59 size_type length =
static_cast<size_type
>(to - from) + 1;
60 result.resize(length);
65 size_type length =
static_cast<size_type
>(from - to) + 1 ;
66 result.resize(length);
73 template<
typename TReal>
78 std::vector<TReal> &result
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 );
89 throw std::logic_error(std::string(
"by > 0" ));
91 for(; from <= to; from += by)
93 result.push_back(from);
99 throw std::logic_error(std::string(
"by < 0" ));
101 for(; from >= to; from += by)
103 result.push_back(from);
110 template<
typename TReal>
115 std::vector<TReal> &result
118 TReal by = ( ( to - from ) / ( static_cast<TReal>( length ) - 1. ) );
119 seq(from, to, by, result);
123 if(result.size() < length)
125 result.push_back(result[result.size()-1] + by );
129 result.resize(length);
138 template<
typename T1 ,
typename T2 >
141 std::vector<T1> & ref,
142 std::vector<T2> & res
146 res.assign(ref.size() , t );
147 std::partial_sum( res.begin() , res.end() , res.begin() );
154 template<
typename TSize,
typename TReal>
155 typename boost::enable_if<boost::is_integral<TSize>,
void>::type
158 std::vector<TReal> &res
162 res.assign(length , t );
163 std::partial_sum(res.begin(),res.end(),res.begin());
184 template <
typename InputIterator >
186 typename std::iterator_traits<InputIterator>::value_type
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. );
199 template <
typename TReal>
200 inline TReal
mean(
const std::vector<TReal> &
x )
202 TReal size =
static_cast<TReal
>(x.size());
203 TReal sum = std::accumulate(x.begin() , x.end(), 0. );
204 return ( sum / size ) ;
208 template <
typename TReal>
210 const std::vector<TReal> &
x,
218 TReal size =
static_cast<TReal
>(x.size());
219 std::vector<TReal> wc(x);
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 ) );
228 template<
class Iter_T>
229 typename std::iterator_traits<Iter_T>::value_type
geometricMean(Iter_T first, Iter_T last)
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);
236 typename std::vector<TReal>::iterator inputIt;
238 for(inputIt = copyOfInput.begin(); inputIt != copyOfInput.end() ; ++inputIt)
240 *inputIt = std::log(*inputIt);
244 TReal sum( std::accumulate(copyOfInput.begin(), copyOfInput.end(), TReal() ));
247 TReal geomean( std::exp(sum / cnt) );
254 template<
typename TReal>
256 const std::vector<TReal> & values,
257 std::pair<TReal,TReal> & range
260 TReal min = * std::min_element(values.begin(),values.end());
261 TReal max = * std::max_element(values.begin(),values.end());
268 inline double max3(T a, T b, T c)
281 template<
typename TReal>
287 return( log10( test ) / log10( static_cast<TReal>(2.) ));
double max3(T a, T b, T c)
maximum of 3 numbers
std::iterator_traits< InputIterator >::value_type mean(InputIterator begin, InputIterator end)
MEAN Trimmed arithmetic mean.
void seq(TReal from, TReal to, std::vector< TReal > &result)
generates the sequence from, from+/-1, ..., to (identical to from:to).
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...
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...
TReal log2(TReal test)
log base 2
EQUISPACEINTERPOL Interpolation on a equidistantly spaced grid.
std::iterator_traits< Iter_T >::value_type geometricMean(Iter_T first, Iter_T last)
computes the mean
KernelTraitsBase< Kernel >::space_type::abscissa_type x