Miscellaneous math routines. More...
Classes | |
| class | ColumnsToBlocks |
| Transform the columns of the given matrix into a block format. More... | |
| class | RangeType |
| Simple real-valued range. More... | |
Typedefs | |
| typedef RangeType< double > | Range |
| 3.0.0 TODO: break reverse-compatibility by changing RangeType to Range. More... | |
Functions | |
| void | Center (const arma::mat &x, arma::mat &xCentered) |
| Creates a centered matrix, where centering is done by subtracting the sum over the columns (a column vector) from each column of the matrix. More... | |
| double | ClampNonNegative (const double d) |
| Forces a number to be non-negative, turning negative numbers into zero. More... | |
| double | ClampNonPositive (const double d) |
| Forces a number to be non-positive, turning positive numbers into zero. More... | |
| double | ClampRange (double value, const double rangeMin, const double rangeMax) |
| Clamp a number between a particular range. More... | |
template < typename ElemType > | |
| void | ClearAlias (arma::Mat< ElemType > &mat) |
| Clear an alias so that no data is overwritten. More... | |
template < typename ElemType > | |
| void | ClearAlias (arma::SpMat< ElemType > &) |
| Clear an alias for a sparse matrix. More... | |
| void | FixedRandomSeed () |
| Set the random seed to a fixed number. More... | |
template < typename ElemType > | |
| arma::Mat< ElemType > | MakeAlias (arma::Mat< ElemType > &input, const bool strict=true) |
| Make an alias of a dense matrix. More... | |
template < typename ElemType > | |
| arma::Row< ElemType > | MakeAlias (arma::Row< ElemType > &input, const bool strict=true) |
| Make an alias of a dense row. More... | |
template < typename ElemType > | |
| arma::Col< ElemType > | MakeAlias (arma::Col< ElemType > &input, const bool strict=true) |
| Make an alias of a dense column. More... | |
template < typename ElemType > | |
| arma::SpMat< ElemType > | MakeAlias (const arma::SpMat< ElemType > &input, const bool=true) |
| Make a copy of a sparse matrix (an alias is not possible). More... | |
template < typename ElemType > | |
| arma::SpRow< ElemType > | MakeAlias (const arma::SpRow< ElemType > &input, const bool=true) |
| Make a copy of a sparse row (an alias is not possible). More... | |
template < typename ElemType > | |
| arma::SpCol< ElemType > | MakeAlias (const arma::SpCol< ElemType > &input, const bool=true) |
| Make a copy of a sparse column (an alias is not possible). More... | |
| void | ObtainDistinctSamples (const size_t loInclusive, const size_t hiExclusive, const size_t maxNumSamples, arma::uvec &distinctSamples) |
| Obtains no more than maxNumSamples distinct samples. More... | |
| void | Orthogonalize (const arma::mat &x, arma::mat &W) |
| Orthogonalize x and return the result in W, using eigendecomposition. More... | |
| void | Orthogonalize (arma::mat &x) |
| Orthogonalize x in-place. More... | |
| int | RandInt (const int hiExclusive) |
| Generates a uniform random integer. More... | |
| int | RandInt (const int lo, const int hiExclusive) |
| Generates a uniform random integer. More... | |
| double | RandNormal () |
| Generates a normally distributed random number with mean 0 and variance 1. More... | |
| double | RandNormal (const double mean, const double variance) |
| Generates a normally distributed random number with specified mean and variance. More... | |
| double | Random () |
| Generates a uniform random number between 0 and 1. More... | |
| double | Random (const double lo, const double hi) |
| Generates a uniform random number in the specified range. More... | |
| void | RandomBasis (arma::mat &basis, const size_t d) |
| Create a random d-dimensional orthogonal basis, storing it in the given matrix. More... | |
| void | RandomSeed (const size_t seed) |
| Set the random seed used by the random functions (Random() and RandInt()). More... | |
| void | RandVector (arma::vec &v) |
| Overwrites a dimension-N vector to a random vector on the unit sphere in R^N. More... | |
| void | RemoveRows (const arma::mat &input, const std::vector< size_t > &rowsToRemove, arma::mat &output) |
| Remove a certain set of rows in a matrix while copying to a second matrix. More... | |
template < typename MatType , typename LabelsType > | |
| void | ShuffleData (const MatType &inputPoints, const LabelsType &inputLabels, MatType &outputPoints, LabelsType &outputLabels, const std::enable_if_t<!arma::is_SpMat< MatType >::value > *=0, const std::enable_if_t<!arma::is_Cube< MatType >::value > *=0) |
| Shuffle a dataset and associated labels (or responses). More... | |
template < typename MatType , typename LabelsType > | |
| void | ShuffleData (const MatType &inputPoints, const LabelsType &inputLabels, MatType &outputPoints, LabelsType &outputLabels, const std::enable_if_t< arma::is_SpMat< MatType >::value > *=0, const std::enable_if_t<!arma::is_Cube< MatType >::value > *=0) |
| Shuffle a sparse dataset and associated labels (or responses). More... | |
template < typename MatType , typename LabelsType > | |
| void | ShuffleData (const MatType &inputPoints, const LabelsType &inputLabels, MatType &outputPoints, LabelsType &outputLabels, const std::enable_if_t<!arma::is_SpMat< MatType >::value > *=0, const std::enable_if_t< arma::is_Cube< MatType >::value > *=0, const std::enable_if_t< arma::is_Cube< LabelsType >::value > *=0) |
| Shuffle a cube-shaped dataset and associated labels (or responses) which are also cube-shaped. More... | |
template < typename T > | |
| T | Sign (const T x) |
| Signum function. More... | |
| void | Smat (const arma::vec &input, arma::mat &output) |
| The inverse of Svec. More... | |
| void | Svec (const arma::mat &input, arma::vec &output) |
| Upper triangular representation of a symmetric matrix, scaled such that, dot(Svec(A), Svec(B)) == dot(A, B) for symmetric A, B. More... | |
| void | Svec (const arma::sp_mat &input, arma::sp_vec &output) |
| size_t | SvecIndex (size_t i, size_t j, size_t n) |
| Return the index such that A[i,j] == factr(i, j) * svec(A)[pos(i, j)], where factr(i, j) = sqrt(2) if i != j and 1 otherwise. More... | |
| void | SymKronId (const arma::mat &A, arma::mat &op) |
| If A is a symmetric matrix, then SymKronId returns an operator Op such that. More... | |
| void | VectorPower (arma::vec &vec, const double power) |
| Auxiliary function to raise vector elements to a specific power. More... | |
| void | WhitenUsingEig (const arma::mat &x, arma::mat &xWhitened, arma::mat &whiteningMatrix) |
| Whitens a matrix using the eigendecomposition of the covariance matrix. More... | |
| void | WhitenUsingSVD (const arma::mat &x, arma::mat &xWhitened, arma::mat &whiteningMatrix) |
| Whitens a matrix using the singular value decomposition of the covariance matrix. More... | |
Variables | |
| MLPACK_EXPORT std::mt19937 | randGen |
| MLPACK_EXPORT is required for global variables; it exports the symbols correctly on Windows. More... | |
| MLPACK_EXPORT std::normal_distribution | randNormalDist |
| MLPACK_EXPORT std::uniform_real_distribution | randUniformDist |
Miscellaneous math routines.
| void mlpack::math::Center | ( | const arma::mat & | x, |
| arma::mat & | xCentered | ||
| ) |
Creates a centered matrix, where centering is done by subtracting the sum over the columns (a column vector) from each column of the matrix.
| x | Input matrix |
| xCentered | Matrix to write centered output into |
Referenced by NystroemKernelRule< KernelType, PointSelectionPolicy >::ApplyKernelMatrix(), and HRectBound< MetricType >::MinWidth().
|
inline |
Forces a number to be non-negative, turning negative numbers into zero.
Avoids branching costs (this is a measurable improvement).
| d | Double to clamp. |
Definition at line 28 of file clamp.hpp.
Referenced by ClampRange().
|
inline |
Forces a number to be non-positive, turning positive numbers into zero.
Avoids branching costs (this is a measurable improvement).
| d | Double to clamp. |
| 0 | if d > 0, d otherwise. |
Definition at line 40 of file clamp.hpp.
Referenced by ClampRange().
|
inline |
Clamp a number between a particular range.
| value | The number to clamp. |
| rangeMin | The first of the range. |
| rangeMax | The last of the range. |
Definition at line 53 of file clamp.hpp.
References ClampNonNegative(), and ClampNonPositive().
| void mlpack::math::ClearAlias | ( | arma::Mat< ElemType > & | mat | ) |
Clear an alias so that no data is overwritten.
This resets the matrix if it is an alias (and does nothing otherwise).
Definition at line 97 of file make_alias.hpp.
| void mlpack::math::ClearAlias | ( | arma::SpMat< ElemType > & | ) |
Clear an alias for a sparse matrix.
This does nothing because no sparse matrices can have aliases.
Definition at line 108 of file make_alias.hpp.
|
inline |
Set the random seed to a fixed number.
This function is used in binding tests to set a fixed random seed before calling mlpack(). In this way we can test whether a certain parameter makes a difference to execution of CLI binding. Refer to pull request #1306 for discussion on this function.
Definition at line 59 of file random.hpp.
| arma::Mat<ElemType> mlpack::math::MakeAlias | ( | arma::Mat< ElemType > & | input, |
| const bool | strict = true |
||
| ) |
Make an alias of a dense matrix.
If strict is true, then the alias cannot be resized or pointed at new memory.
Definition at line 24 of file make_alias.hpp.
| arma::Row<ElemType> mlpack::math::MakeAlias | ( | arma::Row< ElemType > & | input, |
| const bool | strict = true |
||
| ) |
Make an alias of a dense row.
If strict is true, then the alias cannot be resized or pointed at new memory.
Definition at line 37 of file make_alias.hpp.
| arma::Col<ElemType> mlpack::math::MakeAlias | ( | arma::Col< ElemType > & | input, |
| const bool | strict = true |
||
| ) |
Make an alias of a dense column.
If strict is true, then the alias cannot be resized or pointed at new memory.
Definition at line 49 of file make_alias.hpp.
| arma::SpMat<ElemType> mlpack::math::MakeAlias | ( | const arma::SpMat< ElemType > & | input, |
| const bool | = true |
||
| ) |
Make a copy of a sparse matrix (an alias is not possible).
The strict parameter is ignored.
Definition at line 61 of file make_alias.hpp.
| arma::SpRow<ElemType> mlpack::math::MakeAlias | ( | const arma::SpRow< ElemType > & | input, |
| const bool | = true |
||
| ) |
Make a copy of a sparse row (an alias is not possible).
The strict parameter is ignored.
Definition at line 73 of file make_alias.hpp.
| arma::SpCol<ElemType> mlpack::math::MakeAlias | ( | const arma::SpCol< ElemType > & | input, |
| const bool | = true |
||
| ) |
Make a copy of a sparse column (an alias is not possible).
The strict parameter is ignored.
Definition at line 85 of file make_alias.hpp.
|
inline |
Obtains no more than maxNumSamples distinct samples.
Each sample belongs to [loInclusive, hiExclusive).
| loInclusive | The lower bound (inclusive). |
| hiExclusive | The high bound (exclusive). |
| maxNumSamples | The maximum number of samples to obtain. |
| distinctSamples | The samples that will be obtained. |
Definition at line 130 of file random.hpp.
References RandInt().
| void mlpack::math::Orthogonalize | ( | const arma::mat & | x, |
| arma::mat & | W | ||
| ) |
Orthogonalize x and return the result in W, using eigendecomposition.
We will be using the formula
.
| void mlpack::math::Orthogonalize | ( | arma::mat & | x | ) |
Orthogonalize x in-place.
This could be sped up by a custom implementation.
|
inline |
Generates a uniform random integer.
Definition at line 87 of file random.hpp.
References randUniformDist.
Referenced by RandomDimensionSelect::Begin(), SampleInitialization::Cluster(), RandomDescent::DescentFeature(), DataDependentRandomInitializer::Initialize(), RandomAcolInitialization< columnsToAverage >::Initialize(), MultipleRandomDimensionSelect< NumDimensions >::MultipleRandomDimensionSelect(), ObtainDistinctSamples(), GreedyPolicy< EnvironmentType >::Sample(), RandomPointSelection::Select(), and RandomSelection::Select().
|
inline |
Generates a uniform random integer.
Definition at line 95 of file random.hpp.
References randUniformDist.
|
inline |
Generates a normally distributed random number with mean 0 and variance 1.
Definition at line 104 of file random.hpp.
References randNormalDist.
Referenced by GaussianInitialization::Initialize().
|
inline |
Generates a normally distributed random number with specified mean and variance.
| mean | Mean of distribution. |
| variance | Variance of distribution. |
Definition at line 116 of file random.hpp.
References randNormalDist.
|
inline |
Generates a uniform random number between 0 and 1.
Definition at line 71 of file random.hpp.
References randUniformDist.
Referenced by ContinuousMountainCar::InitialSample(), MockCategoricalData(), GreedyPolicy< EnvironmentType >::Sample(), and Acrobat::Torque().
|
inline |
Generates a uniform random number in the specified range.
Definition at line 79 of file random.hpp.
References randUniformDist.
| void mlpack::math::RandomBasis | ( | arma::mat & | basis, |
| const size_t | d | ||
| ) |
Create a random d-dimensional orthogonal basis, storing it in the given matrix.
| basis | Matrix to store basis in. |
| d | Desired number of dimensions in the basis. |
|
inline |
Set the random seed used by the random functions (Random() and RandInt()).
The seed is casted to a 32-bit integer before being given to the random number generator, but a size_t is taken as a parameter for API consistency.
| seed | Seed for the random number generator. |
Definition at line 40 of file random.hpp.
| void mlpack::math::RandVector | ( | arma::vec & | v | ) |
Overwrites a dimension-N vector to a random vector on the unit sphere in R^N.
| void mlpack::math::RemoveRows | ( | const arma::mat & | input, |
| const std::vector< size_t > & | rowsToRemove, | ||
| arma::mat & | output | ||
| ) |
Remove a certain set of rows in a matrix while copying to a second matrix.
| input | Input matrix to copy. |
| rowsToRemove | Vector containing indices of rows to be removed. |
| output | Matrix to copy non-removed rows into. |
| void mlpack::math::ShuffleData | ( | const MatType & | inputPoints, |
| const LabelsType & | inputLabels, | ||
| MatType & | outputPoints, | ||
| LabelsType & | outputLabels, | ||
| const std::enable_if_t<!arma::is_SpMat< MatType >::value > * | = 0, |
||
| const std::enable_if_t<!arma::is_Cube< MatType >::value > * | = 0 |
||
| ) |
Shuffle a dataset and associated labels (or responses).
It is expected that inputPoints and inputLabels have the same number of columns (so, be sure that inputLabels, if it is a vector, is a row vector).
Shuffled data will be output into outputPoints and outputLabels.
Definition at line 28 of file shuffle_data.hpp.
| void mlpack::math::ShuffleData | ( | const MatType & | inputPoints, |
| const LabelsType & | inputLabels, | ||
| MatType & | outputPoints, | ||
| LabelsType & | outputLabels, | ||
| const std::enable_if_t< arma::is_SpMat< MatType >::value > * | = 0, |
||
| const std::enable_if_t<!arma::is_Cube< MatType >::value > * | = 0 |
||
| ) |
Shuffle a sparse dataset and associated labels (or responses).
It is expected that inputPoints and inputLabels have the same number of columns (so, be sure that inputLabels, if it is a vector, is a row vector).
Shuffled data will be output into outputPoints and outputLabels.
Definition at line 51 of file shuffle_data.hpp.
| void mlpack::math::ShuffleData | ( | const MatType & | inputPoints, |
| const LabelsType & | inputLabels, | ||
| MatType & | outputPoints, | ||
| LabelsType & | outputLabels, | ||
| const std::enable_if_t<!arma::is_SpMat< MatType >::value > * | = 0, |
||
| const std::enable_if_t< arma::is_Cube< MatType >::value > * | = 0, |
||
| const std::enable_if_t< arma::is_Cube< LabelsType >::value > * | = 0 |
||
| ) |
Shuffle a cube-shaped dataset and associated labels (or responses) which are also cube-shaped.
It is expected that inputPoints and inputLabels have the same number of columns.
Shuffled data will be output into outputPoints and outputLabels.
Definition at line 104 of file shuffle_data.hpp.
| T mlpack::math::Sign | ( | const T | x | ) |
Signum function.
Return 1 if x>0; return 0 if x=0; return -1 if x<0. Return type are the same as input type.
| x | Number of any type. |
Definition at line 135 of file lin_alg.hpp.
Referenced by ConstrLpBallSolver::Optimize().
| void mlpack::math::Smat | ( | const arma::vec & | input, |
| arma::mat & | output | ||
| ) |
The inverse of Svec.
That is, Smat(Svec(A)) == A.
| input | |
| output | A symmetric matrix |
| void mlpack::math::Svec | ( | const arma::mat & | input, |
| arma::vec & | output | ||
| ) |
Upper triangular representation of a symmetric matrix, scaled such that, dot(Svec(A), Svec(B)) == dot(A, B) for symmetric A, B.
Specifically,
Svec(K) = [ K_11, sqrt(2) K_12, ..., sqrt(2) K_1n, K_22, ..., sqrt(2) K_2n, ..., K_nn ]^T
| input | A symmetric matrix |
| output |
| void mlpack::math::Svec | ( | const arma::sp_mat & | input, |
| arma::sp_vec & | output | ||
| ) |
|
inline |
Return the index such that A[i,j] == factr(i, j) * svec(A)[pos(i, j)], where factr(i, j) = sqrt(2) if i != j and 1 otherwise.
| i | |
| j | |
| n |
| void mlpack::math::SymKronId | ( | const arma::mat & | A, |
| arma::mat & | op | ||
| ) |
If A is a symmetric matrix, then SymKronId returns an operator Op such that.
Op * svec(X) == svec(0.5 * (AX + XA))
for every symmetric matrix X
| A | |
| op |
| void mlpack::math::VectorPower | ( | arma::vec & | vec, |
| const double | power | ||
| ) |
Auxiliary function to raise vector elements to a specific power.
The sign is ignored in the power operation and then re-added. Useful for eigenvalues.
| void mlpack::math::WhitenUsingEig | ( | const arma::mat & | x, |
| arma::mat & | xWhitened, | ||
| arma::mat & | whiteningMatrix | ||
| ) |
Whitens a matrix using the eigendecomposition of the covariance matrix.
Whitening means the covariance matrix of the result is the identity matrix.
| void mlpack::math::WhitenUsingSVD | ( | const arma::mat & | x, |
| arma::mat & | xWhitened, | ||
| arma::mat & | whiteningMatrix | ||
| ) |
Whitens a matrix using the singular value decomposition of the covariance matrix.
Whitening means the covariance matrix of the result is the identity matrix.
| MLPACK_EXPORT std::mt19937 randGen |
MLPACK_EXPORT is required for global variables; it exports the symbols correctly on Windows.
| MLPACK_EXPORT std::normal_distribution randNormalDist |
Referenced by RandNormal().