34 #include <boost/utility/enable_if.hpp>
35 #include <boost/type_traits/is_integral.hpp>
46 template<
typename TReal>
51 std::vector<TReal> &result
55 typedef typename std::vector<TReal>::size_type size_type;
58 size_type length =
static_cast<size_type
>(to - from) + 1;
59 result.resize(length);
64 size_type length =
static_cast<size_type
>(from - to) + 1 ;
65 result.resize(length);
72 template<
typename TReal>
77 std::vector<TReal> &result
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 );
88 throw std::logic_error(std::string(
"by > 0" ));
90 for(; from <= to; from += by)
92 result.push_back(from);
98 throw std::logic_error(std::string(
"by < 0" ));
100 for(; from >= to; from += by)
102 result.push_back(from);
109 template<
typename TReal>
114 std::vector<TReal> &result
117 TReal by = ( ( to - from ) / ( static_cast<TReal>( length ) - 1. ) );
118 seq(from, to, by, result);
122 if(result.size() < length)
124 result.push_back(result[result.size()-1] + by );
128 result.resize(length);
137 template<
typename T1 ,
typename T2 >
140 std::vector<T1> & ref,
141 std::vector<T2> & res
145 res.assign(ref.size() , t );
146 std::partial_sum( res.begin() , res.end() , res.begin() );
153 template<
typename TSize,
typename TReal>
154 typename boost::enable_if<boost::is_integral<TSize>,
void>::type
157 std::vector<TReal> &res
161 res.assign(length , t );
162 std::partial_sum(res.begin(),res.end(),res.begin());
183 template <
typename InputIterator >
185 typename std::iterator_traits<InputIterator>::value_type
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. );
198 template <
typename TReal>
199 inline TReal
mean(
const std::vector<TReal> &
x )
201 TReal size =
static_cast<TReal
>(x.size());
202 TReal sum = std::accumulate(x.begin() , x.end(), 0. );
203 return ( sum / size ) ;
207 template <
typename TReal>
209 const std::vector<TReal> &
x,
217 TReal size =
static_cast<TReal
>(x.size());
218 std::vector<TReal> wc(x);
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 ) );
227 template<
class Iter_T>
228 typename std::iterator_traits<Iter_T>::value_type
geometricMean(Iter_T first, Iter_T last)
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);
235 typename std::vector<TReal>::iterator inputIt;
237 for(inputIt = copyOfInput.begin(); inputIt != copyOfInput.end() ; ++inputIt)
239 *inputIt = std::log(*inputIt);
243 TReal sum( std::accumulate(copyOfInput.begin(), copyOfInput.end(), TReal() ));
246 TReal geomean( std::exp(sum / cnt) );
253 template<
typename TReal>
255 const std::vector<TReal> & values,
256 std::pair<TReal,TReal> & range
259 TReal min = * std::min_element(values.begin(),values.end());
260 TReal max = * std::max_element(values.begin(),values.end());
267 inline double max3(T a, T b, T c)
280 template<
typename TReal>
286 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
std::iterator_traits< Iter_T >::value_type geometricMean(Iter_T first, Iter_T last)
computes the mean
KernelTraitsBase< Kernel >::space_type::abscissa_type x