bpp-core  2.4.0
bpp::VectorTools Class Reference

#include <Bpp/Numeric/VectorTools.h>

Classes

class  order_Cmp_
 

Public Member Functions

 VectorTools ()
 
virtual ~VectorTools ()
 

Static Public Member Functions

template<class T >
static void fill (std::vector< T > &v, T value)
 
template<class T >
static std::vector< T > seq (T from, T to, T by)
 Build a sequence std::vector. More...
 
template<class T >
static size_t which (const std::vector< T > &v, const T &which)
 Send the position of the first occurence of 'which'. More...
 
template<class T >
static std::vector< size_t > whichAll (const std::vector< T > &v, const T &which)
 Send the positions of all occurences of 'which'. More...
 
template<class T >
static std::vector< T > unique (const std::vector< T > &v)
 Send a new std::vector with unique elements. More...
 
template<class T >
static bool isUnique (const std::vector< T > &v)
 Tell if the std::vector as unique elements. More...
 
template<class T >
static std::vector< T > extract (const std::vector< T > &v1, const std::vector< int > &v2)
 
template<class T >
static std::map< T, size_t > countValues (const std::vector< T > &v)
 Count each element of a std::vector. More...
 
static std::vector< double > breaks (const std::vector< double > &v, unsigned int n)
 Get the break points for a given number of classes. More...
 
template<class T >
static size_t nclassScott (const std::vector< T > &v)
 Get the optimal class number following Scott's method. More...
 
template<class T >
static T prod (const std::vector< T > &v1)
 
template<class T >
static std::vector< T > cumProd (const std::vector< T > &v1)
 
template<class T >
static T sum (const std::vector< T > &v1)
 
template<class T >
static std::vector< T > cumSum (const std::vector< T > &v1)
 
template<class T >
static void logNorm (std::vector< T > &v)
 
template<class T >
static T logSumExp (const std::vector< T > &v1)
 
template<class T >
static T logSumExp (const std::vector< T > &v1, const std::vector< T > &v2)
 
template<class T >
static T logMeanExp (const std::vector< T > &v1)
 
template<class T >
static T sumExp (const std::vector< T > &v1)
 
template<class T >
static T sumExp (const std::vector< T > &v1, const std::vector< T > &v2)
 
template<class T >
static std::string paste (const std::vector< T > &v, const std::string &delim=" ")
 Concatenate a std::vector after converting to string. More...
 
template<class T >
static void print (const std::vector< T > &v1, OutputStream &out=*ApplicationTools::message, const std::string &delim=" ")
 Print a std::vector to a stream. More...
 
template<class T >
static void printRange (const std::vector< T > &v1, OutputStream &out=*ApplicationTools::message, const std::string &delim=",", const std::string &rangeDelim="-")
 
template<class T >
static void printForR (const std::vector< T > &v1, std::string variableName="x", std::ostream &out=std::cout)
 Print a std::vector to a stream in R format. More...
 
template<class InputType , class OutputType >
static OutputType scalar (const std::vector< InputType > &v1, const std::vector< InputType > &v2)
 
template<class InputType , class OutputType >
static OutputType scalar (const std::vector< InputType > &v1, const std::vector< InputType > &v2, const std::vector< InputType > &w)
 
template<class T >
static std::vector< T > kroneckerMult (const std::vector< T > &v1, const std::vector< T > &v2)
 
template<class InputType , class OutputType >
static OutputType norm (const std::vector< InputType > &v1)
 
template<class InputType , class OutputType >
static OutputType norm (const std::vector< InputType > &v1, const std::vector< InputType > &w)
 
template<class InputType , class OutputType >
static OutputType cos (const std::vector< InputType > &v1, const std::vector< InputType > &v2)
 
template<class InputType , class OutputType >
static OutputType cos (const std::vector< InputType > &v1, const std::vector< InputType > &v2, const std::vector< InputType > &w)
 
template<class T >
static std::vector< T > abs (const std::vector< T > &v)
 Template function to get the absolute value of all elements of a std::vector. More...
 
template<class InputType , class OutputType >
static OutputType mean (const std::vector< InputType > &v1)
 
template<class InputType , class OutputType >
static OutputType mean (const std::vector< InputType > &v1, const std::vector< InputType > &w, bool normalizeWeights=true)
 
template<class InputType >
static InputType median (std::vector< InputType > &v1)
 
template<class InputType , class OutputType >
static std::vector< OutputType > center (const std::vector< InputType > &v1)
 Set the mean of a std::vector to be 0. More...
 
template<class InputType , class OutputType >
static std::vector< OutputType > center (const std::vector< InputType > &v1, const std::vector< InputType > &w, bool normalizeWeights=true)
 Set the weighted mean of a std::vector to be 0. More...
 
template<class InputType , class OutputType >
static OutputType cov (const std::vector< InputType > &v1, const std::vector< InputType > &v2, bool unbiased=true)
 
template<class InputType , class OutputType >
static OutputType cov (const std::vector< InputType > &v1, const std::vector< InputType > &v2, const std::vector< InputType > &w, bool unbiased=true, bool normalizeWeights=true)
 
template<class InputType , class OutputType >
static OutputType var (const std::vector< InputType > &v1, bool unbiased=true)
 
template<class InputType , class OutputType >
static OutputType var (const std::vector< InputType > &v1, const std::vector< InputType > &w, bool unbiased=true, bool normalizeWeights=true)
 
template<class InputType , class OutputType >
static OutputType sd (const std::vector< InputType > &v1, bool unbiased=true)
 
template<class InputType , class OutputType >
static OutputType sd (const std::vector< InputType > &v1, const std::vector< InputType > &w, bool unbiased=true, bool normalizeWeights=true)
 
template<class InputType , class OutputType >
static OutputType cor (const std::vector< InputType > &v1, const std::vector< InputType > &v2)
 
template<class InputType , class OutputType >
static OutputType cor (const std::vector< InputType > &v1, const std::vector< InputType > &v2, const std::vector< InputType > &w, bool normalizeWeights=true)
 
template<class InputType , class OutputType >
static OutputType shannon (const std::vector< InputType > &v, double base=2.7182818)
 
template<class InputType , class OutputType >
static OutputType shannonDiscrete (const std::vector< InputType > &v, double base=2.7182818)
 
template<class InputType , class OutputType >
static OutputType miDiscrete (const std::vector< InputType > &v1, const std::vector< InputType > &v2, double base=2.7182818)
 
template<class InputType , class OutputType >
static OutputType shannonContinuous (const std::vector< InputType > &v, double base=2.7182818)
 
template<class InputType , class OutputType >
static OutputType miContinuous (const std::vector< InputType > &v1, const std::vector< InputType > &v2, double base=2.7182818)
 
template<class T >
static bool haveSameElements (const std::vector< T > &v1, const std::vector< T > &v2)
 
template<class T >
static bool haveSameElements (std::vector< T > &v1, std::vector< T > &v2)
 
template<class T >
static bool contains (const std::vector< T > &vec, T el)
 
template<class T , class U >
static bool contains (const std::vector< T > &vec, U el)
 
template<class T >
static bool containsAll (std::vector< T > &v1, std::vector< T > &v2)
 
template<class T >
static std::vector< T > vectorUnion (const std::vector< T > &vec1, const std::vector< T > &vec2)
 
template<class T >
static std::vector< T > vectorUnion (const std::vector< std::vector< T > > &vecElementL)
 
template<class T >
static std::vector< T > vectorIntersection (const std::vector< T > &vec1, const std::vector< T > &vec2)
 
template<class T , class U >
static std::vector< T > vectorIntersection (const std::vector< T > &vec1, const std::vector< U > &vec2)
 
template<class T >
static std::vector< T > vectorIntersection (const std::vector< std::vector< T > > &vecElementL)
 
template<class T >
static void append (std::vector< T > &vec1, const std::vector< T > &vec2)
 Append the content of a std::vector to another one. More...
 
template<class T >
static void prepend (std::vector< T > &vec1, const std::vector< T > &vec2)
 Prepend the content of a std::vector to another one. More...
 
template<class T >
static std::vector< T > append (const std::vector< std::vector< T > > &vecElementL)
 
template<class T >
static void extend (std::vector< T > &vec1, const std::vector< T > &vec2)
 Extend the content of a std::vector with another one. Only the elements not present in the first vector will be added. More...
 
template<class T >
static std::vector< T > rep (const std::vector< T > &vec, size_t n)
 
template<class T >
static void diff (std::vector< T > &v1, std::vector< T > &v2, std::vector< T > &v3)
 This function returns the difference of two std::vectors. More...
 
static bool test ()
 Test function. More...
 
Matrix-like functions to resize arrays.
static void resize2 (VVdouble &vv, size_t n1, size_t n2)
 
static void resize3 (VVVdouble &vvv, size_t n1, size_t n2, size_t n3)
 
static void resize4 (VVVVdouble &vvvv, size_t n1, size_t n2, size_t n3, size_t n4)
 
These methods apply the corresponding function to each element

and return the result in a new std::vector.

template<class T >
static std::vector< T > log (const std::vector< T > &v1)
 
template<class T >
static double log (const T &x)
 
template<class T >
static std::vector< double > log (const std::vector< T > &v1, double base)
 
template<class T >
static double exp (const T &x)
 
template<class T >
static std::vector< T > exp (const std::vector< T > &v1)
 
template<class T >
static std::vector< double > cos (const std::vector< T > &v1)
 
template<class T >
static std::vector< double > sin (const std::vector< T > &v1)
 
template<class T >
static std::vector< double > log10 (const std::vector< T > &v1)
 
template<class T >
static std::vector< T > fact (const std::vector< T > &v1)
 
template<class T >
static std::vector< T > sqr (const std::vector< T > &v1)
 
template<class T >
static std::vector< T > pow (const std::vector< T > &v1, T &b)
 
Extrema.
template<class T >
static T min (const std::vector< T > &v)
 Template function to get the minimum value of a std::vector. More...
 
template<class T >
static T max (const std::vector< T > &v)
 Template function to get the maximum value of a std::vector. More...
 
template<class T >
static size_t whichMax (const std::vector< T > &v)
 Template function to get the index of the maximum value of a std::vector. More...
 
template<class T >
static size_t whichMin (const std::vector< T > &v)
 Template function to get the index of the minimum value of a std::vector. More...
 
template<class T >
static std::vector< size_t > whichMaxAll (const std::vector< T > &v)
 Template function to get the indices of the maximum value of a std::vector. More...
 
template<class T >
static std::vector< size_t > whichMinAll (const std::vector< T > &v)
 Template function to get the indices of the minimum value of a std::vector. More...
 
template<class T >
static std::vector< T > range (const std::vector< T > &v)
 Template function to get both extrema of a std::vector. More...
 
template<class T >
static std::vector< size_t > order (const std::vector< T > &v)
 Template function to get the order of elements in the input vector. More...
 

Detailed Description

Definition at line 342 of file VectorTools.h.

Constructor & Destructor Documentation

bpp::VectorTools::VectorTools ( )
inline

Definition at line 345 of file VectorTools.h.

virtual bpp::VectorTools::~VectorTools ( )
inlinevirtual

Definition at line 346 of file VectorTools.h.

Member Function Documentation

template<class T >
static std::vector<T> bpp::VectorTools::abs ( const std::vector< T > &  v)
inlinestatic

Template function to get the absolute value of all elements of a std::vector.

Parameters
vThe input std::vector.
Returns
A vector with all absolute values.

Definition at line 1315 of file VectorTools.h.

template<class T >
static void bpp::VectorTools::append ( std::vector< T > &  vec1,
const std::vector< T > &  vec2 
)
inlinestatic

Append the content of a std::vector to another one.

Parameters
vec1Vector 1.
vec2Vector 2.

Definition at line 1916 of file VectorTools.h.

Referenced by diff(), bpp::AbstractParameterAliasable::getAlias(), and bpp::NumCalcApplicationTools::seqFromString().

template<class T >
static std::vector<T> bpp::VectorTools::append ( const std::vector< std::vector< T > > &  vecElementL)
inlinestatic
Returns
A single std::vector made of the concatenation of the std::vectors passed as input.
Parameters
vecElementLA std::vector of std::vectors.

Definition at line 1938 of file VectorTools.h.

vector< double > VectorTools::breaks ( const std::vector< double > &  v,
unsigned int  n 
)
static

Get the break points for a given number of classes.

Given a std::vector of values, return the values that cut the range of values in a given number of classes.

Parameters
vThe std::vector to parse.
nThe expected number of classes.
Returns
a std::vector of size = n + 1 containing the breaking points.

Definition at line 53 of file VectorTools.cpp.

References range().

Referenced by countValues().

template<class InputType , class OutputType >
static std::vector<OutputType> bpp::VectorTools::center ( const std::vector< InputType > &  v1)
inlinestatic

Set the mean of a std::vector to be 0.

Returns
A std::vector with mean 0.
Parameters
v1A std::vector.

Definition at line 1386 of file VectorTools.h.

template<class InputType , class OutputType >
static std::vector<OutputType> bpp::VectorTools::center ( const std::vector< InputType > &  v1,
const std::vector< InputType > &  w,
bool  normalizeWeights = true 
)
inlinestatic

Set the weighted mean of a std::vector to be 0.

Returns
A std::vector with mean 0.
Parameters
v1A std::vector.
wA std::vector of weights.
normalizeWeightsTell if weights should be normalized so that they sum to 1.

Definition at line 1405 of file VectorTools.h.

template<class T >
static bool bpp::VectorTools::contains ( const std::vector< T > &  vec,
el 
)
inlinestatic
Returns
'true' if a the input std::vector contains the given element.
Parameters
vecThe std::vector to check.
elThe element to look for.

Definition at line 1781 of file VectorTools.h.

Referenced by extend(), bpp::DataTable::setRowName(), vectorIntersection(), and vectorUnion().

template<class T , class U >
static bool bpp::VectorTools::contains ( const std::vector< T > &  vec,
el 
)
inlinestatic

Definition at line 1791 of file VectorTools.h.

template<class T >
static bool bpp::VectorTools::containsAll ( std::vector< T > &  v1,
std::vector< T > &  v2 
)
inlinestatic
Returns
'true' if a the first std::vector contains all elements of the second std::vector.
Warning
The two input std::vectors will be sorted.
Parameters
v1The first std::vector to check.
v2The second std::vector to check.

Definition at line 1809 of file VectorTools.h.

template<class InputType , class OutputType >
static OutputType bpp::VectorTools::cor ( const std::vector< InputType > &  v1,
const std::vector< InputType > &  v2 
)
inlinestatic
Returns
The Pearson correlation coefficient of two std::vectors.
Parameters
v1First std::vector.
v2Second std::vector.
Exceptions
DimensionExceptionIf the two std::vector do not have the same length.

Definition at line 1532 of file VectorTools.h.

template<class InputType , class OutputType >
static OutputType bpp::VectorTools::cor ( const std::vector< InputType > &  v1,
const std::vector< InputType > &  v2,
const std::vector< InputType > &  w,
bool  normalizeWeights = true 
)
inlinestatic
Returns
The weighted Pearson correlation coefficient of two std::vectors.
Parameters
v1First std::vector.
v2Second std::vector.
wA std::vector of weights.
normalizeWeightsTell if weights should be normalized so that they sum to 1.
Exceptions
DimensionExceptionIf the two std::vector do not have the same length.

Definition at line 1547 of file VectorTools.h.

References sum().

template<class T >
static std::vector<double> bpp::VectorTools::cos ( const std::vector< T > &  v1)
inlinestatic

Definition at line 817 of file VectorTools.h.

template<class InputType , class OutputType >
static OutputType bpp::VectorTools::cos ( const std::vector< InputType > &  v1,
const std::vector< InputType > &  v2 
)
inlinestatic
Returns
The cosinus of the angle of two std::vectors.
Parameters
v1First std::vector.
v2Second std::vector.
Exceptions
DimensionExceptionIf the two std::vector do not have the same length.

Definition at line 1071 of file VectorTools.h.

template<class InputType , class OutputType >
static OutputType bpp::VectorTools::cos ( const std::vector< InputType > &  v1,
const std::vector< InputType > &  v2,
const std::vector< InputType > &  w 
)
inlinestatic
Returns
The weighted cosinus of the angle of two std::vectors.
Parameters
v1First std::vector.
v2Second std::vector.
wA std::vector of weights.
Exceptions
DimensionExceptionIf the two std::vector do not have the same length.

Definition at line 1085 of file VectorTools.h.

template<class T >
static std::map<T, size_t> bpp::VectorTools::countValues ( const std::vector< T > &  v)
inlinestatic

Count each element of a std::vector.

Returns
A map with keys = unique std::vector values and values = count for each std::vector value.
Parameters
vthe std::vector to parse.

Definition at line 543 of file VectorTools.h.

References breaks().

template<class InputType , class OutputType >
static OutputType bpp::VectorTools::cov ( const std::vector< InputType > &  v1,
const std::vector< InputType > &  v2,
bool  unbiased = true 
)
inlinestatic
Returns
The covariance of two std::vectors.
Parameters
v1First std::vector.
v2Second std::vector.
unbiasedTell if an unbiased estimate must be computed.
Exceptions
DimensionExceptionIf the two std::vector do not have the same length.

Definition at line 1424 of file VectorTools.h.

template<class InputType , class OutputType >
static OutputType bpp::VectorTools::cov ( const std::vector< InputType > &  v1,
const std::vector< InputType > &  v2,
const std::vector< InputType > &  w,
bool  unbiased = true,
bool  normalizeWeights = true 
)
inlinestatic
Returns
The weighted covariance of two std::vectors. To have a population estimate you have to multiply by $\frac{n}{n-1}$.
Parameters
v1First std::vector.
v2Second std::vector.
wA std::vector of weights.
unbiasedTell if an unbiased estimate must be computed.
normalizeWeightsTell if weights should be normalized so that they sum to 1.
Exceptions
DimensionExceptionIf the two std::vector do not have the same length.

Definition at line 1446 of file VectorTools.h.

References sqr(), and sum().

template<class T >
static std::vector<T> bpp::VectorTools::cumProd ( const std::vector< T > &  v1)
inlinestatic
Returns
The cumulative product of all elements in a std::vector.
Parameters
v1A std::vector.
Author
Julien Dutheil

Definition at line 604 of file VectorTools.h.

template<class T >
static std::vector<T> bpp::VectorTools::cumSum ( const std::vector< T > &  v1)
inlinestatic
Returns
The cumulative sum of all elements in a std::vector.
Parameters
v1A std::vector.
Author
Julien Dutheil

Definition at line 631 of file VectorTools.h.

Referenced by bpp::RandomTools::pickOne().

template<class T >
static void bpp::VectorTools::diff ( std::vector< T > &  v1,
std::vector< T > &  v2,
std::vector< T > &  v3 
)
inlinestatic

This function returns the difference of two std::vectors.

Warning
The two input std::vectors will be sorted. As a consequence, the output std::vector will be also sorted.
Parameters
v1First std::vector.
v2Second std::vector.
v3A std::vector to be populated with all elements in v1 that are not found in v2.

Definition at line 1994 of file VectorTools.h.

References append(), and test().

template<class T >
static double bpp::VectorTools::exp ( const T &  x)
inlinestatic

Definition at line 803 of file VectorTools.h.

Referenced by bpp::MatrixTools::exp(), and exp().

template<class T >
static std::vector<T> bpp::VectorTools::exp ( const std::vector< T > &  v1)
inlinestatic

Definition at line 809 of file VectorTools.h.

References exp().

template<class T >
static void bpp::VectorTools::extend ( std::vector< T > &  vec1,
const std::vector< T > &  vec2 
)
inlinestatic

Extend the content of a std::vector with another one. Only the elements not present in the first vector will be added.

Parameters
vec1Vector 1.
vec2Vector 2.

Definition at line 1956 of file VectorTools.h.

References contains().

template<class T >
static std::vector<T> bpp::VectorTools::extract ( const std::vector< T > &  v1,
const std::vector< int > &  v2 
)
inlinestatic
Author
Laurent Gueguen
Parameters
v1the std::vector of elements,
v2the std::vector of the selected positions
Returns
the std::vector of the selected elements, in the order of the required positions

Definition at line 526 of file VectorTools.h.

template<class T >
static std::vector<T> bpp::VectorTools::fact ( const std::vector< T > &  v1)
inlinestatic

Definition at line 841 of file VectorTools.h.

template<class T >
static void bpp::VectorTools::fill ( std::vector< T > &  v,
value 
)
inlinestatic
template<class T >
static bool bpp::VectorTools::haveSameElements ( const std::vector< T > &  v1,
const std::vector< T > &  v2 
)
inlinestatic
Returns
'true' if the two std::vectors contains the same elements, whatever their order in the container.
Parameters
v1First std::vector.
v2Second std::vector.

Definition at line 1748 of file VectorTools.h.

template<class T >
static bool bpp::VectorTools::haveSameElements ( std::vector< T > &  v1,
std::vector< T > &  v2 
)
inlinestatic
Returns
'true' if the two std::vectors contains the same elements, in the same frequency, whatever their order in the container.
Warning
The two input std::vectors will be sorted.
Parameters
v1First std::vector.
v2Second std::vector.

Definition at line 1767 of file VectorTools.h.

template<class T >
static bool bpp::VectorTools::isUnique ( const std::vector< T > &  v)
inlinestatic

Tell if the std::vector as unique elements.

The input std::vector is copied, and the copy is sorted using QuickSort algorithm. A one-pass loop then look for duplicates.

If v is empty, the method returns 'true'.

Parameters
vthe std::vector to parse.

Definition at line 506 of file VectorTools.h.

Referenced by bpp::DataTable::setColumnNames(), bpp::Table< T >::setColumnNames(), bpp::DataTable::setRowNames(), and bpp::Table< T >::setRowNames().

template<class T >
static std::vector<T> bpp::VectorTools::kroneckerMult ( const std::vector< T > &  v1,
const std::vector< T > &  v2 
)
inlinestatic
Returns
The scalar Kronecker product of two std::vectors.
Parameters
v1First std::vector.
v2Second std::vector.
Exceptions
DimensionExceptionIf the two std::vector do not have the same length.

Definition at line 1011 of file VectorTools.h.

template<class T >
static std::vector<T> bpp::VectorTools::log ( const std::vector< T > &  v1)
inlinestatic

Definition at line 781 of file VectorTools.h.

template<class T >
static double bpp::VectorTools::log ( const T &  x)
inlinestatic

Definition at line 789 of file VectorTools.h.

template<class T >
static std::vector<double> bpp::VectorTools::log ( const std::vector< T > &  v1,
double  base 
)
inlinestatic

Definition at line 795 of file VectorTools.h.

template<class T >
static std::vector<double> bpp::VectorTools::log10 ( const std::vector< T > &  v1)
inlinestatic

Definition at line 833 of file VectorTools.h.

template<class T >
static T bpp::VectorTools::logMeanExp ( const std::vector< T > &  v1)
inlinestatic
Author
Laurent Gueguen
Returns
From std::vector v1, return $\log(\textrm{mean}_i(\exp(v1_i)))$.
Parameters
v1a std::vector.

Definition at line 711 of file VectorTools.h.

References max().

template<class T >
static void bpp::VectorTools::logNorm ( std::vector< T > &  v)
inlinestatic
Author
Laurent Gueguen
Returns
Log-normalize std::vector v1, ie add a constant to the elements of v such that $\sum_i(\exp(v_i)) = 1$.
Parameters
vstd::vector.

Definition at line 647 of file VectorTools.h.

References max().

template<class T >
static T bpp::VectorTools::logSumExp ( const std::vector< T > &  v1)
inlinestatic
Author
Laurent Gueguen
Returns
From std::vector v1, return $\log(\sum_i(\exp(v1_i)))$.
Parameters
v1a std::vector.

Definition at line 664 of file VectorTools.h.

References max().

template<class T >
static T bpp::VectorTools::logSumExp ( const std::vector< T > &  v1,
const std::vector< T > &  v2 
)
inlinestatic
Author
Laurent Gueguen
Returns
From std::vector v1, return $\log(\sum_i(v2_i * \exp(v1_i)))$.
Parameters
v1a std::vector.
v2another std::vector.

Definition at line 685 of file VectorTools.h.

References max().

template<class T >
static T bpp::VectorTools::max ( const std::vector< T > &  v)
inlinestatic

Template function to get the maximum value of a std::vector.

The > operator must be defined for the specified class.

Parameters
vThe input std::vector.
Returns
The maximum value in the std::vector.
Exceptions
EmptyVectorExceptionIf the input std::vector is empty.

Definition at line 1128 of file VectorTools.h.

Referenced by logMeanExp(), logNorm(), logSumExp(), sumExp(), and whichMaxAll().

template<class InputType , class OutputType >
static OutputType bpp::VectorTools::mean ( const std::vector< InputType > &  v1)
inlinestatic
Returns
The mean value of the std::vector.
Parameters
v1A std::vector.

Definition at line 1330 of file VectorTools.h.

template<class InputType , class OutputType >
static OutputType bpp::VectorTools::mean ( const std::vector< InputType > &  v1,
const std::vector< InputType > &  w,
bool  normalizeWeights = true 
)
inlinestatic
Returns
The weighted mean value of the std::vector.
Parameters
v1A std::vector.
wA std::vector of weights.
normalizeWeightsTell if weights should be normalized so that they sum to 1.

Definition at line 1341 of file VectorTools.h.

References sum().

template<class InputType >
static InputType bpp::VectorTools::median ( std::vector< InputType > &  v1)
inlinestatic
Returns
The median value of the std::vector.
Parameters
v1A std::vector.

Definition at line 1359 of file VectorTools.h.

template<class InputType , class OutputType >
static OutputType bpp::VectorTools::miContinuous ( const std::vector< InputType > &  v1,
const std::vector< InputType > &  v2,
double  base = 2.7182818 
)
inlinestatic
Returns
Compute mutual information index from two samples from continuous variables.

This is the continuous version. Each vector is supposed to be a finite sample from a continuous distribution. The density is of the distribution is estimated using a kernel method, as well as the joint density, and are used to compute the continuous mutual information.

Reference: Ivan Kojadinovic (2004) Computational Statistics & Data Analysis, 46:269-294

Author
Julien Dutheil
See also
miDiscrete For the discrete version.
Warning
This function is experimental. Notably, bad kernel density estimates may lead to negative MI :(
Parameters
v1The first input vector.
v2The second input vector.
baseThe base of the logarithm to use.
Exceptions
DimensionExceptionif the two vectors do not have the same lengths.

Definition at line 1714 of file VectorTools.h.

References bpp::AdaptiveKernelDensityEstimation::kDensity().

template<class InputType , class OutputType >
static OutputType bpp::VectorTools::miDiscrete ( const std::vector< InputType > &  v1,
const std::vector< InputType > &  v2,
double  base = 2.7182818 
)
inlinestatic
Returns
Compute mutual information index from two samples from discrete variables.

This is the discrete version. Each vector is supposed to be a finite sample from a discrete distribution. The counts of each (joint) observed state are computed and used to compute the discrete mutual information.

Author
Julien Dutheil
See also
miContinuous.
Parameters
v1The first input vector.
v2The second input vector.
baseThe base of the logarithm to use.
Exceptions
DimensionExceptionif the two vectors do not have the same lengths.

Definition at line 1635 of file VectorTools.h.

template<class T >
static T bpp::VectorTools::min ( const std::vector< T > &  v)
inlinestatic

Template function to get the minimum value of a std::vector.

The < operator must be defined for the specified class.

Parameters
vThe input std::vector.
Returns
The minimum value in the std::vector.
Exceptions
EmptyVectorExceptionIf the input std::vector is empty.

Definition at line 1107 of file VectorTools.h.

Referenced by whichMinAll().

template<class T >
static size_t bpp::VectorTools::nclassScott ( const std::vector< T > &  v)
inlinestatic

Get the optimal class number following Scott's method.

Use Scott's (1979) method to compute the optimal class number for histogram.

Scott, D.W. (1979) On optimal and data-based histograms. Biometrika, 66, 605¿610.

Parameters
vThe std::vector to parse.
Returns
The number of classes.

Definition at line 576 of file VectorTools.h.

References range().

template<class InputType , class OutputType >
static OutputType bpp::VectorTools::norm ( const std::vector< InputType > &  v1)
inlinestatic
Returns
The norm of a std::vector ( $\sqrt{\sum_i^n x_i^2}$).
Parameters
v1A std::vector.

Definition at line 1032 of file VectorTools.h.

template<class InputType , class OutputType >
static OutputType bpp::VectorTools::norm ( const std::vector< InputType > &  v1,
const std::vector< InputType > &  w 
)
inlinestatic
Returns
The "weighted" norm of a std::vector ( $\sqrt{\sum_i^n x_i^2}$).
Parameters
v1A std::vector.
wA std::vector of weights.
Exceptions
DimensionExceptionIf v1 and w do not have the same length.
See also
scalar.

Definition at line 1050 of file VectorTools.h.

template<class T >
static std::vector<size_t> bpp::VectorTools::order ( const std::vector< T > &  v)
inlinestatic

Template function to get the order of elements in the input vector.

This function is equivalent to the R 'order' function. It will sort elements by increasing size, so that [0] in the resulting outptu vector is the indice of the minimum element in the input vector, [1] is the second minimum, etc.

Parameters
vThe input std::vector.
Returns
Vector with sorted positions, according to input vector. throw EmptyVectorException If the input std::vector is empty.

Definition at line 1291 of file VectorTools.h.

template<class T >
static std::string bpp::VectorTools::paste ( const std::vector< T > &  v,
const std::string &  delim = " " 
)
inlinestatic

Concatenate a std::vector after converting to string.

Parameters
vThe std::vector to concatenate.
delimA string which is used to separate the values (default is " ").

Definition at line 872 of file VectorTools.h.

Referenced by bpp::TreeGraphImpl< GraphImpl >::getFather().

template<class T >
static std::vector<T> bpp::VectorTools::pow ( const std::vector< T > &  v1,
T &  b 
)
inlinestatic

Definition at line 857 of file VectorTools.h.

Referenced by bpp::MatrixTools::pow().

template<class T >
static void bpp::VectorTools::prepend ( std::vector< T > &  vec1,
const std::vector< T > &  vec2 
)
inlinestatic

Prepend the content of a std::vector to another one.

Parameters
vec1Vector 1.
vec2Vector 2.

Definition at line 1927 of file VectorTools.h.

template<class T >
static void bpp::VectorTools::print ( const std::vector< T > &  v1,
OutputStream out = ApplicationTools::message,
const std::string &  delim = " " 
)
inlinestatic

Print a std::vector to a stream.

Parameters
v1A std::vector.
outA stream.
delimA string which is used to separate the values (default is " ").

Definition at line 892 of file VectorTools.h.

template<class T >
static void bpp::VectorTools::printForR ( const std::vector< T > &  v1,
std::string  variableName = "x",
std::ostream &  out = std::cout 
)
inlinestatic

Print a std::vector to a stream in R format.

Parameters
v1A std::vector.
variableNamethe variable name (default "x").
outA stream (default cout).

Definition at line 936 of file VectorTools.h.

template<class T >
static void bpp::VectorTools::printRange ( const std::vector< T > &  v1,
OutputStream out = ApplicationTools::message,
const std::string &  delim = ",",
const std::string &  rangeDelim = "-" 
)
inlinestatic

Definition at line 904 of file VectorTools.h.

template<class T >
static T bpp::VectorTools::prod ( const std::vector< T > &  v1)
inlinestatic
Returns
The product of all elements in a std::vector.
Parameters
v1A std::vector.

Definition at line 590 of file VectorTools.h.

template<class T >
static std::vector<T> bpp::VectorTools::range ( const std::vector< T > &  v)
inlinestatic

Template function to get both extrema of a std::vector.

Both < and > operators must be defined for the specified class.

Parameters
vThe input std::vector.
Returns
A std::vector of size 2 which values are min(v) and max(v). throw EmptyVectorException If the input std::vector is empty.

Definition at line 1256 of file VectorTools.h.

Referenced by breaks(), and nclassScott().

template<class T >
static std::vector<T> bpp::VectorTools::rep ( const std::vector< T > &  vec,
size_t  n 
)
inlinestatic
Returns
A single std::vector made of the repetion of the std::vectors passed as input.
Parameters
vecA std::vector.
nthe number of repetitions

Definition at line 1971 of file VectorTools.h.

static void bpp::VectorTools::resize2 ( VVdouble vv,
size_t  n1,
size_t  n2 
)
inlinestatic

Definition at line 355 of file VectorTools.h.

static void bpp::VectorTools::resize3 ( VVVdouble vvv,
size_t  n1,
size_t  n2,
size_t  n3 
)
inlinestatic

Definition at line 361 of file VectorTools.h.

static void bpp::VectorTools::resize4 ( VVVVdouble vvvv,
size_t  n1,
size_t  n2,
size_t  n3,
size_t  n4 
)
inlinestatic

Definition at line 374 of file VectorTools.h.

template<class InputType , class OutputType >
static OutputType bpp::VectorTools::scalar ( const std::vector< InputType > &  v1,
const std::vector< InputType > &  v2 
)
inlinestatic
Returns
The scalar product of two std::vectors.
Parameters
v1First std::vector.
v2Second std::vector.
Exceptions
DimensionExceptionIf the two std::vector do not have the same length.

Definition at line 956 of file VectorTools.h.

template<class InputType , class OutputType >
static OutputType bpp::VectorTools::scalar ( const std::vector< InputType > &  v1,
const std::vector< InputType > &  v2,
const std::vector< InputType > &  w 
)
inlinestatic

This dt product correspond to the dot product <v1,v2> in the space defined by

\[ M = \begin{pmatrix} w_1 & \ldots & \\ \vdots & w_2 & \ldots\\ & \vdots & \ddots\\ \end{pmatrix} \]

Returns
The "weighted" scalar product of two std::vectors.
Parameters
v1First std::vector.
v2Second std::vector.
wA std::vector of weights.
Exceptions
DimensionExceptionIf the two std::vector do not have the same length or do not match the length of the weights.

Definition at line 986 of file VectorTools.h.

template<class InputType , class OutputType >
static OutputType bpp::VectorTools::sd ( const std::vector< InputType > &  v1,
bool  unbiased = true 
)
inlinestatic
Returns
The standard deviation of the std::vector.
Parameters
v1The sample std::vector.
unbiasedTell if an unbiased estimate must be computed.

Definition at line 1506 of file VectorTools.h.

template<class InputType , class OutputType >
static OutputType bpp::VectorTools::sd ( const std::vector< InputType > &  v1,
const std::vector< InputType > &  w,
bool  unbiased = true,
bool  normalizeWeights = true 
)
inlinestatic
Returns
The weighted standard deviation of the std::vector.
Parameters
v1The sample std::vector.
wA std::vector of weights.
unbiasedTell if an unbiased estimate must be computed.
normalizeWeightsTell if weights should be normalized so that they sum to 1.
Exceptions
DimensionExceptionIf v1 and w do not have the same length.

Definition at line 1520 of file VectorTools.h.

template<class T >
static std::vector<T> bpp::VectorTools::seq ( from,
to,
by 
)
inlinestatic

Build a sequence std::vector.

Build a std::vector from a value to another with a specified step. This works for numerical values for which additions, subtractions and division makes sens.

Parameters
fromThe begining (included).
toThe end (included)
byThe step.
Returns
A std::vector containing the sequence.

Definition at line 412 of file VectorTools.h.

Referenced by bpp::NumCalcApplicationTools::seqFromString().

template<class InputType , class OutputType >
static OutputType bpp::VectorTools::shannon ( const std::vector< InputType > &  v,
double  base = 2.7182818 
)
inlinestatic
Returns
Compute the Shannon entropy indice of a vector of frequencies.

The elements of the vector should contain frequencies of each modality of the variable and sum to one. This verification is left to the user though.

Author
Julien Dutheil
See also
shannonDiscrete for computing the shannon indice of a sample, discrete version.
shannonContinuous for computing the shannon indice of a sample, continuous version.
Parameters
vThe input std::vector.
baseThe base of the logarithm to use.

Definition at line 1577 of file VectorTools.h.

template<class InputType , class OutputType >
static OutputType bpp::VectorTools::shannonContinuous ( const std::vector< InputType > &  v,
double  base = 2.7182818 
)
inlinestatic
Returns
Compute the Shannon entropy indice of a sample from a continuous variable.

This is the continuous version. The vector is supposed to be a finite sample from a continuous distribution. The density is of the distribution is estimated using a kernel method, and is used to compute the continuous entropy.

Reference: Ivan Kojadinovic (2004) Computational Statistics & Data Analysis, 46:269-294

Author
Julien Dutheil
See also
shannon For the discrete version.
Parameters
vThe input std::vector.
baseThe base of the logarithm to use.

Definition at line 1676 of file VectorTools.h.

References bpp::AdaptiveKernelDensityEstimation::kDensity().

template<class InputType , class OutputType >
static OutputType bpp::VectorTools::shannonDiscrete ( const std::vector< InputType > &  v,
double  base = 2.7182818 
)
inlinestatic
Returns
Compute the Shannon entropy indice of a vector.

This is the discrete version. The vector is supposed to be a finite sample from a discrete distribution. The counts of each observed state are computed and used to compute the discrete entropy.

Author
Julien Dutheil
See also
shannonContinuous for the continuous version.
shannon for direct computation from frequencies.
Parameters
vThe input std::vector.
baseThe base of the logarithm to use.

Definition at line 1603 of file VectorTools.h.

template<class T >
static std::vector<double> bpp::VectorTools::sin ( const std::vector< T > &  v1)
inlinestatic

Definition at line 825 of file VectorTools.h.

template<class T >
static std::vector<T> bpp::VectorTools::sqr ( const std::vector< T > &  v1)
inlinestatic

Definition at line 849 of file VectorTools.h.

Referenced by cov().

template<class T >
static T bpp::VectorTools::sumExp ( const std::vector< T > &  v1)
inlinestatic
Author
Laurent Gueguen
Returns
From std::vector v1, return $\sum_i(\exp(v1_i))$.
Parameters
v1a std::vector.

Definition at line 732 of file VectorTools.h.

References max().

Referenced by bpp::LogsumHmmLikelihood::computeD2Forward_(), and bpp::LogsumHmmLikelihood::computeDForward_().

template<class T >
static T bpp::VectorTools::sumExp ( const std::vector< T > &  v1,
const std::vector< T > &  v2 
)
inlinestatic
Author
Laurent Gueguen
Returns
From std::vector v1, return $\sum_i(v2_i * \exp(v1_i))$.
Parameters
v1a std::vector.
v2another std::vector.

Definition at line 753 of file VectorTools.h.

References max().

bool VectorTools::test ( )
static

Test function.

Returns
true if all tests are passed.

Definition at line 68 of file VectorTools.cpp.

Referenced by diff(), and vectorIntersection().

template<class T >
static std::vector<T> bpp::VectorTools::unique ( const std::vector< T > &  v)
inlinestatic

Send a new std::vector with unique elements.

The input std::vector is copied, and the copy is sorted using QuickSort algorithm. A one-pass loop then look for duplicates and copy unique element to a result std::vector. The output std::vector is hence sorted.

If v is empty, it is passed 'as is' in return (after being copied).

Parameters
vthe std::vector to parse.

Definition at line 481 of file VectorTools.h.

template<class InputType , class OutputType >
static OutputType bpp::VectorTools::var ( const std::vector< InputType > &  v1,
bool  unbiased = true 
)
inlinestatic
Returns
The variance of the std::vector.
Parameters
v1The sample std::vector.
unbiasedTell if an unbiased estimate must be computed.

Definition at line 1482 of file VectorTools.h.

template<class InputType , class OutputType >
static OutputType bpp::VectorTools::var ( const std::vector< InputType > &  v1,
const std::vector< InputType > &  w,
bool  unbiased = true,
bool  normalizeWeights = true 
)
inlinestatic
Returns
The weighted variance of the std::vector.
Parameters
v1The sample std::vector.
wA std::vector of weights.
unbiasedTell if an unbiased estimate must be computed.
normalizeWeightsTell if weights should be normalized so that they sum to 1.
Exceptions
DimensionExceptionIf v1 and w do not have the same length.

Definition at line 1495 of file VectorTools.h.

template<class T >
static std::vector<T> bpp::VectorTools::vectorIntersection ( const std::vector< T > &  vec1,
const std::vector< T > &  vec2 
)
inlinestatic
Returns
A std::vector which is the intersection of two std::vectors passed as input.
Parameters
vec1Vector 1.
vec2Vector 2.

Definition at line 1867 of file VectorTools.h.

References contains().

template<class T , class U >
static std::vector<T> bpp::VectorTools::vectorIntersection ( const std::vector< T > &  vec1,
const std::vector< U > &  vec2 
)
inlinestatic

Definition at line 1878 of file VectorTools.h.

References contains().

template<class T >
static std::vector<T> bpp::VectorTools::vectorIntersection ( const std::vector< std::vector< T > > &  vecElementL)
inlinestatic
Returns
A std::vector which is the intersection of all std::vectors passed as input.
Parameters
vecElementLA std::vector of std::vectors.

Definition at line 1893 of file VectorTools.h.

References contains(), and test().

template<class T >
static std::vector<T> bpp::VectorTools::vectorUnion ( const std::vector< T > &  vec1,
const std::vector< T > &  vec2 
)
inlinestatic
Returns
A std::vector which is the union of two std::vectors passed as input. Duplicate element will be removed.
Parameters
vec1Vector 1.
vec2Vector 2.

Definition at line 1830 of file VectorTools.h.

References contains().

template<class T >
static std::vector<T> bpp::VectorTools::vectorUnion ( const std::vector< std::vector< T > > &  vecElementL)
inlinestatic
Returns
A std::vector which is the union of all std::vectors passed as input. Duplicate element will be removed.
Parameters
vecElementLA std::vector of std::vectors.

Definition at line 1847 of file VectorTools.h.

References contains().

template<class T >
static size_t bpp::VectorTools::which ( const std::vector< T > &  v,
const T &  which 
)
inlinestatic

Send the position of the first occurence of 'which'.

Comparisons are performed using the == operator. Maximum complexity: O(v.size()).

Parameters
vThe std::vector to search.
whichThe element to search.
Returns
The position of which in v.

Definition at line 437 of file VectorTools.h.

Referenced by bpp::DataTable::deleteColumn(), bpp::Table< T >::deleteColumn(), bpp::DataTable::deleteRow(), bpp::Table< T >::deleteRow(), bpp::DataTable::getColumn(), bpp::Table< T >::getColumn(), bpp::DataTable::getRow(), bpp::Table< T >::getRow(), bpp::DataTable::operator()(), bpp::Table< T >::operator()(), and whichAll().

template<class T >
static std::vector<size_t> bpp::VectorTools::whichAll ( const std::vector< T > &  v,
const T &  which 
)
inlinestatic

Send the positions of all occurences of 'which'.

Comparisons are performed using the == operator. Complexity: O(v.size()).

Parameters
vThe std::vector to search.
whichThe element to search.
Returns
A std::vector containing the positions of which in v.

Definition at line 457 of file VectorTools.h.

References which().

template<class T >
static size_t bpp::VectorTools::whichMax ( const std::vector< T > &  v)
inlinestatic

Template function to get the index of the maximum value of a std::vector.

The > operator must be defined for the specified class. The position sent is the first one matching the maximum value.

Parameters
vThe input std::vector.
Returns
The position of the maximum value in the std::vector.
Exceptions
EmptyVectorExceptionIf the input std::vector is empty.

Definition at line 1150 of file VectorTools.h.

Referenced by bpp::LogsumHmmLikelihood::computeD2Forward_(), and bpp::LogsumHmmLikelihood::computeDForward_().

template<class T >
static std::vector<size_t> bpp::VectorTools::whichMaxAll ( const std::vector< T > &  v)
inlinestatic

Template function to get the indices of the maximum value of a std::vector.

The > and == operator must be defined for the specified class. All positions matching the maximum value are returned.

Parameters
vThe input std::vector.
Returns
A vector of positions matching the maximum value in the std::vector.
Exceptions
EmptyVectorExceptionIf the input std::vector is empty.

Definition at line 1204 of file VectorTools.h.

References max().

template<class T >
static size_t bpp::VectorTools::whichMin ( const std::vector< T > &  v)
inlinestatic

Template function to get the index of the minimum value of a std::vector.

The < operator must be defined for the specified class. The position sent is the first one matching the maximum value.

Parameters
vThe input std::vector.
Returns
The position of the minimum value in the std::vector.
Exceptions
EmptyVectorExceptionIf the input std::vector is empty.

Definition at line 1177 of file VectorTools.h.

template<class T >
static std::vector<size_t> bpp::VectorTools::whichMinAll ( const std::vector< T > &  v)
inlinestatic

Template function to get the indices of the minimum value of a std::vector.

The < and == operator must be defined for the specified class. All positions matching the maximum value are returned.

Parameters
vThe input std::vector.
Returns
A vector of positions matching the minimum value in the std::vector.
Exceptions
EmptyVectorExceptionIf the input std::vector is empty.

Definition at line 1230 of file VectorTools.h.

References min().


The documentation for this class was generated from the following files: