KrisLibrary  1.0.0
Files | Namespaces | Classes | Typedefs | Enumerations | Functions | Variables
Math

Definitions of mathematical concepts and numerical algorithms. More...

Files

file  AABB.h
 Functions defining axis-aligned bounding boxes (AABBs).
 
file  angle.h
 Planar (R2) rotation utilities.
 
file  brent.h
 Brent's methods for parabolic minimization of a 1D function.
 
file  Conditioner.h
 Numerical conditioners for a matrix equation A*x=b.
 
file  conjgrad.h
 Template routine using preconditioned conjugate gradient to solve a linear system.
 
file  diffeq.h
 Various methods for solving ordinary differential equations.
 
file  differentiation.h
 Numerical differentiation routines.
 
file  fastmath.h
 Miscellaneous lightweight math routines.
 
file  function.h
 Abstract base classes for function interfaces.
 
file  Householder.h
 Functions for householder transformations.
 
file  math/indexing.h
 Utilities for matrix/vector access / manipulation with index vectors.
 
file  infnan.h
 Cross-platform infinity and not-a-number routines.
 
file  interpolate.h
 Convenience functions for linear interpolation of vectors and matrices.
 
file  math.h
 Common math typedefs, constants, functions.
 
file  metric.h
 Standard vector/matrix metrics.
 
file  misc.h
 Miscellaneous math functions.
 
file  quadrature.h
 Several functions for performing quadrature (function integration)
 
file  math/random.h
 Defines a standard method for random floating-point number generation.
 
file  root.h
 Numerical root-solving routines.
 
file  sparsefunction.h
 Vector field classes with sparse jacobians.
 
file  math/indexing.h
 Utilities for matrix/vector access / manipulation with index vectors.
 
file  vectorfunction.h
 Various basic function classes.
 

Namespaces

 Math
 Contains all definitions in the Math package.
 
 Math::Quadrature
 Namespace for quadrature functions.
 

Classes

struct  Math::AngleInterval
 A contiguous range of angles. More...
 
struct  Math::AngleSet
 A set of AngleIntervals. More...
 
struct  Math::BLASInterface
 An interface to BLAS. Activated with the preprocessor flag HAVE_BLAS=1. More...
 
class  Math::CholeskyDecomposition< T >
 Performs the Cholesky decomposition. More...
 
class  Math::Complex
 Complex number class (x + iy). More...
 
class  Math::Quaternion
 Complex quaternion class (w + ix + jy + kz). More...
 
struct  Math::Conditioner_SymmDiag
 A matrix conditioner that does a pre/postmultiply with a diagonal S. More...
 
struct  Math::NullPreconditioner< Matrix >
 Identity precondtioner. More...
 
struct  Math::JacobiPreconditioner< Matrix >
 Jacobi preconditioning (inverse of diagonal) More...
 
class  Math::DiagonalMatrixTemplate< T >
 A templated diagonal matrix, represented by a vector of the entries on the diagonal. More...
 
class  Math::RealFunction
 A function from R to R. More...
 
class  Math::RealFunction2
 
class  Math::VectorFunction
 A function from R to R^n, identical to RealFunction except a vector is returned. More...
 
class  Math::ScalarFieldFunction
 A function from R^n to R. More...
 
class  Math::VectorFieldFunction
 A function from R^n to R^m. More...
 
class  Math::DiffEqFunction
 
class  Math::Gaussian< T >
 Multivariate gaussian N(mu,K) of d dimensions. More...
 
class  Math::InequalityConstraint
 A vector field with constraints s.t. ci(x) >= 0. More...
 
class  Math::CompositeInequalityConstraint
 
class  Math::LimitConstraint
 
class  Math::LinearConstraint
 constraint represented as A*x >= b i.e. constraint value is A*x-b More...
 
struct  Math::InequalityConstraintAdaptor
 A class that makes it easier to construct "plugin" classes to alter constraint behavior. More...
 
struct  Math::Interval
 A generic interval {a,b}, where { and } can be either (,[ or ),]. More...
 
struct  Math::OpenInterval
 An open interval (a,b) More...
 
struct  Math::ClosedInterval
 A closed interval [a,b]. More...
 
struct  Math::LAPACKInterface
 An interface to LAPACK. Activated with the preprocessor flag HAVE_CLAPACK=1. More...
 
struct  Math::LDLDecomposition< T >
 Performs the LDL^t decompositoin of a symmetric matrix A. More...
 
class  Math::LUDecomposition< T >
 Forms the LU decomposition A=PLU. More...
 
class  Math::MatrixIterator< T >
 An iterator through MatrixTemplate elements. More...
 
class  Math::MatrixTemplate< T >
 A matrix over the field T. More...
 
class  Math::NormAccumulator< T >
 
class  Math::QRDecomposition< T >
 Calculates the QR decomposition. More...
 
class  Math::NRQRDecomposition< T >
 The QR decomposition as computed by the algorithm in Numerical Recipes in C. More...
 
struct  Math::QNHessianUpdater
 Maintains the Cholesky decomposition of the hessian H over Quasi-Newton steps. More...
 
class  Math::RowEchelon< T >
 Compute reduced row-eschelon form for a matrix A. More...
 
class  Math::SparseVectorFunction
 A vector field function with a sparse jacobian. The Jacobian_Sparse and Jacobian_i_Sparse methods must be overridden. More...
 
class  Math::SVDecomposition< T >
 Performs the singular value decomposition. More...
 
class  Math::RobustSVD< T >
 Performs a pre/postconditioned singular value decomposition. More...
 
class  Math::ScalarFieldDirectionalFunction
 A function g(t) that returns f(x+tn) for a scalar field f(x) If ref is true, then x,n are set to refer to the x,n provided in the constructor, rather than to copy. More...
 
class  Math::ScalarFieldProjectionFunction
 
class  Math::LinearScalarFieldFunction
 
class  Math::QuadraticScalarFieldFunction
 
struct  Math::NormSquaredScalarFieldFunction
 A scalar field ||x||^2. More...
 
struct  Math::NormScalarFieldFunction
 A scalar field for the L-d norm, where d is passed into the constructor. More...
 
class  Math::MinimumScalarFieldFunction
 A scalar field min_i xi. More...
 
class  Math::MaximumScalarFieldFunction
 A scalar field max_i xi. More...
 
class  Math::ComposeScalarFieldFunction
 A scalar field h(x) = f(g(x)) More...
 
class  Math::Vector3FieldFunction
 
class  Math::LinearVectorFieldFunction
 
class  Math::Compose_SF_VF_Function
 A scalar field function h(x) = f(g(x)) (g vector-valued) More...
 
class  Math::Compose_VF_VF_Function
 A vector field function h(x) = f(g(x)) (f,g vector fields) More...
 
class  Math::ComponentVectorFieldFunction
 
class  Math::VectorFieldProjectionFunction
 A function g(x) that returns the i'th component of vector field f(x) More...
 
class  Math::CompositeVectorFieldFunction
 
class  Math::IndexedVectorFieldFunction
 A vector field function f(x) = g(x[xindices])[findices]. More...
 
class  Math::SliceVectorFieldFunction
 A vector field function f(x) = g(x0 | x0[xindices]=x) More...
 
class  Math::VectorIterator< T >
 An iterator through VectorTemplate elements. More...
 
class  Math::VectorTemplate< T >
 A vector over the field T. More...
 

Typedefs

typedef double Math::Real
 
typedef Real(* Math::QuadratureFunction) (RealFunction &, Real, Real)
 

Enumerations

enum  ConvergenceResult {
  ConvergenceX, ConvergenceF, Divergence, LocalMinimum,
  MaxItersReached, ConvergenceError
}
 

Functions

void Math::AABBClamp (Vector &x, const Vector &bmin, const Vector &bmax, Real d=Zero)
 Clamps x to be contained in the AABB (bmin,bmax)
 
Real Math::AABBMargin (const Vector &x, const Vector &bmin, const Vector &bmax, int &index)
 
Real Math::AABBMargin (const Vector &x, const Vector &bmin, const Vector &bmax)
 
bool Math::AABBContains (const Vector &x, const Vector &bmin, const Vector &bmax, Real d=Zero)
 Returns true if the AABB (bmin,bmax) contains x.
 
int Math::AABBLineSearch (const Vector &x0, const Vector &dx, const Vector &bmin, const Vector &bmax, Real &t)
 
bool Math::AABBClipLine (const Vector &x0, const Vector &dx, const Vector &bmin, const Vector &bmax, Real &u0, Real &u1)
 
Real Math::AngleNormalize (Real a)
 Normalizes an angle to [0,2pi)
 
Real Math::AngleDiff (Real a, Real b)
 Returns the closest distance to get to a from b (range [-pi,pi])
 
Real Math::AngleCCWDiff (Real a, Real b)
 Returns the CCW distance needed to get to a from b.
 
Real Math::AngleInterp (Real a, Real b, Real u)
 Interpolates between rotations a and b (u from 0 to 1)
 
bool Math::IsValidAngle (Real a)
 
void Math::Acos_All (Real x, Real &a, Real &b)
 returns all solutions y to cos(y)=x in a,b
 
void Math::Asin_All (Real x, Real &a, Real &b)
 returns all solutions y to sin(y)=x in a,b
 
void Math::Atan_All (Real x, Real &a, Real &b)
 returns all solutions y to tan(y)=x in a,b
 
void Math::TransformCosSin_Cos (Real a, Real b, Real &c, Real &d)
 
void Math::TransformCosSin_Sin (Real a, Real b, Real &c, Real &d)
 Same as above, but returns c*sin(x+d)
 
bool Math::SolveCosSinEquation (Real a, Real b, Real c, Real &t1, Real &t2)
 
void Math::SolveCosSinGreater (Real a, Real b, Real c, AngleInterval &i)
 Same as above, but a cos(x) + b sin(x) >= c.
 
void Math::BracketMin (Real &a, Real &b, Real &c, Real &fa, Real &fb, Real &fc, RealFunction &func)
 Returns a bracketing triplet given some a,b. More...
 
ConvergenceResult Math::ParabolicMinimization (Real ax, Real bx, Real cx, RealFunction &f, int &maxIters, Real tol, Real &xmin)
 Brent's algorithm for parabolic minimization. More...
 
ConvergenceResult Math::ParabolicMinimization (Real x, RealFunction &f, int &maxIters, Real tol, Real &xmin)
 
Real Math::ParabolicLineMinimization (ScalarFieldFunction &f, const Vector &x, const Vector &n, int maxIters, Real tol)
 
Real Math::ParabolicLineMinimization_i (ScalarFieldFunction &f, const Vector &x, int i, int maxIters, Real tol)
 Same as above, but minimizes f(x + t*ei).
 
template<class Matrix , class Preconditioner >
int Math::CG (const Matrix &A, Vector &x, const Vector &b, const Preconditioner &M, int &max_iter, Real &tol)
 
Real Math::RungeKutta4_step (RealFunction2 *f, Real t0, Real h, Real w)
 Runge-Kutta 4 step for 1D ODEs. More...
 
Real Math::RungeKutta4 (RealFunction2 *f, Real a, Real b, Real alpha, int n)
 Runge-Kutta 4 method for 1D ODEs. More...
 
Real Math::RKF (RealFunction2 *f, Real a, Real b, Real alpha, Real tol, Real hmax, Real hmin)
 Runge-Kutta-Fehlberg method for 1D ODEs. More...
 
Real Math::AM2I (RealFunction2 *f, Real h, Real t0, Real t1, Real t2, Real w0, Real w1, Real w2)
 Adams-Moulton 2 step implicit method for 1D ODEs. More...
 
Real Math::AM2E (RealFunction2 *f, Real h, Real t0, Real t1, Real w0, Real w1)
 Adams-Bashforth 2 step explicit method for 1D ODEs. More...
 
Real Math::AM2_predictor_corrector_step (RealFunction2 *f, Real h, Real t0, Real t1, Real t2, Real w0, Real w1)
 Adams-Moulton predictor-corrector step of order 2 for 1D ODEs.
 
Real Math::AM2_predictor_corrector (RealFunction2 *f, Real a, Real b, Real alpha0, Real alpha1, int n)
 Adams-Moulton predictor-corrector of order 2 for 1D ODEs.
 
void Math::Euler_step (DiffEqFunction *f, Real t0, Real h, const Vector &w0, Vector &w1)
 Euler step for an ODE system. More...
 
void Math::RungeKutta4_step (DiffEqFunction *f, Real t0, Real h, const Vector &w0, Vector &w1)
 Runge-Kutta 4 step for an ODE system. More...
 
void Math::Euler (DiffEqFunction *f, Real a, Real b, const Vector &alpha, int n, Vector &wn)
 Solve an ODE system using Euler's method. More...
 
void Math::RungeKutta4 (DiffEqFunction *f, Real a, Real b, const Vector &alpha, int n, Vector &wn)
 Solve an ODE system using the Runge Kutta 4 method. More...
 
Real Math::dfCenteredDifference (RealFunction &f, Real x, Real h)
 
void Math::dfCenteredDifference (VectorFunction &f, Real x, Real h, Vector &df)
 
Real Math::dfCenteredDifferenceAdaptive (RealFunction &f, Real x, Real h0, Real tol)
 
void Math::dfCenteredDifferenceAdaptive (VectorFunction &f, Real x, Real h0, Real tol, Vector &df)
 
Real Math::ddfCenteredDifference (RealFunction &f, Real x, Real h)
 
void Math::ddfCenteredDifference (VectorFunction &f, Real x, Real h, Vector &ddf)
 
void Math::GradientForwardDifference (ScalarFieldFunction &f, Vector &x, Real h, Vector &g)
 x is provided as a temporary, it's restored to its original value later
 
void Math::JacobianForwardDifference (VectorFieldFunction &f, Vector &x, Real h, Matrix &J)
 
void Math::HessianForwardDifference (ScalarFieldFunction &f, Vector &x, Real h, Matrix &H)
 
void Math::HessianForwardDifference_Grad (ScalarFieldFunction &f, Vector &x, Real h, Matrix &H)
 
void Math::GradientCenteredDifference (ScalarFieldFunction &f, Vector &x, Real h, Vector &g)
 
void Math::JacobianCenteredDifference (VectorFieldFunction &f, Vector &x, Real h, Matrix &J)
 
void Math::HessianCenteredDifference (ScalarFieldFunction &f, Vector &x, Real h, Matrix &H)
 
void Math::HessianCenteredDifference_Grad (ScalarFieldFunction &f, Vector &x, Real h, Matrix &H)
 
void Math::GradientCenteredDifferenceAdaptive (ScalarFieldFunction &f, Vector &x, Real h0, Real tol, Vector &g)
 
void Math::GradientForwardDifference (ScalarFieldFunction &f, Vector &x, const Vector &h, Vector &g)
 specified hi in each direction xi
 
void Math::JacobianForwardDifference (VectorFieldFunction &f, Vector &x, const Vector &h, Matrix &J)
 
void Math::HessianForwardDifference (ScalarFieldFunction &f, Vector &x, const Vector &h, Matrix &H)
 
void Math::HessianForwardDifference_Grad (ScalarFieldFunction &f, Vector &x, const Vector &h, Matrix &H)
 
void Math::GradientCenteredDifference (ScalarFieldFunction &f, Vector &x, const Vector &h, Vector &g)
 
void Math::JacobianCenteredDifference (VectorFieldFunction &f, Vector &x, const Vector &h, Matrix &J)
 
void Math::HessianCenteredDifference (ScalarFieldFunction &f, Vector &x, const Vector &h, Matrix &H)
 
void Math::HessianCenteredDifference_Grad (ScalarFieldFunction &f, Vector &x, const Vector &h, Matrix &H)
 
virtual std::string Math::RealFunction::Label () const
 
virtual std::string Math::RealFunction::VariableLabel () const
 
virtual Real Math::RealFunction::operator() (Real t)
 
virtual void Math::RealFunction::PreEval (Real t)
 
virtual Real Math::RealFunction::Eval (Real t)=0
 
virtual Real Math::RealFunction::Deriv (Real t)
 
virtual Real Math::RealFunction::Deriv2 (Real t)
 
virtual std::string Math::RealFunction2::Label () const
 
virtual std::string Math::RealFunction2::VariableLabel (int i) const
 
virtual Real Math::RealFunction2::operator() (Real t, Real x)
 
virtual void Math::RealFunction2::PreEval (Real t, Real x)
 
virtual Real Math::RealFunction2::Eval (Real t, Real x)=0
 
virtual std::string Math::VectorFunction::Label () const
 
virtual std::string Math::VectorFunction::Label (int i) const
 
virtual std::string Math::VectorFunction::VariableLabel () const
 
virtual int Math::VectorFunction::NumDimensions () const
 
virtual void Math::VectorFunction::operator() (Real t, Vector &x)
 
virtual void Math::VectorFunction::PreEval (Real t)
 
virtual void Math::VectorFunction::Eval (Real t, Vector &x)=0
 
virtual void Math::VectorFunction::Deriv (Real t, Vector &dx)
 
virtual void Math::VectorFunction::Deriv2 (Real t, Vector &ddx)
 
virtual std::string Math::ScalarFieldFunction::Label () const
 
virtual std::string Math::ScalarFieldFunction::VariableLabel (int i) const
 
virtual Real Math::ScalarFieldFunction::operator() (const Vector &x)
 
virtual void Math::ScalarFieldFunction::PreEval (const Vector &x)
 
virtual Real Math::ScalarFieldFunction::Eval (const Vector &x)=0
 
virtual void Math::ScalarFieldFunction::Gradient (const Vector &x, Vector &grad)
 
virtual Real Math::ScalarFieldFunction::Gradient_i (const Vector &x, int i)
 
virtual Real Math::ScalarFieldFunction::DirectionalDeriv (const Vector &x, const Vector &h)
 
virtual void Math::ScalarFieldFunction::Hessian (const Vector &x, Matrix &H)
 
virtual Real Math::ScalarFieldFunction::Hessian_ij (const Vector &x, int i, int j)
 
virtual Real Math::ScalarFieldFunction::DirectionalDeriv2 (const Vector &x, const Vector &h)
 
virtual std::string Math::VectorFieldFunction::Label () const
 
virtual std::string Math::VectorFieldFunction::Label (int i) const
 
virtual std::string Math::VectorFieldFunction::VariableLabel (int i) const
 
virtual int Math::VectorFieldFunction::NumDimensions () const
 
virtual void Math::VectorFieldFunction::operator() (const Vector &x, Vector &v)
 
virtual void Math::VectorFieldFunction::PreEval (const Vector &x)
 
virtual void Math::VectorFieldFunction::Eval (const Vector &x, Vector &v)=0
 
virtual Real Math::VectorFieldFunction::Eval_i (const Vector &x, int i)
 
virtual Real Math::VectorFieldFunction::Jacobian_ij (const Vector &x, int i, int j)
 
virtual void Math::VectorFieldFunction::Jacobian_i (const Vector &x, int i, Vector &Ji)
 
virtual void Math::VectorFieldFunction::Jacobian_j (const Vector &x, int j, Vector &Jj)
 
virtual void Math::VectorFieldFunction::Jacobian (const Vector &x, Matrix &J)
 
virtual void Math::VectorFieldFunction::DirectionalDeriv (const Vector &x, const Vector &h, Vector &v)
 
virtual Real Math::VectorFieldFunction::Divergence (const Vector &x)
 
virtual void Math::VectorFieldFunction::Hessian_i (const Vector &x, int i, Matrix &Hi)
 
virtual Real Math::VectorFieldFunction::Hessian_ijk (const Vector &x, int i, int j, int k)
 
virtual int Math::DiffEqFunction::NumDimensions () const
 
virtual void Math::DiffEqFunction::operator() (Real t, const Vector &y, Vector &fy)
 
virtual void Math::DiffEqFunction::PreEval (Real t, const Vector &y)
 
virtual void Math::DiffEqFunction::Eval (Real t, const Vector &y, Vector &fy)=0
 
template<class T >
int Math::OrthonormalBasis (const VectorTemplate< T > *x, VectorTemplate< T > *basis, int n)
 
template<class T >
int Math::OrthogonalBasis (const VectorTemplate< T > *x, VectorTemplate< T > *basis, int n)
 Same as above, but does not normalize.
 
template<class T >
void Math::Orthogonalize (VectorTemplate< T > &x, const VectorTemplate< T > *basis, int n)
 orthogonalizes a vector w.r.t the orthogonal basis of n vectors
 
template<class T >
Math::HouseholderTransform (VectorTemplate< T > &v)
 
template<class T >
void Math::HouseholderPreMultiply (T tau, const VectorTemplate< T > &v, MatrixTemplate< T > &A)
 
template<class T >
void Math::HouseholderPostMultiply (T tau, const VectorTemplate< T > &v, MatrixTemplate< T > &A)
 
template<class T >
void Math::HouseholderApply (T tau, const VectorTemplate< T > &v, VectorTemplate< T > &w)
 
template<class T >
void Math::HouseholderHM1 (T tau, MatrixTemplate< T > &A)
 
template<class T >
void Math::SetElements (VectorTemplate< T > &A, const std::vector< int > &indices, T fill)
 Sets A[indices] = fill.
 
template<class T >
void Math::SetElements (VectorTemplate< T > &A, const std::vector< int > &indices, const VectorTemplate< T > &fill)
 Sets A[indices] = fill. More...
 
template<class T >
void Math::GetElements (const VectorTemplate< T > &A, const std::vector< int > &indices, VectorTemplate< T > &B)
 Sets B = A[indices].
 
template<class T >
void Math::CopyElements (VectorTemplate< T > &A, const std::vector< int > &aindices, const VectorTemplate< T > &B, const std::vector< int > &bindices)
 Sets A[aindices] = B[bindices].
 
template<class T >
void Math::RemoveElements (VectorTemplate< T > &A, const std::vector< int > &indices)
 Removes the indexed elements of A (shrinking A)
 
template<class T >
void Math::RemoveElements (SparseArray< T > &A, const std::vector< int > &indices)
 Removes the indexed elements of A (shrinking A)
 
template<class T >
void Math::AddElements (VectorTemplate< T > &A, const std::vector< int > &indices, T fill)
 The inverse of RemoveElements. More...
 
template<class T >
void Math::SetRows (MatrixTemplate< T > &A, const std::vector< int > &indices, T fill)
 Sets the indexed rows of A to fill.
 
template<class T >
void Math::SetElements (MatrixTemplate< T > &A, const std::vector< int > &rows, const std::vector< int > &cols, T fill)
 Sets A[r,c] = fill for all r in rows and all c in columns.
 
template<class T >
void Math::SetElements (MatrixTemplate< T > &A, const std::vector< int > &rows, const std::vector< int > &cols, const MatrixTemplate< T > &fill)
 Sets A[r,c] = fill for all r in rows and all c in columns. More...
 
template<class T >
void Math::GetElements (const MatrixTemplate< T > &A, const std::vector< int > &rows, const std::vector< int > &cols, MatrixTemplate< T > &B)
 Sets B[i,j] = A[rows[i],cols[j]] for all i and j.
 
template<class T >
void Math::CopyElements (MatrixTemplate< T > &A, const std::vector< int > &arows, const std::vector< int > &acols, const MatrixTemplate< T > &B, const std::vector< int > &brows, const std::vector< int > &bcols)
 Sets A[ar,ac] = B[br,bc] for all (ar,br) in arows x brows, (ac,bc) in acols x bcols.
 
template<class T >
void Math::RemoveElements (MatrixTemplate< T > &A, const std::vector< int > &rows, const std::vector< int > &cols)
 Removes the indexed rows and columns of A (shrinking A)
 
template<class T >
void Math::SetColumns (MatrixTemplate< T > &A, const std::vector< int > &indices, T fill)
 Sets the indexed columns of A to fill.
 
template<class T >
void Math::SetRows (MatrixTemplate< T > &A, const std::vector< int > &indices, const VectorTemplate< T > &fill)
 Sets the indexed rows of A to the vector fill.
 
template<class T >
void Math::SetColumns (MatrixTemplate< T > &A, const std::vector< int > &indices, const VectorTemplate< T > &fill)
 Sets the indexed columns of A to the vector fill.
 
template<class T >
void Math::SetRows (MatrixTemplate< T > &A, const std::vector< int > &indices, const MatrixTemplate< T > &fill)
 Sets the indexed rows of A to the columns of the matrix fill. More...
 
template<class T >
void Math::SetColumns (MatrixTemplate< T > &A, const std::vector< int > &indices, const MatrixTemplate< T > &fill)
 Sets the indexed columns of A to the columns of the matrix fill. More...
 
template<class T >
void Math::GetRows (const MatrixTemplate< T > &A, const std::vector< int > &indices, MatrixTemplate< T > &B)
 Copies the indexed rows in A into B. More...
 
template<class T >
void Math::GetColumns (const MatrixTemplate< T > &A, const std::vector< int > &indices, MatrixTemplate< T > &B)
 Copies the indexed columns in A into B. More...
 
template<class T >
void Math::RemoveRows (MatrixTemplate< T > &A, const std::vector< int > &indices)
 Removes the rows of A indexed by the sorted list indices.
 
template<class T >
void Math::RemoveColumns (MatrixTemplate< T > &A, const std::vector< int > &indices)
 Removes the columns of A indexed by the sorted indices.
 
template<class T >
void Math::RemoveRows (SparseMatrixTemplate_RM< T > &A, const std::vector< int > &indices)
 Removes the rows of A indexed by the sorted list indices.
 
template<class T >
void Math::RemoveColumns (SparseMatrixTemplate_RM< T > &A, const std::vector< int > &indices)
 Removes the columns of A indexed by the sorted indices.
 
int Math::IsNaN (double x)
 Returns nonzero if x is not-a-number (NaN)
 
int Math::IsNaN (float x)
 
int Math::IsFinite (double x)
 Returns nonzero unless x is infinite or a NaN.
 
int Math::IsFinite (float x)
 
int Math::IsInf (double x)
 Returns +1 if x is +inf, -1 if x is -inf, and 0 otherwise.
 
int Math::IsInf (float x)
 
template<class T >
bool Math::LinearlyDependent_Robust (const VectorTemplate< T > &a, const VectorTemplate< T > &b, T &c, bool &cb, T eps=Epsilon)
 Robust determination of linear dependence. More...
 
template<class T >
bool Math::LinearlyDependent_Robust (const MatrixTemplate< T > &A, VectorTemplate< T > &c, T eps=Epsilon)
 A matrix version of the function above. More...
 
double Math::Abs (double x)
 
double Math::Sqr (double x)
 
double Math::Sqrt (double x)
 
double Math::Exp (double x)
 
double Math::Log (double x)
 
double Math::Pow (double x, double y)
 
double Math::Sin (double x)
 
double Math::Cos (double x)
 
double Math::Tan (double x)
 
double Math::Sinh (double x)
 
double Math::Cosh (double x)
 
double Math::Tanh (double x)
 
double Math::Asin (double x)
 
double Math::Acos (double x)
 
double Math::Atan (double x)
 
double Math::Atan2 (double y, double x)
 
double Math::Floor (double x)
 
double Math::Ceil (double x)
 
double Math::Mod (double x, double y)
 
float Math::Abs (float x)
 
float Math::Sqr (float x)
 
float Math::Sqrt (float x)
 
float Math::Exp (float x)
 
float Math::Log (float x)
 
float Math::Pow (float x, float y)
 
float Math::Sin (float x)
 
float Math::Cos (float x)
 
float Math::Tan (float x)
 
float Math::Sinh (float x)
 
float Math::Cosh (float x)
 
float Math::Tanh (float x)
 
float Math::Asin (float x)
 
float Math::Acos (float x)
 
float Math::Atan (float x)
 
float Math::Atan2 (float y, float x)
 
float Math::Floor (float x)
 
float Math::Ceil (float x)
 
float Math::Mod (float x, float y)
 
double Math::Inv (double x)
 1/x
 
double Math::Sign (double x)
 Returns {-1,0,1} if x is {<0,0,>0}.
 
double Math::Clamp (double x, double a, double b)
 Returns a if x < a, b if x > b, otherwise x.
 
double Math::Trunc (double x)
 
double Math::Frac (double x)
 
float Math::Inv (float x)
 
float Math::Sign (float x)
 
float Math::Clamp (float x, float a, float b)
 
float Math::Trunc (float x)
 
float Math::Frac (float x)
 
double Math::dot (double a, double b)
 Dot product of a scalar as a 1-d vector.
 
bool Math::FuzzyEquals (double a, double b, double eps=dEpsilon)
 Returns true if a and b are within +/- eps.
 
bool Math::FuzzyZero (double a, double eps=dEpsilon)
 Returns true if a is zero within +/- eps.
 
double Math::PseudoInv (double x, double eps=dZero)
 Returns 1/x if x is nonzero, otherwise 0.
 
float Math::dot (float a, float b)
 
bool Math::FuzzyEquals (float a, float b, float eps=fEpsilon)
 
bool Math::FuzzyZero (float a, float eps=fEpsilon)
 
float Math::PseudoInv (float x, float eps=fZero)
 
template<class T >
Real Math::Delta (T i, T j)
 Kronecker delta.
 
template<class T >
Real Math::Delta (T x)
 
double Math::DtoR (double f)
 Degree to radian conversion.
 
double Math::RtoD (double f)
 Radian to degree conversion.
 
float Math::DtoR (float f)
 
float Math::RtoD (float f)
 
template<class T >
Math::Norm (const VectorTemplate< T > &x, Real norm)
 
template<class T >
Math::Norm_L1 (const VectorTemplate< T > &x)
 
template<class T >
Math::Norm_L2 (const VectorTemplate< T > &x)
 
template<class T >
Math::Norm_L2_Safe (const VectorTemplate< T > &x)
 Same as above, but robust to over/underflow.
 
template<class T >
Math::Norm_LInf (const VectorTemplate< T > &x)
 
template<class T >
Math::Norm_Mahalanobis (const VectorTemplate< T > &x, const MatrixTemplate< T > &A)
 
template<class T >
Math::Norm_Weighted (const VectorTemplate< T > &x, Real norm, const VectorTemplate< T > &w)
 
template<class T >
Math::Norm_WeightedL1 (const VectorTemplate< T > &x, const VectorTemplate< T > &w)
 
template<class T >
Math::Norm_WeightedL2 (const VectorTemplate< T > &x, const VectorTemplate< T > &w)
 
template<class T >
Math::Norm_WeightedLInf (const VectorTemplate< T > &x, const VectorTemplate< T > &w)
 
template<class T >
Math::Distance (const VectorTemplate< T > &x, const VectorTemplate< T > &y, Real norm)
 
template<class T >
Math::Distance_L1 (const VectorTemplate< T > &x, const VectorTemplate< T > &y)
 
template<class T >
Math::Distance_L2 (const VectorTemplate< T > &x, const VectorTemplate< T > &y)
 
template<class T >
Math::Distance_L2_Safe (const VectorTemplate< T > &x, const VectorTemplate< T > &y)
 Same as above, but robust to over/underflow.
 
template<class T >
Math::Distance_LInf (const VectorTemplate< T > &x, const VectorTemplate< T > &y)
 
template<class T >
Math::Distance_Mahalanobis (const VectorTemplate< T > &x, const VectorTemplate< T > &y, const MatrixTemplate< T > &A)
 
template<class T >
Math::Distance_Weighted (const VectorTemplate< T > &x, const VectorTemplate< T > &y, Real norm, const VectorTemplate< T > &w)
 
template<class T >
Math::Distance_WeightedL1 (const VectorTemplate< T > &x, const VectorTemplate< T > &y, const VectorTemplate< T > &w)
 
template<class T >
Math::Distance_WeightedL2 (const VectorTemplate< T > &x, const VectorTemplate< T > &y, const VectorTemplate< T > &w)
 
template<class T >
Math::Distance_WeightedLInf (const VectorTemplate< T > &x, const VectorTemplate< T > &y, const VectorTemplate< T > &w)
 
template<class T >
Math::Norm_L1 (const MatrixTemplate< T > &A)
 
template<class T >
Math::Norm_LInf (const MatrixTemplate< T > &A)
 
template<class T >
Math::Norm_Frobenius (const MatrixTemplate< T > &A)
 
template<class T >
Math::Norm_Frobenius_Safe (const MatrixTemplate< T > &A)
 Same as above, but robust to over/underflow.
 
template<class T >
Math::Distance_L1 (const MatrixTemplate< T > &A, const MatrixTemplate< T > &B)
 
template<class T >
Math::Distance_LInf (const MatrixTemplate< T > &A, const MatrixTemplate< T > &B)
 
template<class T >
Math::Distance_Frobenius (const MatrixTemplate< T > &A, const MatrixTemplate< T > &B)
 
template<class T >
Math::Distance_Frobenius_Safe (const MatrixTemplate< T > &A, const MatrixTemplate< T > &B)
 Same as above, but robust to over/underflow.
 
int Math::quadratic (double a, double b, double c, double &x1, double &x2)
 
int Math::cubic (double a, double b, double c, double d, double x[3])
 
double Math::pythag (double a, double b)
 Returns c where a^2+b^2=c^2.
 
double Math::pythag_leg (double a, double c)
 Returns b where a^2+b^2=c^2.
 
double Math::Sinc (double x)
 Computes the sinc function sin(x)/x (stable for small x)
 
double Math::Sinc_Dx (double x)
 Computes the derivative of the sinc function.
 
double Math::dFactorial (unsigned int n)
 Computes the factorial of n, with double precision.
 
double Math::dLogFactorial (unsigned int n)
 Computes the log of the factorial of n.
 
double Math::dChoose (unsigned int n, unsigned int k)
 Computes n choose k in double precision.
 
double Math::dLogChoose (unsigned int n, unsigned int k)
 Computes the log of n choose k.
 
double Math::TaylorCoeff (double x, unsigned int n)
 Computes the taylor series coefficient x^n/n!
 
double Math::Gamma (double x)
 Computes the gamma function.
 
double Math::LogGamma (double x)
 Computes log gamma(x)
 
double Math::GammaInv (double x)
 Computes 1 / gamma(x)
 
double Math::Beta (double a, double b)
 Computes the beta function B(a,b)
 
double Math::LogBeta (double a, double b)
 Computes log B(a,b)
 
double Math::NormalizedIncompleteBeta (double a, double b, double x)
 Computes the normalized incomplete beta function B(a,b,x)
 
double Math::Erf (double x)
 Computes the error function.
 
double Math::ErfComplimentary (double x)
 Computes the complimentary error function?
 
int Math::FuzzySign (double x, double eps=dEpsilon)
 Returns -1 if x<eps, 0 if |x|<=eps, 1 if x>eps.
 
bool Math::OpposingSigns_pos (double a, double b)
 
bool Math::OpposingSigns_neg (double a, double b)
 Same as above, but treats 0 as a negative number.
 
int Math::quadratic (float a, float b, float c, float &x1, float &x2)
 
int Math::cubic (float a, float b, float c, float d, float x[3])
 
float Math::pythag (float a, float b)
 
float Math::pythag_leg (float a, float c)
 
float Math::Sinc (float x)
 
float Math::Sinc_Dx (float x)
 
float Math::fFactorial (unsigned int n)
 
float Math::fLogFactorial (unsigned int n)
 
float Math::fChoose (unsigned int n, unsigned int k)
 
float Math::fLogChoose (unsigned int n, unsigned int k)
 
float Math::TaylorCoeff (float x, unsigned int n)
 
float Math::Gamma (float x)
 
float Math::LogGamma (float x)
 
float Math::GammaInv (float x)
 
float Math::Beta (float a, float b)
 
float Math::LogBeta (float a, float b)
 
float Math::NormalizedIncompleteBeta (float a, float b, float x)
 
float Math::Erf (float x)
 
float Math::ErfComplimentary (float x)
 
int Math::FuzzySign (float x, float eps=fEpsilon)
 
bool Math::OpposingSigns_pos (float a, float b)
 
bool Math::OpposingSigns_neg (float a, float b)
 
template<class T >
Math::IntegerPower (const T x, int i)
 Calculates x^i where i is an integer (in O(log i) time)
 
unsigned int Math::Factorial (unsigned int n)
 Returns n! in O(n) time.
 
unsigned int Math::FactorialTruncated (unsigned int n, unsigned int k)
 Returns n!/(n-k)! in O(k) time.
 
unsigned int Math::Choose (unsigned int n, unsigned int k)
 Returns `n choose k' = n!/k!(n-k)! in O(k) time.
 
Real Math::rFactorial (unsigned int n)
 
Real Math::LogFactorial (unsigned int n)
 
Real Math::rChoose (unsigned int n, unsigned int k)
 
Real Math::LogChoose (unsigned int n, unsigned int k)
 
void Math::Srand (unsigned long seed)
 
long int Math::RandInt ()
 Generates a random int.
 
long int Math::RandInt (long int n)
 
Real Math::Rand ()
 Generates a random Real uniformly in [0,1].
 
Real Math::Rand (Real a, Real b)
 Generates a random Real uniformly in [a,b].
 
Real Math::RandGaussian ()
 
Real Math::RandGaussian (Real mean, Real stddev)
 Generates a random Real in a Gaussian distribution.
 
bool Math::RandBool ()
 Generates a random boolean that is true with probability 0.5.
 
bool Math::RandBool (Real p)
 Generates a random boolean that is true with probability p.
 
std::ostream & Math::operator<< (std::ostream &out, ConvergenceResult r)
 
ConvergenceResult Math::Root_Bisection (RealFunction &f, Real &a, Real &b, Real &x, Real tol)
 Uses bisection to bracket f's root. More...
 
ConvergenceResult Math::Root_Secant (RealFunction &f, Real x0, Real &x1, int &maxIters, Real tolx, Real tolf)
 Uses the secant method to search for f's root. More...
 
ConvergenceResult Math::Root_SecantBracket (RealFunction &f, Real &a, Real &b, Real &x, int &iters, Real tolx, Real tolf)
 
ConvergenceResult Math::Root_Newton (RealFunction &f, Real &x, int &maxIters, Real tolx, Real tolf)
 Performs Newton's method, which uses the derivative of f to search for it's root. More...
 
ConvergenceResult Math::Root_NewtonBracket (RealFunction &f, Real a, Real b, Real &x, int &maxIters, Real tolx, Real tolf)
 Same as above, but the interval [a,b] must be known to contain a root.
 
ConvergenceResult Math::Root_Newton (ScalarFieldFunction &f, const Vector &x0, Vector &x, int &maxIters, Real tolx, Real tolf)
 Same as Root_Newton(), but takes a scalar field function as input.
 
ConvergenceResult Math::Root_Newton (VectorFieldFunction &f, const Vector &x0, Vector &x, int &maxIters, Real tolx, Real tolf)
 Same as Root_Newton(), but takes a vector field function as input.
 
int Math::WeightedSample (const std::vector< Real > &weights)
 Samples an integer with weighted probability. More...
 
int Math::WeightedSample (const std::vector< Real > &weights, Real totWeight)
 Same as above, but the sum of all weights, W, is provided.
 
int Math::CumulativeWeightedSample (const std::vector< Real > &partialSumWeights)
 
void Math::RandomAllocate (std::vector< int > &num, size_t total)
 Allocates total samples within the buckets in num, roughly evenly. An O(n) algorithm where n is the number of buckets. More...
 
void Math::RandomAllocate (std::vector< int > &num, size_t total, const std::vector< Real > &weights)
 Same as above, but with weights. More...
 
Real Math::Sample (const Interval &s)
 Uniformly samples the given intervals.
 
Real Math::Sample (const ClosedIntervalSet &s)
 Uniformly samples the interval set.
 
void Math::SampleCircle (Real r, Real &x, Real &y)
 Uniform distribution on boundary of a circle with radius r.
 
void Math::SampleDisk (Real r, Real &x, Real &y)
 Uniform distribution inside a circle with radius r.
 
void Math::SampleTriangle (Real &x, Real &y)
 Uniform distribution in the triangle whose vertices are (0,0),(1,0),(0,1)
 
void Math::SampleBall (Real r, Real &x, Real &y, Real &z)
 Uniform distribution on boundary of a sphere with radius r.
 
void Math::SampleSphere (Real r, Real &x, Real &y, Real &z)
 Uniform distribution inside a sphere with radius r.
 
void Math::SampleHyperBall (Real r, std::vector< Real > &v)
 Uniformly samples from a hyper-ball of dimension v.size()
 
void Math::SampleHyperSphere (Real r, std::vector< Real > &v)
 Uniformly samples from a hyper-sphere of dimension v.size()
 
virtual void Math::SparseVectorFunction::Jacobian (const Vector &x, Matrix &J)
 
virtual void Math::SparseVectorFunction::Jacobian_i (const Vector &x, int i, Vector &Ji)
 
virtual void Math::SparseVectorFunction::Hessian_i (const Vector &x, int i, Matrix &Hi)
 
virtual void Math::SparseVectorFunction::Jacobian_Sparse (const Vector &x, SparseMatrix &J)=0
 
virtual void Math::SparseVectorFunction::Jacobian_i_Sparse (const Vector &x, int i, SparseVector &Ji)=0
 
virtual void Math::SparseVectorFunction::Hessian_i_Sparse (const Vector &x, int i, SparseMatrix &Hi)
 

Variables

StandardRNG Math::rng
 

Detailed Description

Definitions of mathematical concepts and numerical algorithms.

Generates random gaussian distributed floating point values.

NEEDED ON SOLARIS END SOLARIS SECTION

Uses a given uniform random number generator, generates values in a gaussian with 0 mean and standard deviation 1.

Function Documentation

bool Math::AABBClipLine ( const Vector x0,
const Vector dx,
const Vector bmin,
const Vector bmax,
Real &  u0,
Real &  u1 
)

Clips the line segment x=x0+u*dx, with t in [u0,u1] to the AABB (bmin,bmax). Returns false if there is no intersection.

Referenced by AABBContains().

int Math::AABBLineSearch ( const Vector x0,
const Vector dx,
const Vector bmin,
const Vector bmax,
Real &  t 
)

For a point inside the AABB (bmin,bmax), limits the desired step t x = x0+t*dx such that x is inside the AABB. Returns the index responsible for this limit

Referenced by AABBContains(), and Optimization::BCMinimizationProblem::LineMinimizationStep().

Real Math::AABBMargin ( const Vector x,
const Vector bmin,
const Vector bmax,
int &  index 
)
inline

Returns the minimum distance from x to the boundaries of the AABB (bmin,bmax). Also returns the element index that contains the minimum margin.

Real Math::AABBMargin ( const Vector x,
const Vector bmin,
const Vector bmax 
)
inline

Returns the minimum distance from x to the boundaries of the AABB (bmin,bmax)

template<class T >
void Math::AddElements ( VectorTemplate< T > &  A,
const std::vector< int > &  indices,
fill 
)

The inverse of RemoveElements.

Expands A such that the elements indexed by indices are set to fill. A must be able to expand to size A.n + indices.size()

Referenced by Optimization::InequalityMargin().

Real Math::AM2E ( RealFunction2 f,
Real  h,
Real  t0,
Real  t1,
Real  w0,
Real  w1 
)

Adams-Bashforth 2 step explicit method for 1D ODEs.

Returns w2 given previous 2 time steps

Referenced by AM2_predictor_corrector_step().

Real Math::AM2I ( RealFunction2 f,
Real  h,
Real  t0,
Real  t1,
Real  t2,
Real  w0,
Real  w1,
Real  w2 
)

Adams-Moulton 2 step implicit method for 1D ODEs.

Implicit, so it returns w2 (given w2!)

Referenced by AM2_predictor_corrector_step().

void Math::BracketMin ( Real &  a,
Real &  b,
Real &  c,
Real &  fa,
Real &  fb,
Real &  fc,
RealFunction func 
)

Returns a bracketing triplet given some a,b.

A bracketing triplet [a,b,c] is such that b is between a and c, and f(b) is less than both f(a) and f(c). The function values are returned as well.

Referenced by ParabolicMinimization().

template<class Matrix , class Preconditioner >
int Math::CG ( const Matrix A,
Vector x,
const Vector b,
const Preconditioner &  M,
int &  max_iter,
Real &  tol 
)

Solves the symmetric positive definite linear system Ax=b using the Conjugate Gradient method. Uses any type of matrix A with a method A.mul(x,b) (b=Ax) where b,x are vectors, and any preconditioner P with method P.solve(r,x) x = P*r where r,x are vectors.

CG follows the algorithm described on p. 15 in the SIAM Templates book.

The return value indicates convergence within max_iter (input) iterations (0), or no convergence within max_iter iterations (1).

Upon successful return, output arguments have the following values:

   x  --  approximate solution to Ax = b

max_iter – the number of iterations performed before the tolerance was reached tol – the residual after the final iteration

int Math::cubic ( double  a,
double  b,
double  c,
double  d,
double  x[3] 
)

Computes up to 3 soln's to quadratic equation a^3 x + b^2 x + c x + d = 0. Returns the number of solutions (0 to 3)

References quadratic(), and Sign().

Referenced by ErfComplimentary(), and OpposingSigns_neg().

int Math::CumulativeWeightedSample ( const std::vector< Real > &  partialSumWeights)

Same as above, but the array stores cumulative weights (i.e. partial sums) O(log n) algorithm

References Rand().

Real Math::ddfCenteredDifference ( RealFunction f,
Real  x,
Real  h 
)

centered differences for 2nd derivative f''(x) ~= 1/h^2*(f(x+h) - 2f(x) + f(x-h)) + O(h^2)

References ddfCenteredDifference().

Referenced by ddfCenteredDifference(), and TestGradients().

Real Math::dfCenteredDifference ( RealFunction f,
Real  x,
Real  h 
)

centered differences f'(x) ~= 1/2h*(f(x+h) - f(x-h)) + O(h^2)

References dfCenteredDifference().

Referenced by dfCenteredDifference(), dfCenteredDifferenceAdaptive(), and TestDeriv().

Real Math::dfCenteredDifferenceAdaptive ( RealFunction f,
Real  x,
Real  h0,
Real  tol 
)

adaptive centered differences with h determined dynamically starting from h0 such that the (approximate) error is no greater than tol

References dfCenteredDifference(), and dfCenteredDifferenceAdaptive().

Referenced by dfCenteredDifferenceAdaptive(), and GradientCenteredDifferenceAdaptive().

void Math::Euler ( DiffEqFunction f,
Real  a,
Real  b,
const Vector alpha,
int  n,
Vector wn 
)

Solve an ODE system using Euler's method.

Steps forward the ODE system

y' = f(t,y)
y(a) = alpha

using n iterations of Euler's method to reach time b.

Referenced by IntegratedControlSet::Contains(), and IntegratedControlSpace::Simulate().

void Math::Euler_step ( DiffEqFunction f,
Real  t0,
Real  h,
const Vector w0,
Vector w1 
)

Euler step for an ODE system.

Steps forward the ODE system

y' = f(t,y)
y(t0) = w0

by the time step h, placing the result in w1.

Referenced by IntegratedControlSpace::Simulate().

template<class T >
void Math::GetColumns ( const MatrixTemplate< T > &  A,
const std::vector< int > &  indices,
MatrixTemplate< T > &  B 
)
inline

Copies the indexed columns in A into B.

B has dimensions A.m by indices.size()

template<class T >
void Math::GetRows ( const MatrixTemplate< T > &  A,
const std::vector< int > &  indices,
MatrixTemplate< T > &  B 
)
inline

Copies the indexed rows in A into B.

B has dimensions indices.size() by A.n.

void Math::GradientCenteredDifferenceAdaptive ( ScalarFieldFunction f,
Vector x,
Real  h0,
Real  tol,
Vector g 
)

adaptive centered differences with h determined dynamically starting from h0 such that the (approximate) error is no greater than tol

References dfCenteredDifferenceAdaptive(), and Inv().

template<class T >
void Math::HouseholderApply ( tau,
const VectorTemplate< T > &  v,
VectorTemplate< T > &  w 
)

Applies a householder transformation tau,v to vector w

template<class T >
void Math::HouseholderHM1 ( tau,
MatrixTemplate< T > &  A 
)

Applies a householder transformation v,tau to a matrix being built up from the identity matrix, using the first column of A as a householder vector

template<class T >
void Math::HouseholderPostMultiply ( tau,
const VectorTemplate< T > &  v,
MatrixTemplate< T > &  A 
)

Applies a householder transformation v,tau to matrix m from the right hand side in order to zero out rows

template<class T >
void Math::HouseholderPreMultiply ( tau,
const VectorTemplate< T > &  v,
MatrixTemplate< T > &  A 
)

Applies a householder transformation v,tau to matrix A

template<class T >
T Math::HouseholderTransform ( VectorTemplate< T > &  v)

Replace v[0:n-1] with a householder vector (v[0:n-1]) and coefficient tau that annihilate v[1:n-1]. Tau is returned

References pythag().

template<class T >
bool Math::LinearlyDependent_Robust ( const VectorTemplate< T > &  a,
const VectorTemplate< T > &  b,
T &  c,
bool &  cb,
eps = Epsilon 
)

Robust determination of linear dependence.

Calculates a constant c s.t. they're linearly dependent within rel error eps and |c| <= 1.

2 cases, (1) a*c = b with maxabs(a*c-b)/|a| <= eps. (2) a = c*b with maxabs(a-c*b)/|b| <= eps. in case 1, cb = false, in case 2, cb=true. c is chosen by pseudoinverse

Returns
True if the vectors are dependent.

Referenced by Math3D::Plane3D::allIntersections().

template<class T >
bool Math::LinearlyDependent_Robust ( const MatrixTemplate< T > &  A,
VectorTemplate< T > &  c,
eps = Epsilon 
)

A matrix version of the function above.

Returns
A vector c s.t. A*c = 0. All coefficients |ci| <= 1 At least one ci = 1.
bool Math::OpposingSigns_pos ( double  a,
double  b 
)
inline

Returns true of a and be have different signs, treating 0 as a positive number

Referenced by OpposingSigns_neg().

template<class T >
int Math::OrthonormalBasis ( const VectorTemplate< T > *  x,
VectorTemplate< T > *  basis,
int  n 
)

Performs the Gram-Schmidt process to get an orthonormal basis for the span of the input vectors X. Returns the number of nonzero vectors in the output basis

References dot(), and Inv().

Referenced by Math::RowEchelon< T >::getNullspace().

Real Math::ParabolicLineMinimization ( ScalarFieldFunction f,
const Vector x,
const Vector n,
int  maxIters,
Real  tol 
)

Finds a minimum t* of f(x + t*n), using parabolic minimization Other parameters are the same as ParabolicMinimization.

References ParabolicMinimization().

Referenced by Optimization::BCMinimizationProblem::LineMinimizationStep(), and Optimization::MinimizationProblem::SolveCG().

ConvergenceResult Math::ParabolicMinimization ( Real  ax,
Real  bx,
Real  cx,
RealFunction f,
int &  maxIters,
Real  tol,
Real &  xmin 
)

Brent's algorithm for parabolic minimization.

Brackets the minimum to a fractional precision of about tol. [ax,bx,cx] are a bracketing triplet. The abscissa of the minimum is returned as xmin, and the result of convergence is returned (either ConvergenceX or MaxItersReached). The minimum function value is not returned... The number of iterations taken is returned in maxIters.

The second version only takes a starting point, and finds a minimum from there.

References BracketMin().

Referenced by ParabolicLineMinimization(), and ParabolicLineMinimization_i().

int Math::quadratic ( double  a,
double  b,
double  c,
double &  x1,
double &  x2 
)

Computes up to 2 soln's to quadratic equation a^2 x + b x + c = 0. Returns the number of solutions (0, 1, or 2)

Referenced by Math3D::Plane2D::allIntersections(), Math3D::Sphere3D::closestPoint(), cubic(), ErfComplimentary(), Math3D::Cylinder3D::intersects(), and OpposingSigns_neg().

void Math::RandomAllocate ( vector< int > &  num,
size_t  total 
)

Allocates total samples within the buckets in num, roughly evenly. An O(n) algorithm where n is the number of buckets.

Specifically, this allocates at least floor(total/n) samples to each bucket, then distributes the remaining total-n*floor(total/n) such that no bucket receives more than 1 extra sample.

Allocates total samples within the buckets in num, roughly evenly. An O(n) algorithm where n is the number of buckets.

References Rand().

Referenced by Statistics::LinearProcessHMM::Posterior(), and Statistics::GaussianMixtureModel::TrainEM().

void Math::RandomAllocate ( vector< int > &  num,
size_t  total,
const vector< Real > &  weights 
)

Same as above, but with weights.

Same as above, but with weights.

References Rand().

Real Math::RKF ( RealFunction2 f,
Real  a,
Real  b,
Real  alpha,
Real  tol,
Real  hmax,
Real  hmin 
)

Runge-Kutta-Fehlberg method for 1D ODEs.

For the IVP

y' = f(t,y)
y(a) = alpha

does the Runge-Kutta-Fehlberg method with tolerance tol, max step size hmax, min step size hmin to reach time b.

ConvergenceResult Math::Root_Bisection ( RealFunction f,
Real &  a,
Real &  b,
Real &  x,
Real  tol 
)

Uses bisection to bracket f's root.

[a,b] must be a range such that f(a) and f(b) have opposing signs. [a,b] is returned as a refined bracket. Linear convergence. The number of iterations used is ceil(log2(b-a)-log2(eps)).

References Sign().

ConvergenceResult Math::Root_Newton ( RealFunction f,
Real &  x,
int &  maxIters,
Real  tolx,
Real  tolf 
)

Performs Newton's method, which uses the derivative of f to search for it's root.

f.Deriv() must be defined. Quadratic convergence. The # of iterations is returned in maxIters.

Referenced by Math::InequalityConstraint::Push().

ConvergenceResult Math::Root_Secant ( RealFunction f,
Real  x0,
Real &  x1,
int &  maxIters,
Real  tolx,
Real  tolf 
)

Uses the secant method to search for f's root.

Order of convergence ~1.6. The # of iterations is returned in maxIters.

ConvergenceResult Math::Root_SecantBracket ( RealFunction f,
Real &  a,
Real &  b,
Real &  x,
int &  maxIters,
Real  tolx,
Real  tolf 
)

Same as above, but the interval [a,b] must be known to contain a root. [a,b] is returned as a refined bracket.

References Sign().

Referenced by Math::InequalityConstraint::LineSearch().

Real Math::RungeKutta4 ( RealFunction2 f,
Real  a,
Real  b,
Real  alpha,
int  n 
)

Runge-Kutta 4 method for 1D ODEs.

Solves the initial value problem

y' = f(t,y)
y(a) = alpha

using n iterations of Runge-kutta order 4 to reach time b.

References RungeKutta4_step().

void Math::RungeKutta4 ( DiffEqFunction f,
Real  a,
Real  b,
const Vector alpha,
int  n,
Vector wn 
)

Solve an ODE system using the Runge Kutta 4 method.

Steps forward the ODE system

y' = f(t,y)
y(a) = alpha

using n iterations of Runge Kutta 4 to reach time b.

References RungeKutta4_step().

Real Math::RungeKutta4_step ( RealFunction2 f,
Real  t0,
Real  h,
Real  w 
)

Runge-Kutta 4 step for 1D ODEs.

Steps forward the initial value problem

y' = f(t,y)
y(t0) = w

by the time step h.

Referenced by IntegratedControlSpace::Simulate().

void Math::RungeKutta4_step ( DiffEqFunction f,
Real  t0,
Real  h,
const Vector w0,
Vector w1 
)

Runge-Kutta 4 step for an ODE system.

Steps forward the ODE system

y' = f(t,y)
y(t0) = w0

by the time step h, placing the result in w1.

Referenced by RungeKutta4().

template<class T >
void Math::SetColumns ( MatrixTemplate< T > &  A,
const std::vector< int > &  indices,
const MatrixTemplate< T > &  fill 
)
inline

Sets the indexed columns of A to the columns of the matrix fill.

The fill matrix is A.m by indices.size(). For copying from a matrix to another using the same set of indices, use CopyColumns().

template<class T >
void Math::SetElements ( VectorTemplate< T > &  A,
const std::vector< int > &  indices,
const VectorTemplate< T > &  fill 
)
inline

Sets A[indices] = fill.

The fill vector is of size indices.size(). For copying from a vector to another using the same set of indices, use CopyElements().

template<class T >
void Math::SetElements ( MatrixTemplate< T > &  A,
const std::vector< int > &  rows,
const std::vector< int > &  cols,
const MatrixTemplate< T > &  fill 
)
inline

Sets A[r,c] = fill for all r in rows and all c in columns.

The fill matrix is of size rows.size() x cols.size(). For copying from a matrix to another using the same set of indices, use CopyElements().

template<class T >
void Math::SetRows ( MatrixTemplate< T > &  A,
const std::vector< int > &  indices,
const MatrixTemplate< T > &  fill 
)
inline

Sets the indexed rows of A to the columns of the matrix fill.

The fill matrix is indices.size() by A.n. For copying from a matrix to another using the same set of indices, use CopyRows().

bool Math::SolveCosSinEquation ( Real  a,
Real  b,
Real  c,
Real &  t1,
Real &  t2 
)

Solves a cos(x) + b sin(x) = c returns at most 2 different values of x, or false if there is no solution.

References FuzzyEquals(), and TransformCosSin_Sin().

Referenced by Atan_All().

void Math::TransformCosSin_Cos ( Real  a,
Real  b,
Real &  c,
Real &  d 
)

A "cos/sin" equation is a f(x) = cos(x) + b sin(x) which can be expressed as f(x) = c*cos(x+d)

References FuzzyEquals(), and pythag().

Referenced by Atan_All(), and SolveCosSinGreater().

int Math::WeightedSample ( const std::vector< Real > &  weights)

Samples an integer with weighted probability.

The probability of sampling integer i in [0,n) is wi / W where W = sum of all wi.

References WeightedSample().

Referenced by KinodynamicTree::DeleteSubTree(), RestartShortcutMotionPlanner::Plan(), RestartShortcutMotionPlanner::PlanMore(), and Statistics::GaussianMixtureModel::TrainEM().