Classes | Enumerations | Functions

QuadProgPP Namespace Reference

Classes

class  Vector
class  CanonicalBaseVector
class  Matrix
class  QuadProg

Enumerations

enum  MType { DIAG }

Functions

std::set< unsigned int > seq (unsigned int s, unsigned int e)
std::set< unsigned int > singleton (unsigned int i)
template<typename T >
Vector< T > operator+ (const Vector< T > &rhs)
template<typename T >
Vector< T > operator+ (const Vector< T > &lhs, const Vector< T > &rhs)
template<typename T >
Vector< T > operator+ (const Vector< T > &lhs, const T &a)
template<typename T >
Vector< T > operator+ (const T &a, const Vector< T > &rhs)
template<typename T >
Vector< T > operator- (const Vector< T > &rhs)
template<typename T >
Vector< T > operator- (const Vector< T > &lhs, const Vector< T > &rhs)
template<typename T >
Vector< T > operator- (const Vector< T > &lhs, const T &a)
template<typename T >
Vector< T > operator- (const T &a, const Vector< T > &rhs)
template<typename T >
Vector< T > operator* (const Vector< T > &lhs, const Vector< T > &rhs)
template<typename T >
Vector< T > operator* (const Vector< T > &lhs, const T &a)
template<typename T >
Vector< T > operator* (const T &a, const Vector< T > &rhs)
template<typename T >
Vector< T > operator/ (const Vector< T > &lhs, const Vector< T > &rhs)
template<typename T >
Vector< T > operator/ (const Vector< T > &lhs, const T &a)
template<typename T >
Vector< T > operator/ (const T &a, const Vector< T > &rhs)
template<typename T >
Vector< T > operator^ (const Vector< T > &lhs, const Vector< T > &rhs)
template<typename T >
Vector< T > operator^ (const Vector< T > &lhs, const T &a)
template<typename T >
Vector< T > operator^ (const T &a, const Vector< T > &rhs)
template<typename T >
bool operator== (const Vector< T > &v, const Vector< T > &w)
template<typename T >
bool operator!= (const Vector< T > &v, const Vector< T > &w)
template<typename T >
bool operator< (const Vector< T > &v, const Vector< T > &w)
template<typename T >
bool operator<= (const Vector< T > &v, const Vector< T > &w)
template<typename T >
bool operator> (const Vector< T > &v, const Vector< T > &w)
template<typename T >
bool operator>= (const Vector< T > &v, const Vector< T > &w)
template<typename T >
std::ostream & operator<< (std::ostream &os, const Vector< T > &v)
template<typename T >
std::istream & operator>> (std::istream &is, Vector< T > &v)
template<typename T >
sum (const Vector< T > &v)
template<typename T >
prod (const Vector< T > &v)
template<typename T >
mean (const Vector< T > &v)
template<typename T >
median (const Vector< T > &v)
template<typename T >
stdev (const Vector< T > &v, bool sample_correction=false)
template<typename T >
var (const Vector< T > &v, bool sample_correction=false)
template<typename T >
max (const Vector< T > &v)
template<typename T >
min (const Vector< T > &v)
template<typename T >
unsigned int index_max (const Vector< T > &v)
template<typename T >
unsigned int index_min (const Vector< T > &v)
template<typename T >
dot_prod (const Vector< T > &a, const Vector< T > &b)
template<typename T >
Vector< T > exp (const Vector< T > &v)
template<typename T >
Vector< T > log (const Vector< T > &v)
template<typename T >
Vector< T > sqrt (const Vector< T > &v)
template<typename T >
Vector< T > pow (const Vector< T > &v, double a)
template<typename T >
Vector< T > abs (const Vector< T > &v)
template<typename T >
Vector< T > sign (const Vector< T > &v)
template<typename T >
unsigned int partition (Vector< T > &v, unsigned int begin, unsigned int end)
template<typename T >
void quicksort (Vector< T > &v, unsigned int begin, unsigned int end)
template<typename T >
Vector< T > sort (const Vector< T > &v)
template<typename T >
Vector< double > rank (const Vector< T > &v)
template<typename T >
Matrix< T > operator+ (const Matrix< T > &rhs)
template<typename T >
Matrix< T > operator+ (const Matrix< T > &lhs, const Matrix< T > &rhs)
template<typename T >
Matrix< T > operator+ (const Matrix< T > &lhs, const T &a)
template<typename T >
Matrix< T > operator+ (const T &a, const Matrix< T > &rhs)
template<typename T >
Matrix< T > operator- (const Matrix< T > &rhs)
template<typename T >
Matrix< T > operator- (const Matrix< T > &lhs, const Matrix< T > &rhs)
template<typename T >
Matrix< T > operator- (const Matrix< T > &lhs, const T &a)
template<typename T >
Matrix< T > operator- (const T &a, const Matrix< T > &rhs)
template<typename T >
Matrix< T > operator* (const Matrix< T > &lhs, const Matrix< T > &rhs)
template<typename T >
Matrix< T > operator* (const Matrix< T > &lhs, const T &a)
template<typename T >
Matrix< T > operator* (const T &a, const Matrix< T > &rhs)
template<typename T >
Matrix< T > operator/ (const Matrix< T > &lhs, const Matrix< T > &rhs)
template<typename T >
Matrix< T > operator/ (const Matrix< T > &lhs, const T &a)
template<typename T >
Matrix< T > operator/ (const T &a, const Matrix< T > &rhs)
template<typename T >
Matrix< T > operator^ (const Matrix< T > &lhs, const T &a)
template<typename T >
bool operator== (const Matrix< T > &a, const Matrix< T > &b)
template<typename T >
bool operator!= (const Matrix< T > &a, const Matrix< T > &b)
template<typename T >
std::ostream & operator<< (std::ostream &os, const Matrix< T > &m)
template<typename T >
std::istream & operator>> (std::istream &is, Matrix< T > &m)
template<typename T >
sign (const T &v)
template<typename T >
dist (const T &a, const T &b)
template<typename T >
void svd (const Matrix< T > &A, Matrix< T > &U, Vector< T > &W, Matrix< T > &V)
template<typename T >
Matrix< T > pinv (const Matrix< T > &A)
template<typename T >
int lu (const Matrix< T > &A, Matrix< T > &LU, Vector< unsigned int > &index)
template<typename T >
Vector< T > lu_solve (const Matrix< T > &LU, const Vector< T > &b, Vector< unsigned int > &index)
template<typename T >
void lu_solve (const Matrix< T > &LU, Vector< T > &x, const Vector< T > &b, Vector< unsigned int > &index)
template<typename T >
Matrix< T > lu_inverse (const Matrix< T > &A)
template<typename T >
lu_det (const Matrix< T > &A)
template<typename T >
void cholesky (const Matrix< T > A, Matrix< T > &LL)
template<typename T >
Matrix< T > cholesky (const Matrix< T > A)
template<typename T >
Vector< T > cholesky_solve (const Matrix< T > &LL, const Vector< T > &b)
template<typename T >
void cholesky_solve (const Matrix< T > &LL, Vector< T > &x, const Vector< T > &b)
template<typename T >
void forward_elimination (const Matrix< T > &L, Vector< T > &y, const Vector< T > b)
template<typename T >
Vector< T > forward_elimination (const Matrix< T > &L, const Vector< T > b)
template<typename T >
void backward_elimination (const Matrix< T > &U, Vector< T > &x, const Vector< T > &y)
template<typename T >
Vector< T > backward_elimination (const Matrix< T > &U, const Vector< T > y)
template<typename T >
void random (Matrix< T > &m)
template<typename T >
Vector< T > sum (const Matrix< T > &m)
template<typename T >
Vector< T > r_sum (const Matrix< T > &m)
template<typename T >
all_sum (const Matrix< T > &m)
template<typename T >
Vector< T > prod (const Matrix< T > &m)
template<typename T >
Vector< T > r_prod (const Matrix< T > &m)
template<typename T >
all_prod (const Matrix< T > &m)
template<typename T >
Vector< T > mean (const Matrix< T > &m)
template<typename T >
Vector< T > r_mean (const Matrix< T > &m)
template<typename T >
all_mean (const Matrix< T > &m)
template<typename T >
Vector< T > var (const Matrix< T > &m, bool sample_correction=false)
template<typename T >
Vector< T > stdev (const Matrix< T > &m, bool sample_correction=false)
template<typename T >
Vector< T > r_var (const Matrix< T > &m, bool sample_correction=false)
template<typename T >
Vector< T > r_stdev (const Matrix< T > &m, bool sample_correction=false)
template<typename T >
Vector< T > max (const Matrix< T > &m)
template<typename T >
Vector< T > r_max (const Matrix< T > &m)
template<typename T >
Vector< T > min (const Matrix< T > &m)
template<typename T >
Vector< T > r_min (const Matrix< T > &m)
template<typename T >
Matrix< T > exp (const Matrix< T > &m)
template<typename T >
Matrix< T > sqrt (const Matrix< T > &m)
template<typename T >
Matrix< T > kron (const Vector< T > &b, const Vector< T > &a)
template<typename T >
Matrix< T > t (const Matrix< T > &a)
template<typename T >
Matrix< T > dot_prod (const Matrix< T > &a, const Matrix< T > &b)
template<typename T >
Matrix< T > dot_prod (const Matrix< T > &a, const Vector< T > &b)
template<typename T >
Matrix< T > dot_prod (const Vector< T > &a, const Matrix< T > &b)
template<typename T >
Matrix< double > rank (const Matrix< T > m)
template<typename T >
Matrix< double > r_rank (const Matrix< T > m)
void compute_d (Vector< double > &d, const Matrix< double > &J, const Vector< double > &np)
void update_z (Vector< double > &z, const Matrix< double > &J, const Vector< double > &d, int iq)
void update_r (const Matrix< double > &R, Vector< double > &r, const Vector< double > &d, int iq)
bool add_constraint (Matrix< double > &R, Matrix< double > &J, Vector< double > &d, int &iq, double &rnorm)
void delete_constraint (Matrix< double > &R, Matrix< double > &J, Vector< int > &A, Vector< double > &u, int n, int p, int &iq, int l)
void cholesky_decomposition (Matrix< double > &A)
void cholesky_solve (const Matrix< double > &L, Vector< double > &x, const Vector< double > &b)
void forward_elimination (const Matrix< double > &L, Vector< double > &y, const Vector< double > &b)
void backward_elimination (const Matrix< double > &U, Vector< double > &x, const Vector< double > &y)
double scalar_product (const Vector< double > &x, const Vector< double > &y)
double distance (double a, double b)
void print_matrix (const char *name, const Matrix< double > &A, int n=-1, int m=-1)
template<typename T >
void print_vector (const char *name, const Vector< T > &v, int n=-1)

Detailed Description

Index utilities


Enumeration Type Documentation

Enumerator:
DIAG 

Definition at line 32 of file Array.h.

{ DIAG };

Function Documentation

template<typename T >
Vector<T> QuadProgPP::abs ( const Vector< T > &  v ) [inline]
bool QuadProgPP::add_constraint ( Matrix< double > &  R,
Matrix< double > &  J,
Vector< double > &  d,
int &  iq,
double &  rnorm 
)

Definition at line 532 of file QuadProg.cpp.

References distance(), print_matrix(), print_vector(), and QuadProgPP::Vector< T >::size().

Referenced by QuadProgPP::QuadProg::solve_quadprog().

{
  int n = d.size();
#ifdef TRACE_SOLVER
  std::cout << "Add constraint " << iq << '/';
#endif
  register int i, j, k;
  double cc, ss, h, t1, t2, xny;
        
  /* we have to find the Givens rotation which will reduce the element
    d[j] to zero.
    if it is already zero we don't have to do anything, except of
    decreasing j */  
  for (j = n - 1; j >= iq + 1; j--)
  {
    /* The Givens rotation is done with the matrix (cc cs, cs -cc).
    If cc is one, then element (j) of d is zero compared with element
    (j - 1). Hence we don't have to do anything. 
    If cc is zero, then we just have to switch column (j) and column (j - 1) 
    of J. Since we only switch columns in J, we have to be careful how we
    update d depending on the sign of gs.
    Otherwise we have to apply the Givens rotation to these columns.
    The i - 1 element of d has to be updated to h. */
    cc = d[j - 1];
    ss = d[j];
    h = distance(cc, ss);
    if (fabs(h) < std::numeric_limits<double>::epsilon()) // h == 0
      continue;
    d[j] = 0.0;
    ss = ss / h;
    cc = cc / h;
    if (cc < 0.0)
    {
      cc = -cc;
      ss = -ss;
      d[j - 1] = -h;
    }
    else
      d[j - 1] = h;
    xny = ss / (1.0 + cc);
    for (k = 0; k < n; k++)
    {
      t1 = J[k][j - 1];
      t2 = J[k][j];
      J[k][j - 1] = t1 * cc + t2 * ss;
      J[k][j] = xny * (t1 + J[k][j - 1]) - t2;
    }
  }
  /* update the number of constraints added*/
  iq++;
  /* To update R we have to put the iq components of the d vector
    into column iq - 1 of R
    */
  for (i = 0; i < iq; i++)
    R[i][iq - 1] = d[i];
#ifdef TRACE_SOLVER
  std::cout << iq << std::endl;
  print_matrix("R", R, iq, iq);
  print_matrix("J", J);
  print_vector("d", d, iq);
#endif
  
  if (fabs(d[iq - 1]) <= std::numeric_limits<double>::epsilon() * R_norm) 
  {
    // problem degenerate
    return false;
  }
  R_norm = std::max<double>(R_norm, fabs(d[iq - 1]));
  return true;
}
template<typename T >
T QuadProgPP::all_mean ( const Matrix< T > &  m )

Definition at line 2297 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), and QuadProgPP::Matrix< T >::nrows().

{
  T tmp = (T)0;
  for (unsigned int i = 0; i < m.nrows(); i++)
    for (unsigned int j = 0; j < m.ncols(); j++)
      tmp += m[i][j];
  return tmp / (m.nrows() * m.ncols());
}
template<typename T >
T QuadProgPP::all_prod ( const Matrix< T > &  m )

Definition at line 2259 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), and QuadProgPP::Matrix< T >::nrows().

{
  T tmp = (T)1;
  for (unsigned int i = 0; i < m.nrows(); i++)
    for (unsigned int j = 0; j < m.ncols(); j++)
      tmp *= m[i][j];
  return tmp;
}
template<typename T >
T QuadProgPP::all_sum ( const Matrix< T > &  m )

Definition at line 2229 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), and QuadProgPP::Matrix< T >::nrows().

{
  T tmp = (T)0;
  for (unsigned int i = 0; i < m.nrows(); i++)
    for (unsigned int j = 0; j < m.ncols(); j++)
      tmp += m[i][j];
  return tmp;
}
template<typename T >
Vector<T> QuadProgPP::backward_elimination ( const Matrix< T > &  U,
const Vector< T >  y 
)

Definition at line 2180 of file Array.h.

References forward_elimination().

{
  Vector<T> x;
  forward_elimination(U, x, y);
        
  return x;
}
template<typename T >
void QuadProgPP::backward_elimination ( const Matrix< T > &  U,
Vector< T > &  x,
const Vector< T > &  y 
)

Definition at line 2160 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), QuadProgPP::Matrix< T >::nrows(), QuadProgPP::Vector< T >::resize(), and QuadProgPP::Vector< T >::size().

Referenced by cholesky_solve().

{
  if (U.ncols() != U.nrows())
    throw std::logic_error("Error in Backward elimination: matrix must be squared (upper triangular)");
  if (y.size() != U.nrows())
    throw std::logic_error("Error in Backward elimination: b vector must be of the same dimensions of U matrix");
  int i, j, n = y.size();
  x.resize(n);
        
  x[n - 1] = y[n - 1] / U[n - 1][n - 1];
  for (i = n - 2; i >= 0; i--)
    {
      x[i] = y[i];
      for (j = i + 1; j < n; j++)
        x[i] -= U[i][j] * x[j];
      x[i] = x[i] / U[i][i];
    }
}
void QuadProgPP::backward_elimination ( const Matrix< double > &  U,
Vector< double > &  x,
const Vector< double > &  y 
) [inline]

Definition at line 769 of file QuadProg.cpp.

References QuadProgPP::Matrix< T >::nrows().

{
  register int i, j, n = U.nrows();
        
  x[n - 1] = y[n - 1] / U[n - 1][n - 1];
  for (i = n - 2; i >= 0; i--)
  {
    x[i] = y[i];
    for (j = i + 1; j < n; j++)
      x[i] -= U[i][j] * x[j];
    x[i] = x[i] / U[i][i];
  }
}
template<typename T >
Matrix<T> QuadProgPP::cholesky ( const Matrix< T >  A )

Definition at line 2098 of file Array.h.

References cholesky().

{
  Matrix<T> LL;
  cholesky(A, LL);
        
  return LL;
}
template<typename T >
void QuadProgPP::cholesky ( const Matrix< T >  A,
Matrix< T > &  LL 
)

Definition at line 2068 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), QuadProgPP::Matrix< T >::nrows(), sqrt(), and sum().

Referenced by cholesky().

{
  if (A.ncols() != A.nrows())
    throw std::logic_error("Error in Cholesky decomposition: matrix must be squared");
  int i, j, k, n = A.ncols();
  double sum;
  LL = A;
        
  for (i = 0; i < n; i++)
    {
      for (j = i; j < n; j++)
        {
          sum = LL[i][j];
          for (k = i - 1; k >= 0; k--)
            sum -= LL[i][k] * LL[j][k];
          if (i == j) 
            {
              if (sum <= 0.0)
                throw std::logic_error("Error in Cholesky decomposition: matrix is not postive definite");
              LL[i][i] = ::std::sqrt(sum);
            }
          else
            LL[j][i] = sum / LL[i][i];
        }
      for (k = i + 1; k < n; k++)
        LL[i][k] = LL[k][i];
    } 
}
void QuadProgPP::cholesky_decomposition ( Matrix< double > &  A )

Definition at line 711 of file QuadProg.cpp.

References QuadProgPP::Matrix< T >::nrows(), print_matrix(), sqrt(), and sum().

Referenced by QuadProgPP::QuadProg::solve_quadprog().

{
  register int i, j, k, n = A.nrows();
  register double sum;
        
  for (i = 0; i < n; i++)
  {
    for (j = i; j < n; j++)
    {
      sum = A[i][j];
      for (k = i - 1; k >= 0; k--)
        sum -= A[i][k]*A[j][k];
      if (i == j) 
            {
              if (sum <= 0.0)
        {
          std::ostringstream os;
          // raise error
          print_matrix("A", A);
          os << "Error in cholesky decomposition, sum: " << sum;
          throw std::logic_error(os.str());
          exit(-1);
        }
              A[i][i] = ::std::sqrt(sum);
            }
      else
        A[j][i] = sum / A[i][i];
    }
    for (k = i + 1; k < n; k++)
      A[i][k] = A[k][i];
  } 
}
template<typename T >
Vector<T> QuadProgPP::cholesky_solve ( const Matrix< T > &  LL,
const Vector< T > &  b 
)

Definition at line 2107 of file Array.h.

References backward_elimination(), forward_elimination(), QuadProgPP::Matrix< T >::ncols(), QuadProgPP::Matrix< T >::nrows(), and QuadProgPP::Vector< T >::size().

Referenced by cholesky_solve(), and QuadProgPP::QuadProg::solve_quadprog().

{
  if (LL.ncols() != LL.nrows())
    throw std::logic_error("Error in Cholesky solve: matrix must be squared");
  unsigned int n = LL.ncols();
  if (b.size() != n)
    throw std::logic_error("Error in Cholesky decomposition: b vector must be of the same dimensions of LU matrix");
  Vector<T> x, y;
        
  /* Solve L * y = b */
  forward_elimination(LL, y, b);
  /* Solve L^T * x = y */
  backward_elimination(LL, x, y);
        
  return x;
}
template<typename T >
void QuadProgPP::cholesky_solve ( const Matrix< T > &  LL,
Vector< T > &  x,
const Vector< T > &  b 
)

Definition at line 2125 of file Array.h.

References cholesky_solve().

{
  x = cholesky_solve(LL, b);
}
void QuadProgPP::cholesky_solve ( const Matrix< double > &  L,
Vector< double > &  x,
const Vector< double > &  b 
)

Definition at line 744 of file QuadProg.cpp.

References backward_elimination(), forward_elimination(), and QuadProgPP::Matrix< T >::nrows().

{
  int n = L.nrows();
  Vector<double> y(n);
        
  /* Solve L * y = b */
  forward_elimination(L, y, b);
  /* Solve L^T * x = y */
  backward_elimination(L, x, y);
}
void QuadProgPP::compute_d ( Vector< double > &  d,
const Matrix< double > &  J,
const Vector< double > &  np 
) [inline]

Definition at line 489 of file QuadProg.cpp.

References QuadProgPP::Vector< T >::size(), and sum().

Referenced by QuadProgPP::QuadProg::solve_quadprog().

{
  register int i, j, n = d.size();
  register double sum;
  
  /* compute d = H^T * np */
  for (i = 0; i < n; i++)
  {
    sum = 0.0;
    for (j = 0; j < n; j++)
      sum += J[j][i] * np[j];
    d[i] = sum;
  }
}
void QuadProgPP::delete_constraint ( Matrix< double > &  R,
Matrix< double > &  J,
Vector< int > &  A,
Vector< double > &  u,
int  n,
int  p,
int &  iq,
int  l 
)

Definition at line 603 of file QuadProg.cpp.

References distance().

Referenced by QuadProgPP::QuadProg::solve_quadprog().

{
#ifdef TRACE_SOLVER
  std::cout << "Delete constraint " << l << ' ' << iq;
#endif
  register int i, j, k, qq = -1; // just to prevent warnings from smart compilers
  double cc, ss, h, xny, t1, t2;
  
  /* Find the index qq for active constraint l to be removed */
  for (i = p; i < iq; i++)
    if (A[i] == l)
    {
      qq = i;
      break;
    }
      
  /* remove the constraint from the active set and the duals */
  for (i = qq; i < iq - 1; i++)
    {
      A[i] = A[i + 1];
      u[i] = u[i + 1];
      for (j = 0; j < n; j++)
        R[j][i] = R[j][i + 1];
    }
      
  A[iq - 1] = A[iq];
  u[iq - 1] = u[iq];
  A[iq] = 0; 
  u[iq] = 0.0;
  for (j = 0; j < iq; j++)
    R[j][iq - 1] = 0.0;
  /* constraint has been fully removed */
  iq--;
#ifdef TRACE_SOLVER
  std::cout << '/' << iq << std::endl;
#endif 
  
  if (iq == 0)
    return;
  
  for (j = qq; j < iq; j++)
  {
    cc = R[j][j];
    ss = R[j + 1][j];
    h = distance(cc, ss);
    if (fabs(h) < std::numeric_limits<double>::epsilon()) // h == 0
      continue;
    cc = cc / h;
    ss = ss / h;
    R[j + 1][j] = 0.0;
    if (cc < 0.0)
    {
      R[j][j] = -h;
      cc = -cc;
      ss = -ss;
    }
    else
      R[j][j] = h;
    
    xny = ss / (1.0 + cc);
    for (k = j + 1; k < iq; k++)
    {
      t1 = R[j][k];
      t2 = R[j + 1][k];
      R[j][k] = t1 * cc + t2 * ss;
      R[j + 1][k] = xny * (t1 + R[j][k]) - t2;
    }
    for (k = 0; k < n; k++)
    {
      t1 = J[k][j];
      t2 = J[k][j + 1];
      J[k][j] = t1 * cc + t2 * ss;
      J[k][j + 1] = xny * (J[k][j] + t1) - t2;
    }
  }
}
template<typename T >
T QuadProgPP::dist ( const T &  a,
const T &  b 
)
double QuadProgPP::distance ( double  a,
double  b 
) [inline]
template<typename T >
T QuadProgPP::dot_prod ( const Vector< T > &  a,
const Vector< T > &  b 
) [inline]

Definition at line 710 of file Array.h.

References QuadProgPP::Vector< T >::size(), and sum().

Referenced by pinv().

{
  T sum = (T)0;
  if (a.size() != b.size())
    throw std::logic_error("Dotprod error: the vectors are not the same size");
  for (unsigned int i = 0; i < a.size(); i++)
    sum += a[i] * b[i];
        
  return sum;
}
template<typename T >
Matrix<T> QuadProgPP::dot_prod ( const Matrix< T > &  a,
const Vector< T > &  b 
)

Definition at line 2502 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), QuadProgPP::Matrix< T >::nrows(), and QuadProgPP::Vector< T >::size().

{
  if (a.ncols() != b.size())
    throw std::logic_error("Error matrix dot product: dimensions of the matrix and the vector are not compatible");
  Matrix<T> tmp(a.nrows(), 1);
  for (unsigned int i = 0; i < tmp.nrows(); i++)
    {
      tmp[i][0] = (T)0;
      for (unsigned int k = 0; k < a.ncols(); k++)
        tmp[i][0] += a[i][k] * b[k];
    }
                
  return tmp;
}
template<typename T >
Matrix<T> QuadProgPP::dot_prod ( const Vector< T > &  a,
const Matrix< T > &  b 
)

Definition at line 2518 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), and QuadProgPP::Vector< T >::size().

{
  if (a.size() != b.ncols())
    throw std::logic_error("Error matrix dot product: dimensions of the vector and matrix are not compatible");
  Matrix<T> tmp(1, b.ncols());
  for (unsigned int j = 0; j < tmp.ncols(); j++)
    {
      tmp[0][j] = (T)0;
      for (unsigned int k = 0; k < a.size(); k++)
        tmp[0][j] += a[k] * b[k][j];
    }
                
  return tmp;
}
template<typename T >
Matrix<T> QuadProgPP::dot_prod ( const Matrix< T > &  a,
const Matrix< T > &  b 
)

Definition at line 2485 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), and QuadProgPP::Matrix< T >::nrows().

{
  if (a.ncols() != b.nrows())
    throw std::logic_error("Error matrix dot product: dimensions of the matrices are not compatible");
  Matrix<T> tmp(a.nrows(), b.ncols());
  for (unsigned int i = 0; i < tmp.nrows(); i++)
    for (unsigned int j = 0; j < tmp.ncols(); j++)
      {
        tmp[i][j] = (T)0;
        for (unsigned int k = 0; k < a.ncols(); k++)
          tmp[i][j] += a[i][k] * b[k][j];
      }
                        
  return tmp;
}
template<typename T >
Vector<T> QuadProgPP::exp ( const Vector< T > &  v ) [inline]
template<typename T >
Matrix<T> QuadProgPP::exp ( const Matrix< T > &  m )

Single element mathematical functions

Definition at line 2435 of file Array.h.

References exp(), QuadProgPP::Matrix< T >::ncols(), and QuadProgPP::Matrix< T >::nrows().

{
  Matrix<T> tmp(m.nrows(), m.ncols());
        
  for (unsigned int i = 0; i < m.nrows(); i++)
    for (unsigned int j = 0; j < m.ncols(); j++)
      tmp[i][j] = exp(m[i][j]);
        
  return tmp;
}
void QuadProgPP::forward_elimination ( const Matrix< double > &  L,
Vector< double > &  y,
const Vector< double > &  b 
) [inline]

Definition at line 755 of file QuadProg.cpp.

References QuadProgPP::Matrix< T >::nrows().

{
  register int i, j, n = L.nrows();
        
  y[0] = b[0] / L[0][0];
  for (i = 1; i < n; i++)
  {
    y[i] = b[i];
    for (j = 0; j < i; j++)
      y[i] -= L[i][j] * y[j];
    y[i] = y[i] / L[i][i];
  }
}
template<typename T >
void QuadProgPP::forward_elimination ( const Matrix< T > &  L,
Vector< T > &  y,
const Vector< T >  b 
)

Definition at line 2131 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), QuadProgPP::Matrix< T >::nrows(), QuadProgPP::Vector< T >::resize(), and QuadProgPP::Vector< T >::size().

Referenced by backward_elimination(), cholesky_solve(), forward_elimination(), and QuadProgPP::QuadProg::solve_quadprog().

{
  if (L.ncols() != L.nrows())
    throw std::logic_error("Error in Forward elimination: matrix must be squared (lower triangular)");
  if (b.size() != L.nrows())
    throw std::logic_error("Error in Forward elimination: b vector must be of the same dimensions of L matrix");
  int i, j, n = b.size();
  y.resize(n);
        
  y[0] = b[0] / L[0][0];
  for (i = 1; i < n; i++)
    {
      y[i] = b[i];
      for (j = 0; j < i; j++)
        y[i] -= L[i][j] * y[j];
      y[i] = y[i] / L[i][i];
    }
}
template<typename T >
Vector<T> QuadProgPP::forward_elimination ( const Matrix< T > &  L,
const Vector< T >  b 
)

Definition at line 2151 of file Array.h.

References forward_elimination().

{
  Vector<T> y;
  forward_elimination(L, y, b);
        
  return y;
}
template<typename T >
unsigned int QuadProgPP::index_max ( const Vector< T > &  v ) [inline]

Definition at line 687 of file Array.h.

References max(), and QuadProgPP::Vector< T >::size().

{
  unsigned int max = 0;
  for (unsigned int i = 1; i < v.size(); i++)
    if (v[i] > v[max])
      max = i;
        
  return max;
}
template<typename T >
unsigned int QuadProgPP::index_min ( const Vector< T > &  v ) [inline]

Definition at line 698 of file Array.h.

References min(), and QuadProgPP::Vector< T >::size().

{
  unsigned int min = 0;
  for (unsigned int i = 1; i < v.size(); i++)
    if (v[i] < v[min])
      min = i;
        
  return min;
}
template<typename T >
Matrix<T> QuadProgPP::kron ( const Vector< T > &  b,
const Vector< T > &  a 
)

Matrix operators

Definition at line 2463 of file Array.h.

References QuadProgPP::Vector< T >::size().

{
  Matrix<T> tmp(b.size(), a.size());
  for (unsigned int i = 0; i < b.size(); i++)
    for (unsigned int j = 0; j < a.size(); j++)
      tmp[i][j] = a[j] * b[i];
        
  return tmp;
}
template<typename T >
Vector<T> QuadProgPP::log ( const Vector< T > &  v ) [inline]
template<typename T >
int QuadProgPP::lu ( const Matrix< T > &  A,
Matrix< T > &  LU,
Vector< unsigned int > &  index 
)

Definition at line 1934 of file Array.h.

References max(), QuadProgPP::Matrix< T >::ncols(), QuadProgPP::Matrix< T >::nrows(), and QuadProgPP::Vector< T >::resize().

Referenced by lu_det(), and lu_inverse().

{
  if (A.ncols() != A.nrows())
    throw std::logic_error("Error in LU decomposition: matrix must be squared");
  int i, p, j, k, n = A.ncols(), ex;
  T val, tmp;
  Vector<T> d(n);
  LU = A;
  index.resize(n);
        
  ex = 1;
  for (i = 0; i < n; i++)
    {
      index[i] = i;
      val = (T)0.0;
      for (j = 0; j < n; j++)
        val = std::max(val, (T)fabs(LU[i][j]));
      if (val == (T)0.0)
        std::logic_error("Error in LU decomposition: matrix was singular");
      d[i] = val;
    }

  for (k = 0; k < n - 1; k++)
    {
      p = k;
      val = fabs(LU[k][k]) / d[k];
      for (i = k + 1; i < n; i++)
        {
          tmp = fabs(LU[i][k]) / d[i];
          if (tmp > val)
            {
              val = tmp;
              p = i;
            }
        }
      if (val == (T)0.0)
        std::logic_error("Error in LU decomposition: matrix was singular");
      if (p > k)
        {
          ex = -ex;
          std::swap(index[k], index[p]);
          std::swap(d[k], d[p]);
          for (j = 0; j < n; j++)
            std::swap(LU[k][j], LU[p][j]);
        }
                
      for (i = k + 1; i < n; i++)
        {
          LU[i][k] /= LU[k][k];
          for (j = k + 1; j < n; j++)
            LU[i][j] -= LU[i][k] * LU[k][j];
        }
    }
  if (LU[n - 1][n - 1] == (T)0.0)
    std::logic_error("Error in LU decomposition: matrix was singular");
                
  return ex;
}
template<typename T >
T QuadProgPP::lu_det ( const Matrix< T > &  A )

Definition at line 2054 of file Array.h.

References QuadProgPP::Matrix< T >::extractDiag(), lu(), QuadProgPP::Matrix< T >::ncols(), QuadProgPP::Matrix< T >::nrows(), and prod().

{
  if (A.ncols() != A.nrows())
    throw std::logic_error("Error in LU determinant: matrix must be squared");  
  unsigned int d;
  Matrix<T> LU;
  Vector<unsigned int> index;
        
  d = lu(A, LU, index);
        
  return d * prod(LU.extractDiag());
}
template<typename T >
Matrix<T> QuadProgPP::lu_inverse ( const Matrix< T > &  A )

Definition at line 2034 of file Array.h.

References lu(), lu_solve(), QuadProgPP::Matrix< T >::ncols(), QuadProgPP::Matrix< T >::nrows(), and QuadProgPP::CanonicalBaseVector< T >::reset().

{
  if (A.ncols() != A.nrows())
    throw std::logic_error("Error in LU invert: matrix must be squared");       
  unsigned int n = A.ncols();
  Matrix<T> A1(n, n), LU;
  Vector<unsigned int> index;
        
  lu(A, LU, index);
  CanonicalBaseVector<T> e(0, n);
  for (unsigned i = 0; i < n; i++)
    {
      e.reset(i);
      A1.setColumn(i, lu_solve(LU, e, index));
    }
        
  return A1;
}
template<typename T >
Vector<T> QuadProgPP::lu_solve ( const Matrix< T > &  LU,
const Vector< T > &  b,
Vector< unsigned int > &  index 
)

Definition at line 1994 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), QuadProgPP::Matrix< T >::nrows(), QuadProgPP::Vector< T >::size(), and sum().

Referenced by lu_inverse(), and lu_solve().

{
  if (LU.ncols() != LU.nrows())
    throw std::logic_error("Error in LU solve: LU matrix should be squared");
  unsigned int n = LU.ncols();
  if (b.size() != n)
    throw std::logic_error("Error in LU solve: b vector must be of the same dimensions of LU matrix");
  Vector<T> x((T)0.0, n);
  int i, j, p;
  T sum;
        
  p = index[0];
  x[0] = b[p];
        
  for (i = 1; i < n; i++)
    {
      sum = (T)0.0;
      for (j = 0; j < i; j++)
        sum += LU[i][j] * x[j];
      p = index[i];
      x[i] = b[p] - sum;
    }
  x[n - 1] /= LU[n - 1][n - 1];
  for (i = n - 2; i >= 0; i--)
    {
      sum = (T)0.0;
      for (j = i + 1; j < n; j++)
        sum += LU[i][j] * x[j];
      x[i] = (x[i] - sum) / LU[i][i];
    }
  return x;
}
template<typename T >
void QuadProgPP::lu_solve ( const Matrix< T > &  LU,
Vector< T > &  x,
const Vector< T > &  b,
Vector< unsigned int > &  index 
)

Definition at line 2028 of file Array.h.

References lu_solve().

{
  x = lu_solve(LU, b, index);
}
template<typename T >
T QuadProgPP::max ( const Vector< T > &  v ) [inline]

Definition at line 667 of file Array.h.

References QuadProgPP::Vector< T >::size().

Referenced by QmitkRenderWindow::AdjustRenderWindowMenuVisibility(), ANNmin_k::ANNmin_k(), ANNpr_queue::ANNpr_queue(), annSpread(), mitk::ExtrudedContour::BuildGeometry(), mitk::PolygonToRingFilter::BuildVtkTube(), mitk::CalculateGrayValueStatisticsTool::CalculateMinMax(), mitk::Interactor::CanHandleEvent(), mitk::PlanarPolygon::CheckForLineIntersection(), mitk::DataStorage::ComputeBoundingGeometry3D(), itk::BrainMaskExtractionImageFilter< TOutputImagePixelType >::ComputeHistogram(), mitk::Image::ComputeImageStatistics(), itk::DiffusionQballReconstructionImageFilter< TReferenceImagePixelType, TGradientImagePixelType, TOdfPixelType, NrOdfDirections, NrBasisFunctionCenters >::ComputeReconstructionMatrix(), mitk::DataStorage::ComputeTimeBounds(), QwtScaleDiv::contains(), QmitkPropertyDelegate::createEditor(), mitk::Image::Expand(), mitk::TimeSlicedGeometry::ExpandToNumberOfTimeSteps(), mitk::NavigationDataLandmarkTransformFilter::FindCorrespondentLandmarks(), mitk::BoundingObjectToSegmentationFilter::GenerateData(), mitk::CylindricToCartesianFilter::GenerateOutputInformation(), GenerateRandomNumber(), GenerateRandomPoint(), mitk::PropertyManager::GetDefaultLimits(), itk::OrientationDistributionFunction< TComponent, NOdfDirections >::GetGeneralizedGFA(), mitk::TimeSlicedGeometry::GetGeometry3D(), itk::OrientationDistributionFunction< TComponent, NOdfDirections >::GetInterpolatedComponent(), mitk::LabeledImageToSurfaceFilter::GetLabelForNthOutput(), mitk::SimpleHistogram::GetMax(), itk::OrientationDistributionFunction< TComponent, NOdfDirections >::GetNthDiffusionDirection(), itk::OrientationDistributionFunction< TComponent, NOdfDirections >::GetPrincipleCurvature(), itk::OrientationDistributionFunction< TComponent, NOdfDirections >::GetPrincipleDiffusionDirection(), mitk::Image::GetScalarValue2ndMinNoRecompute(), mitk::Image::GetScalarValueMinNoRecompute(), itk::OrientationDistributionFunction< TComponent, NOdfDirections >::GetStdDevByMaxValue(), mitk::Image::Image(), index_max(), mitk::Geometry3D::Initialize(), mitk::RenderingManager::InitializeViews(), QmitkSliceWidget::InitWidget(), mitk::MaskImageFilter::InternalComputeMask(), mitk::CalculateGrayValueStatisticsTool::ITKHistogramming(), QmitkRegionGrowingView::ItkImageProcessing(), lu(), max(), itk::OrientationDistributionFunction< TComponent, NOdfDirections >::MaxNormalize(), itk::OrientationDistributionFunction< TComponent, NOdfDirections >::MinMaxNormalize(), mitkPicFileReaderTest(), mitk::TimeSlicedGeometry::MSToTimeStep(), mitk::MeshMapper2D::Paint(), QxtItemDelegatePrivate::paintProgress(), mitk::SphereLandmarkProjector::ProjectLandmarks(), QmitkDiffusionTensorEstimation::QBallStandardAlgorithmsDeconvolutionButton(), QmitkDiffusionTensorEstimation::QBallStandardAlgorithmsDirectionButton(), r_max(), mitk::Image::ResetImageStatistics(), mitk::LevelWindow::SetAuto(), QwtPlot::setAxisScale(), QmitkSliderNavigatorWidget::SetLabelValues(), QmitkTransferFunctionCanvas::SetMax(), mitk::Stepper::SetRange(), mitk::RenderingManager::SetShading(), mitk::ManufacturerLogo::SetupCamera(), mitk::ManufacturerLogo::SetupPosition(), sl_fair_split(), sl_midpt_split(), QuadProgPP::QuadProg::solve_quadprog(), QmitkBasicImageProcessing::StartButtonClicked(), QmitkImageCropper::SurroundingCheck(), svd(), mitkClaronTrackingDeviceTestClass::TestToolConfiguration(), mitk::TimeSlicedGeometry::TimeStepToMS(), QxtSpanSliderPrivate::triggerAction(), QxtFlowViewAnimator::update(), mitk::TimeSlicedGeometry::UpdateInformation(), and QxtBaseSpinBox::validate().

{
  T value = v[0];
  for (unsigned int i = 1; i < v.size(); i++)
    value = std::max(v[i], value);
        
  return value;
}
template<typename T >
Vector<T> QuadProgPP::max ( const Matrix< T > &  m )

Definition at line 2365 of file Array.h.

References max(), QuadProgPP::Matrix< T >::ncols(), and QuadProgPP::Matrix< T >::nrows().

{
  Vector<T> res(m.ncols());
  double value;
  for (unsigned int j = 0; j < m.ncols(); j++)
    {
      value = m[0][j];
      for (unsigned int i = 1; i < m.nrows(); i++)
        value = std::max(m[i][j], value);
      res[j] = value;
    }
        
  return res;
}
template<typename T >
T QuadProgPP::mean ( const Vector< T > &  v ) [inline]
template<typename T >
Vector<T> QuadProgPP::mean ( const Matrix< T > &  m )

Definition at line 2269 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), and QuadProgPP::Matrix< T >::nrows().

{
  Vector<T> res((T)0, m.ncols());
  for (unsigned int j = 0; j < m.ncols(); j++)
    {
      for (unsigned int i = 0; i < m.nrows(); i++)
        res[j] += m[i][j];
      res[j] /= m.nrows();
    }
        
  return res;
}
template<typename T >
T QuadProgPP::median ( const Vector< T > &  v ) [inline]

Definition at line 635 of file Array.h.

References QuadProgPP::Vector< T >::size(), and sort().

Referenced by mitk::ManualSegmentationToSurfaceFilter::GenerateData(), and itk::OrientationDistributionFunction< TComponent, NOdfDirections >::GetPrincipleCurvature().

{
  Vector<T> tmp = sort(v);
  if (v.size() % 2 == 1) // it is an odd-sized vector
    return tmp[v.size() / 2];
  else
    return 0.5 * (tmp[v.size() / 2 - 1] + tmp[v.size() / 2]);
}
template<typename T >
T QuadProgPP::min ( const Vector< T > &  v ) [inline]

Definition at line 677 of file Array.h.

References min, and QuadProgPP::Vector< T >::size().

Referenced by QuadProgPP::Matrix< T >::extractDiag(), index_min(), and QuadProgPP::QuadProg::solve_quadprog().

{
  T value = v[0];
  for (unsigned int i = 1; i < v.size(); i++)
    value = std::min(v[i], value);
        
  return value;
}
template<typename T >
Vector<T> QuadProgPP::min ( const Matrix< T > &  m )

Definition at line 2397 of file Array.h.

References min, QuadProgPP::Matrix< T >::ncols(), and QuadProgPP::Matrix< T >::nrows().

{
  Vector<T> res(m.ncols());
  double value;
  for (unsigned int j = 0; j < m.ncols(); j++)
    {
      value = m[0][j];
      for (unsigned int i = 1; i < m.nrows(); i++)
        value = std::min(m[i][j], value);
      res[j] = value;
    }
        
  return res;
}
template<typename T >
bool QuadProgPP::operator!= ( const Matrix< T > &  a,
const Matrix< T > &  b 
) [inline]

Definition at line 1610 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), and QuadProgPP::Matrix< T >::nrows().

{
  if (a.nrows() != b.nrows() || a.ncols() != b.ncols())
    throw std::logic_error("Matrices of different size are not confrontable");
  for (unsigned i = 0; i < a.nrows(); i++)
    for (unsigned j = 0; j < a.ncols(); j++)
      if (a[i][j] != b[i][j])
        return true;
  return false;
}
template<typename T >
bool QuadProgPP::operator!= ( const Vector< T > &  v,
const Vector< T > &  w 
) [inline]

Definition at line 491 of file Array.h.

References QuadProgPP::Vector< T >::size().

{
  if (v.size() != w.size())
    throw std::logic_error("Vectors of different size are not confrontable");
  for (unsigned i = 0; i < v.size(); i++)
    if (v[i] != w[i])
      return true;
  return false;
}
template<typename T >
Vector<T> QuadProgPP::operator* ( const Vector< T > &  lhs,
const Vector< T > &  rhs 
) [inline]

Definition at line 343 of file Array.h.

References QuadProgPP::Vector< T >::size().

{
  if (lhs.size() != rhs.size())
    throw std::logic_error("Operator*: vectors have different sizes");
  Vector<T> tmp(lhs.size());
  for (unsigned int i = 0; i < lhs.size(); i++)
    tmp[i] = lhs[i] * rhs[i];
        
  return tmp;
}
template<typename T >
Matrix<T> QuadProgPP::operator* ( const Matrix< T > &  lhs,
const T &  a 
)

Definition at line 1452 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), and QuadProgPP::Matrix< T >::nrows().

{
  Matrix<T> tmp(lhs.nrows(), lhs.ncols());
  for (unsigned int i = 0; i < lhs.nrows(); i++)
    for (unsigned int j = 0; j < lhs.ncols(); j++)
      tmp[i][j] = lhs[i][j] * a;
        
  return tmp;
}
template<typename T >
Vector<T> QuadProgPP::operator* ( const T &  a,
const Vector< T > &  rhs 
) [inline]

Definition at line 365 of file Array.h.

References QuadProgPP::Vector< T >::size().

{
  Vector<T> tmp(rhs.size());
  for (unsigned int i = 0; i < rhs.size(); i++)
    tmp[i] = a * rhs[i];
                
  return tmp;
}
template<typename T >
Matrix<T> QuadProgPP::operator* ( const Matrix< T > &  lhs,
const Matrix< T > &  rhs 
)

Definition at line 1439 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), and QuadProgPP::Matrix< T >::nrows().

{
  if (lhs.ncols() != rhs.ncols() || lhs.nrows() != rhs.nrows())
    throw std::logic_error("Operator*: matrices have different sizes");
  Matrix<T> tmp(lhs.nrows(), lhs.ncols());
  for (unsigned int i = 0; i < lhs.nrows(); i++)
    for (unsigned int j = 0; j < lhs.ncols(); j++)
      tmp[i][j] = lhs[i][j] * rhs[i][j];
        
  return tmp;
}
template<typename T >
Matrix<T> QuadProgPP::operator* ( const T &  a,
const Matrix< T > &  rhs 
)

Definition at line 1463 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), and QuadProgPP::Matrix< T >::nrows().

{
  Matrix<T> tmp(rhs.nrows(), rhs.ncols());
  for (unsigned int i = 0; i < rhs.nrows(); i++)
    for (unsigned int j = 0; j < rhs.ncols(); j++)
      tmp[i][j] = a * rhs[i][j];
        
  return tmp;
}
template<typename T >
Vector<T> QuadProgPP::operator* ( const Vector< T > &  lhs,
const T &  a 
) [inline]

Definition at line 355 of file Array.h.

References QuadProgPP::Vector< T >::size().

{
  Vector<T> tmp(lhs.size());
  for (unsigned int i = 0; i < lhs.size(); i++)
    tmp[i] = lhs[i] * a;
                
  return tmp;
}
template<typename T >
Matrix<T> QuadProgPP::operator+ ( const Matrix< T > &  lhs,
const T &  a 
)

Definition at line 1332 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), and QuadProgPP::Matrix< T >::nrows().

{
  Matrix<T> tmp(lhs.nrows(), lhs.ncols());
  for (unsigned int i = 0; i < lhs.nrows(); i++)
    for (unsigned int j = 0; j < lhs.ncols(); j++)
      tmp[i][j] = lhs[i][j] + a;
        
  return tmp;
}
template<typename T >
Vector<T> QuadProgPP::operator+ ( const Vector< T > &  lhs,
const Vector< T > &  rhs 
) [inline]

Definition at line 231 of file Array.h.

References QuadProgPP::Vector< T >::size().

{
  if (lhs.size() != rhs.size())
    throw std::logic_error("Operator+: vectors have different sizes");
  Vector<T> tmp(lhs.size());
  for (unsigned int i = 0; i < lhs.size(); i++)
    tmp[i] = lhs[i] + rhs[i];
        
  return tmp;
}
template<typename T >
Vector<T> QuadProgPP::operator+ ( const Vector< T > &  rhs ) [inline]

Definition at line 225 of file Array.h.

{
  return rhs;
}
template<typename T >
Vector<T> QuadProgPP::operator+ ( const Vector< T > &  lhs,
const T &  a 
) [inline]

Definition at line 243 of file Array.h.

References QuadProgPP::Vector< T >::size().

{
  Vector<T> tmp(lhs.size());
  for (unsigned int i = 0; i < lhs.size(); i++)
    tmp[i] = lhs[i] + a;
                
  return tmp;
}
template<typename T >
Matrix<T> QuadProgPP::operator+ ( const Matrix< T > &  rhs )

Definition at line 1313 of file Array.h.

{
  return rhs;
}
template<typename T >
Matrix<T> QuadProgPP::operator+ ( const Matrix< T > &  lhs,
const Matrix< T > &  rhs 
)

Definition at line 1319 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), and QuadProgPP::Matrix< T >::nrows().

{
  if (lhs.ncols() != rhs.ncols() || lhs.nrows() != rhs.nrows())
    throw std::logic_error("Operator+: matrices have different sizes");
  Matrix<T> tmp(lhs.nrows(), lhs.ncols());
  for (unsigned int i = 0; i < lhs.nrows(); i++)
    for (unsigned int j = 0; j < lhs.ncols(); j++)
      tmp[i][j] = lhs[i][j] + rhs[i][j];
        
  return tmp;
}
template<typename T >
Matrix<T> QuadProgPP::operator+ ( const T &  a,
const Matrix< T > &  rhs 
)

Definition at line 1343 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), and QuadProgPP::Matrix< T >::nrows().

{
  Matrix<T> tmp(rhs.nrows(), rhs.ncols());
  for (unsigned int i = 0; i < rhs.nrows(); i++)
    for (unsigned int j = 0; j < rhs.ncols(); j++)
      tmp[i][j] = a + rhs[i][j];
        
  return tmp;
}
template<typename T >
Vector<T> QuadProgPP::operator+ ( const T &  a,
const Vector< T > &  rhs 
) [inline]

Definition at line 253 of file Array.h.

References QuadProgPP::Vector< T >::size().

{
  Vector<T> tmp(rhs.size());
  for (unsigned int i = 0; i < rhs.size(); i++)
    tmp[i] = a + rhs[i];
                
  return tmp;
}
template<typename T >
Vector<T> QuadProgPP::operator- ( const Vector< T > &  lhs,
const Vector< T > &  rhs 
) [inline]

Definition at line 290 of file Array.h.

References QuadProgPP::Vector< T >::size().

{
  if (lhs.size() != rhs.size())
    throw std::logic_error("Operator-: vectors have different sizes");
  Vector<T> tmp(lhs.size());
  for (unsigned int i = 0; i < lhs.size(); i++)
    tmp[i] = lhs[i] - rhs[i];
        
  return tmp;
}
template<typename T >
Vector<T> QuadProgPP::operator- ( const Vector< T > &  lhs,
const T &  a 
) [inline]

Definition at line 302 of file Array.h.

References QuadProgPP::Vector< T >::size().

{
  Vector<T> tmp(lhs.size());
  for (unsigned int i = 0; i < lhs.size(); i++)
    tmp[i] = lhs[i] - a;
                
  return tmp;
}
template<typename T >
Matrix<T> QuadProgPP::operator- ( const Matrix< T > &  lhs,
const Matrix< T > &  rhs 
)

Definition at line 1382 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), and QuadProgPP::Matrix< T >::nrows().

{
  if (lhs.ncols() != rhs.ncols() || lhs.nrows() != rhs.nrows())
    throw std::logic_error("Operator-: matrices have different sizes");
  Matrix<T> tmp(lhs.nrows(), lhs.ncols());
  for (unsigned int i = 0; i < lhs.nrows(); i++)
    for (unsigned int j = 0; j < lhs.ncols(); j++)
      tmp[i][j] = lhs[i][j] - rhs[i][j];
        
  return tmp;
}
template<typename T >
Matrix<T> QuadProgPP::operator- ( const Matrix< T > &  rhs )

Definition at line 1376 of file Array.h.

{       
  return (T)(-1) * rhs;
}
template<typename T >
Vector<T> QuadProgPP::operator- ( const T &  a,
const Vector< T > &  rhs 
) [inline]

Definition at line 312 of file Array.h.

References QuadProgPP::Vector< T >::size().

{
  Vector<T> tmp(rhs.size());
  for (unsigned int i = 0; i < rhs.size(); i++)
    tmp[i] = a - rhs[i];
                
  return tmp;
}
template<typename T >
Matrix<T> QuadProgPP::operator- ( const Matrix< T > &  lhs,
const T &  a 
)

Definition at line 1395 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), and QuadProgPP::Matrix< T >::nrows().

{
  Matrix<T> tmp(lhs.nrows(), lhs.ncols());
  for (unsigned int i = 0; i < lhs.nrows(); i++)
    for (unsigned int j = 0; j < lhs.ncols(); j++)
      tmp[i][j] = lhs[i][j] - a;
        
  return tmp;
}
template<typename T >
Matrix<T> QuadProgPP::operator- ( const T &  a,
const Matrix< T > &  rhs 
)

Definition at line 1406 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), and QuadProgPP::Matrix< T >::nrows().

{
  Matrix<T> tmp(rhs.nrows(), rhs.ncols());
  for (unsigned int i = 0; i < rhs.nrows(); i++)
    for (unsigned int j = 0; j < rhs.ncols(); j++)
      tmp[i][j] = a - rhs[i][j];
        
  return tmp;
}
template<typename T >
Vector<T> QuadProgPP::operator- ( const Vector< T > &  rhs ) [inline]

Definition at line 284 of file Array.h.

{
  return (T)(-1) * rhs;
}
template<typename T >
Vector<T> QuadProgPP::operator/ ( const T &  a,
const Vector< T > &  rhs 
) [inline]

Definition at line 418 of file Array.h.

References QuadProgPP::Vector< T >::size().

{
  Vector<T> tmp(rhs.size());
  for (unsigned int i = 0; i < rhs.size(); i++)
    tmp[i] = a / rhs[i];
                
  return tmp;
}
template<typename T >
Matrix<T> QuadProgPP::operator/ ( const Matrix< T > &  lhs,
const Matrix< T > &  rhs 
)

Definition at line 1496 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), and QuadProgPP::Matrix< T >::nrows().

{
  if (lhs.ncols() != rhs.ncols() || lhs.nrows() != rhs.nrows())
    throw std::logic_error("Operator+: matrices have different sizes");
  Matrix<T> tmp(lhs.nrows(), lhs.ncols());
  for (unsigned int i = 0; i < lhs.nrows(); i++)
    for (unsigned int j = 0; j < lhs.ncols(); j++)
      tmp[i][j] = lhs[i][j] / rhs[i][j];
        
  return tmp;
}
template<typename T >
Vector<T> QuadProgPP::operator/ ( const Vector< T > &  lhs,
const Vector< T > &  rhs 
) [inline]

Definition at line 396 of file Array.h.

References QuadProgPP::Vector< T >::size().

{
  if (lhs.size() != rhs.size())
    throw std::logic_error("Operator/: vectors have different sizes");
  Vector<T> tmp(lhs.size());
  for (unsigned int i = 0; i < lhs.size(); i++)
    tmp[i] = lhs[i] / rhs[i];
        
  return tmp;
}
template<typename T >
Matrix<T> QuadProgPP::operator/ ( const Matrix< T > &  lhs,
const T &  a 
)

Definition at line 1509 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), and QuadProgPP::Matrix< T >::nrows().

{
  Matrix<T> tmp(lhs.nrows(), lhs.ncols());
  for (unsigned int i = 0; i < lhs.nrows(); i++)
    for (unsigned int j = 0; j < lhs.ncols(); j++)
      tmp[i][j] = lhs[i][j] / a;
        
  return tmp;
}
template<typename T >
Vector<T> QuadProgPP::operator/ ( const Vector< T > &  lhs,
const T &  a 
) [inline]

Definition at line 408 of file Array.h.

References QuadProgPP::Vector< T >::size().

{
  Vector<T> tmp(lhs.size());
  for (unsigned int i = 0; i < lhs.size(); i++)
    tmp[i] = lhs[i] / a;
                
  return tmp;
}
template<typename T >
Matrix<T> QuadProgPP::operator/ ( const T &  a,
const Matrix< T > &  rhs 
)

Definition at line 1520 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), and QuadProgPP::Matrix< T >::nrows().

{
  Matrix<T> tmp(rhs.nrows(), rhs.ncols());
  for (unsigned int i = 0; i < rhs.nrows(); i++)
    for (unsigned int j = 0; j < rhs.ncols(); j++)
      tmp[i][j] = a / rhs[i][j];
        
  return tmp;
}
template<typename T >
bool QuadProgPP::operator< ( const Vector< T > &  v,
const Vector< T > &  w 
) [inline]

Definition at line 502 of file Array.h.

{
  if (v.size() != w.size())
    throw std::logic_error("Vectors of different size are not confrontable");
  for (unsigned i = 0; i < v.size(); i++)
    if (v[i] >= w[i])
      return false;
  return true;
}
template<typename T >
std::ostream& QuadProgPP::operator<< ( std::ostream &  os,
const Matrix< T > &  m 
)

Input/Output

Definition at line 1627 of file Array.h.

{
  os << std::endl << m.nrows() << " " << m.ncols() << std::endl;
  for (unsigned int i = 0; i < m.nrows(); i++)
    {
      for (unsigned int j = 0; j < m.ncols() - 1; j++)
        os << std::setw(20) << std::setprecision(16) << m[i][j] << ", ";
      os << std::setw(20) << std::setprecision(16) << m[i][m.ncols() - 1] << std::endl;
    }
        
  return os;
}
template<typename T >
std::ostream& QuadProgPP::operator<< ( std::ostream &  os,
const Vector< T > &  v 
) [inline]

Input/Output

Definition at line 549 of file Array.h.

{
  os << std::endl << v.size() << std::endl;
  for (unsigned int i = 0; i < v.size() - 1; i++)
    os << std::setw(20) << std::setprecision(16) << v[i] << ", ";
  os << std::setw(20) << std::setprecision(16) << v[v.size() - 1] << std::endl;
        
  return os;
}
template<typename T >
bool QuadProgPP::operator<= ( const Vector< T > &  v,
const Vector< T > &  w 
) [inline]

Definition at line 513 of file Array.h.

{
  if (v.size() != w.size())
    throw std::logic_error("Vectors of different size are not confrontable");
  for (unsigned i = 0; i < v.size(); i++)
    if (v[i] > w[i])
      return false;
  return true;
}
template<typename T >
bool QuadProgPP::operator== ( const Matrix< T > &  a,
const Matrix< T > &  b 
) [inline]

Definition at line 1598 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), and QuadProgPP::Matrix< T >::nrows().

{
  if (a.nrows() != b.nrows() || a.ncols() != b.ncols())
    throw std::logic_error("Matrices of different size are not confrontable");
  for (unsigned i = 0; i < a.nrows(); i++)
    for (unsigned j = 0; j < a.ncols(); j++)
      if (a[i][j] != b[i][j])
        return false;
  return true;
}
template<typename T >
bool QuadProgPP::operator== ( const Vector< T > &  v,
const Vector< T > &  w 
) [inline]

Definition at line 480 of file Array.h.

References QuadProgPP::Vector< T >::size().

{
  if (v.size() != w.size())
    throw std::logic_error("Vectors of different size are not confrontable");
  for (unsigned i = 0; i < v.size(); i++)
    if (v[i] != w[i])
      return false;
  return true;
}
template<typename T >
bool QuadProgPP::operator> ( const Vector< T > &  v,
const Vector< T > &  w 
) [inline]

Definition at line 524 of file Array.h.

References QuadProgPP::Vector< T >::size().

{
  if (v.size() != w.size())
    throw std::logic_error("Vectors of different size are not confrontable");
  for (unsigned i = 0; i < v.size(); i++)
    if (v[i] <= w[i])
      return false;
  return true;
}
template<typename T >
bool QuadProgPP::operator>= ( const Vector< T > &  v,
const Vector< T > &  w 
) [inline]

Definition at line 535 of file Array.h.

References QuadProgPP::Vector< T >::size().

{
  if (v.size() != w.size())
    throw std::logic_error("Vectors of different size are not confrontable");
  for (unsigned i = 0; i < v.size(); i++)
    if (v[i] < w[i])
      return false;
  return true;
}
template<typename T >
std::istream& QuadProgPP::operator>> ( std::istream &  is,
Matrix< T > &  m 
)

Definition at line 1641 of file Array.h.

References QuadProgPP::Matrix< T >::resize().

{
  int rows, cols;
  char comma;
  is >> rows >> cols;
  m.resize(rows, cols);
  for (unsigned int i = 0; i < rows; i++)
    for (unsigned int j = 0; j < cols; j++)
      is >> m[i][j] >> comma;
        
  return is;
}
template<typename T >
std::istream& QuadProgPP::operator>> ( std::istream &  is,
Vector< T > &  v 
)

Definition at line 560 of file Array.h.

References QuadProgPP::Vector< T >::resize().

{
  int elements;
  char comma;
  is >> elements;
  v.resize(elements);
  for (unsigned int i = 0; i < elements; i++)
    is >> v[i] >> comma;
        
  return is;
}
template<typename T >
Vector<T> QuadProgPP::operator^ ( const Vector< T > &  lhs,
const Vector< T > &  rhs 
) [inline]

Definition at line 428 of file Array.h.

References pow(), and QuadProgPP::Vector< T >::size().

{
  if (lhs.size() != rhs.size())
    throw std::logic_error("Operator^: vectors have different sizes");
  Vector<T> tmp(lhs.size());
  for (unsigned int i = 0; i < lhs.size(); i++)
    tmp[i] = pow(lhs[i], rhs[i]);
        
  return tmp;
}
template<typename T >
Vector<T> QuadProgPP::operator^ ( const Vector< T > &  lhs,
const T &  a 
) [inline]

Definition at line 440 of file Array.h.

References pow(), and QuadProgPP::Vector< T >::size().

{
  Vector<T> tmp(lhs.size());
  for (unsigned int i = 0; i < lhs.size(); i++)
    tmp[i] = pow(lhs[i], a);
                
  return tmp;
}
template<typename T >
Vector<T> QuadProgPP::operator^ ( const T &  a,
const Vector< T > &  rhs 
) [inline]

Definition at line 450 of file Array.h.

References pow(), and QuadProgPP::Vector< T >::size().

{
  Vector<T> tmp(rhs.size());
  for (unsigned int i = 0; i < rhs.size(); i++)
    tmp[i] = pow(a, rhs[i]);
                
  return tmp;
}
template<typename T >
Matrix<T> QuadProgPP::operator^ ( const Matrix< T > &  lhs,
const T &  a 
)

Definition at line 1553 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), QuadProgPP::Matrix< T >::nrows(), and pow().

{
  Matrix<T> tmp(lhs.nrows(), lhs.ncols());
  for (unsigned int i = 0; i < lhs.nrows(); i++)
    for (unsigned int j = 0; j < lhs.ncols(); j++)
      tmp[i][j] = pow(lhs[i][j], a);
        
  return tmp;
}
template<typename T >
unsigned int QuadProgPP::partition ( Vector< T > &  v,
unsigned int  begin,
unsigned int  end 
) [inline]

Definition at line 786 of file Array.h.

Referenced by quicksort().

{
  unsigned int i = begin + 1, j = begin + 1;
  T pivot = v[begin];
  while (j <= end) 
    {
      if (v[j] < pivot) {
        std::swap(v[i], v[j]);
        i++;
      }
      j++;
    }
  v[begin] = v[i - 1];
  v[i - 1] = pivot;
  return i - 2;
}
template<typename T >
Matrix<T> QuadProgPP::pinv ( const Matrix< T > &  A )

Definition at line 1918 of file Array.h.

References DIAG, dot_prod(), QuadProgPP::Matrix< T >::ncols(), QuadProgPP::Matrix< T >::nrows(), svd(), and t().

{
  Matrix<T> U, V, x, tmp(A.ncols(), A.nrows());
  Vector<T> W;
  CanonicalBaseVector<T> e(0, A.nrows());
  svd(A, U, W, V);
  for (unsigned int i = 0; i < A.nrows(); i++)
    {
      e.reset(i);
      tmp.setColumn(i, dot_prod(dot_prod(dot_prod(V, Matrix<double>(DIAG, 1.0 / W, 0.0, W.size(), W.size())), t(U)), e));
    }
                
  return tmp;
}
template<typename T >
Vector<T> QuadProgPP::pow ( const Vector< T > &  v,
double  a 
) [inline]
void QuadProgPP::print_matrix ( const char *  name,
const Matrix< double > &  A,
int  n = -1,
int  m = -1 
)

Definition at line 783 of file QuadProg.cpp.

References QuadProgPP::Matrix< T >::ncols(), QuadProgPP::Matrix< T >::nrows(), and t().

Referenced by add_constraint(), cholesky_decomposition(), and QuadProgPP::QuadProg::solve_quadprog().

{
  std::ostringstream s;
  std::string t;
  if (n == -1)
    n = A.nrows();
  if (m == -1)
    m = A.ncols();
        
  s << name << ": " << std::endl;
  for (int i = 0; i < n; i++)
  {
    s << " ";
    for (int j = 0; j < m; j++)
      s << A[i][j] << ", ";
    s << std::endl;
  }
  t = s.str();
  t = t.substr(0, t.size() - 3); // To remove the trailing space, comma and newline
        
  std::cout << t << std::endl;
}
template<typename T >
void QuadProgPP::print_vector ( const char *  name,
const Vector< T > &  v,
int  n = -1 
)

Definition at line 807 of file QuadProg.cpp.

References QuadProgPP::Vector< T >::size(), and t().

Referenced by add_constraint(), and QuadProgPP::QuadProg::solve_quadprog().

{
  std::ostringstream s;
  std::string t;
  if (n == -1)
    n = v.size();
        
  s << name << ": " << std::endl << " ";
  for (int i = 0; i < n; i++)
  {
    s << v[i] << ", ";
  }
  t = s.str();
  t = t.substr(0, t.size() - 2); // To remove the trailing space and comma
        
  std::cout << t << std::endl;
}
template<typename T >
T QuadProgPP::prod ( const Vector< T > &  v ) [inline]

Definition at line 616 of file Array.h.

References QuadProgPP::Vector< T >::size().

Referenced by lu_det().

{
  T tmp = (T)1;
  for (unsigned int i = 0; i < v.size(); i++)
    tmp *= v[i];
        
  return tmp;
}
template<typename T >
Vector<T> QuadProgPP::prod ( const Matrix< T > &  m )

Definition at line 2239 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), and QuadProgPP::Matrix< T >::nrows().

{
  Vector<T> tmp((T)1, m.ncols());
  for (unsigned int j = 0; j < m.ncols(); j++)
    for (unsigned int i = 0; i < m.nrows(); i++)
      tmp[j] *= m[i][j];
  return tmp;
}
template<typename T >
void QuadProgPP::quicksort ( Vector< T > &  v,
unsigned int  begin,
unsigned int  end 
) [inline]

Definition at line 805 of file Array.h.

References partition().

{
  if (end > begin)
    {
      unsigned int index = partition(v, begin, end);
      quicksort(v, begin, index);
      quicksort(v, index + 2, end);
    }
}
template<typename T >
Vector<T> QuadProgPP::r_max ( const Matrix< T > &  m )

Definition at line 2381 of file Array.h.

References max(), QuadProgPP::Matrix< T >::ncols(), and QuadProgPP::Matrix< T >::nrows().

{
  Vector<T> res(m.nrows());
  double value;
  for (unsigned int i = 0; i < m.nrows(); i++)
    {
      value = m[i][0];
      for (unsigned int j = 1; j < m.ncols(); j++)
        value = std::max(m[i][j], value);
      res[i] = value;
    }
        
  return res;
}
template<typename T >
Vector<T> QuadProgPP::r_mean ( const Matrix< T > &  m )

Definition at line 2283 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), and QuadProgPP::Matrix< T >::nrows().

{
  Vector<T> res((T)0, m.rows());
  for (unsigned int i = 0; i < m.nrows(); i++)
    {
      for (unsigned int j = 0; j < m.ncols(); j++)
        res[i] += m[i][j];
      res[i] /= m.nrows();
    }
        
  return res;
}
template<typename T >
Vector<T> QuadProgPP::r_min ( const Matrix< T > &  m )

Definition at line 2413 of file Array.h.

References min, QuadProgPP::Matrix< T >::ncols(), and QuadProgPP::Matrix< T >::nrows().

{
  Vector<T> res(m.nrows());
  double value;
  for (unsigned int i = 0; i < m.nrows(); i++)
    {
      value = m[i][0];
      for (unsigned int j = 1; j < m.ncols(); j++)
        value = std::min(m[i][j], value);
      res[i] = value;
    }
        
  return res;
}
template<typename T >
Vector<T> QuadProgPP::r_prod ( const Matrix< T > &  m )

Definition at line 2249 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), and QuadProgPP::Matrix< T >::nrows().

{
  Vector<T> tmp((T)1, m.nrows());
  for (unsigned int i = 0; i < m.nrows(); i++)
    for (unsigned int j = 0; j < m.ncols(); j++)
      tmp[i] *= m[i][j];
  return tmp;
}
template<typename T >
Matrix<double> QuadProgPP::r_rank ( const Matrix< T >  m ) [inline]

Definition at line 2544 of file Array.h.

References QuadProgPP::Matrix< T >::extractRow(), QuadProgPP::Matrix< T >::ncols(), QuadProgPP::Matrix< T >::nrows(), and QuadProgPP::Matrix< T >::setRow().

{
  Matrix<double> tmp(m.nrows(), m.ncols());
  for (unsigned int i = 0; i < m.nrows(); i++)
    tmp.setRow(i, rank<T>(m.extractRow(i)));
  
  return tmp;                  
}
template<typename T >
Vector<T> QuadProgPP::r_stdev ( const Matrix< T > &  m,
bool  sample_correction = false 
)

Definition at line 2359 of file Array.h.

References r_var(), and sqrt().

{
  return sqrt(r_var(m, sample_correction));
}
template<typename T >
Vector<T> QuadProgPP::r_sum ( const Matrix< T > &  m )

Definition at line 2219 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), and QuadProgPP::Matrix< T >::nrows().

{
  Vector<T> tmp((T)0, m.nrows());
  for (unsigned int i = 0; i < m.nrows(); i++)
    for (unsigned int j = 0; j < m.ncols(); j++)
      tmp[i] += m[i][j];
  return tmp;
}
template<typename T >
Vector<T> QuadProgPP::r_var ( const Matrix< T > &  m,
bool  sample_correction = false 
)

Definition at line 2336 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), QuadProgPP::Matrix< T >::nrows(), and sum().

Referenced by r_stdev().

{
  Vector<T> res((T)0, m.nrows());
  double sum, ssum;
  unsigned int n = m.ncols();
  for (unsigned int i = 0; i < m.nrows(); i++)
    {   
      sum = 0.0; ssum = 0.0;
      for (unsigned int j = 0; j < m.ncols(); j++)
        {
          sum += m[i][j];
          ssum += (m[i][j] * m[i][j]);
        }
      if (!sample_correction)
        res[i] = (ssum / n) - (sum / n) * (sum / n);
      else
        res[i] = n * ((ssum / n) - (sum / n) * (sum / n)) / (n - 1);
    }
        
  return res;
}
template<typename T >
void QuadProgPP::random ( Matrix< T > &  m )

Definition at line 2197 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), and QuadProgPP::Matrix< T >::nrows().

{
  for (unsigned int i = 0; i < m.nrows(); i++)
    for (unsigned int j = 0; j < m.ncols(); j++)
      m[i][j] = (T)(rand() / double(RAND_MAX));
}
template<typename T >
Vector<double> QuadProgPP::rank ( const Vector< T > &  v ) [inline]

Definition at line 826 of file Array.h.

References QuadProgPP::Vector< T >::size().

{
  Vector<T> tmp(v);
  Vector<double> tmp_rank(0.0, v.size());       
        
  for (unsigned int i = 0; i < tmp.size(); i++)
    {
      unsigned int smaller = 0, equal = 0;
      for (unsigned int j = 0; j < tmp.size(); j++)
        if (i == j)
          continue;
        else
          if (tmp[j] < tmp[i])
            smaller++;
          else if (tmp[j] == tmp[i])
            equal++;
      tmp_rank[i] = smaller + 1;
      if (equal > 0)
        {
          for (unsigned int j = 1; j <= equal; j++)
            tmp_rank[i] += smaller + 1 + j;
          tmp_rank[i] /= (double)(equal + 1);
        }
    }
        
  return tmp_rank;
}
template<typename T >
Matrix<double> QuadProgPP::rank ( const Matrix< T >  m ) [inline]

Definition at line 2534 of file Array.h.

References QuadProgPP::Matrix< T >::extractColumn(), QuadProgPP::Matrix< T >::ncols(), QuadProgPP::Matrix< T >::nrows(), and QuadProgPP::Matrix< T >::setColumn().

{
  Matrix<double> tmp(m.nrows(), m.ncols());
  for (unsigned int j = 0; j < m.ncols(); j++)
    tmp.setColumn(j, rank<T>(m.extractColumn(j)));
  
  return tmp;                  
}
double QuadProgPP::scalar_product ( const Vector< double > &  x,
const Vector< double > &  y 
) [inline]

Definition at line 700 of file QuadProg.cpp.

References QuadProgPP::Vector< T >::size(), and sum().

Referenced by QuadProgPP::QuadProg::solve_quadprog().

{
  register int i, n = x.size();
  register double sum;
        
  sum = 0.0;
  for (i = 0; i < n; i++)
    sum += x[i] * y[i];
  return sum;                   
}
std::set< unsigned int > QuadProgPP::seq ( unsigned int  s,
unsigned int  e 
)

Index utilities

Definition at line 23 of file Array.cpp.

                    {

std::set<unsigned int> seq(unsigned int s, unsigned int e)
{
        std::set<unsigned int> tmp;
        for (unsigned int i = s; i <= e; i++)
template<typename T >
Vector<T> QuadProgPP::sign ( const Vector< T > &  v ) [inline]

Definition at line 776 of file Array.h.

References QuadProgPP::Vector< T >::size().

Referenced by svd().

{
  Vector<T> tmp(v.size());
  for (unsigned int i = 0; i < v.size(); i++)
    tmp[i] = v[i] > 0 ? +1 : v[i] == 0 ? 0 : -1;
        
  return tmp;
}
template<typename T >
T QuadProgPP::sign ( const T &  v )

Definition at line 1655 of file Array.h.

{
  if (v >= (T)0.0)
    return (T)1.0;
  else
    return (T)-1.0;
}
std::set< unsigned int > QuadProgPP::singleton ( unsigned int  i )

Definition at line 32 of file Array.cpp.

{
        std::set<unsigned int> tmp;
template<typename T >
Vector<T> QuadProgPP::sort ( const Vector< T > &  v ) [inline]
template<typename T >
Vector<T> QuadProgPP::sqrt ( const Vector< T > &  v ) [inline]

Definition at line 746 of file Array.h.

References QuadProgPP::Vector< T >::size().

Referenced by QwtSpline::buildPeriodicSpline(), mitk::CylindricToCartesianFilter::buildTransformShortCuts(), mitk::SlicedGeometry3D::CalculateSpacing(), mitk::ImageMapperGL2D::CalculateSpacing(), mitk::SurfaceInteractor::CanHandleEvent(), itk::AnalyticalDiffusionQballReconstructionImageFilter< TReferenceImagePixelType, TGradientImagePixelType, TOdfPixelType, NOrderL, NrOdfDirections >::Cart2Sph(), QmitkPointBasedRegistrationView::checkLandmarkError(), cholesky(), cholesky_decomposition(), QwtPlotCurve::closestPoint(), itk::OrientationDistributionFunction< TComponent, NOdfDirections >::ComputeBaseMesh(), itk::DiffusionQballReconstructionImageFilter< TReferenceImagePixelType, TGradientImagePixelType, TOdfPixelType, NrOdfDirections, NrBasisFunctionCenters >::ComputeReconstructionMatrix(), MeshUtil< MeshType, ScalarAccessor >::CreateRegularSphereMesh2(), QmitkDiffusionDicomImport::DicomLoadStartLoad(), dist(), distance(), itk::PointShell< NPoints, TMatrixType >::DistributePointShell(), QwtRoundScaleDraw::extent(), mitk::Geometry3D::GetDiagonalLength(), itk::OrientationDistributionFunction< TComponent, NOdfDirections >::GetGeneralizedFractionalAnisotropy(), itk::OrientationDistributionFunction< TComponent, NOdfDirections >::GetGeneralizedGFA(), itk::OrientationDistributionFunction< TComponent, NOdfDirections >::GetInterpolatedComponent(), itk::OrientationDistributionFunction< TComponent, NOdfDirections >::GetMaxChordLength(), mitk::ClaronInterface::GetQuaternions(), itk::OrientationDistributionFunction< TComponent, NOdfDirections >::GetStdDevByMaxValue(), mitk::ClaronInterface::GetTipQuaternions(), ipMITKSegmentationGetCutPoints(), ipMITKSegmentationGetDistGradient(), mitk::Cone::IsInside(), mitk::CalculateGrayValueStatisticsTool::ITKHistogramming(), mitk::OdfVtkMapper2D< TPixelType, NrOdfDirections >::MeasureDisplayedGeometry(), mitkNavigationDataLandmarkTransformFilterTest(), mitk::SpaceNavigatorVtkCameraController::OnSpaceNavigatorEvent(), mitk::TDMouseVtkCameraController::OnTDMouseEvent(), mitk::SurfaceGLMapper2D::PaintCells(), r_stdev(), RGBtoHSI(), vtkThickPlane::SetNormal(), itk::AnalyticalDiffusionQballReconstructionImageFilter< TReferenceImagePixelType, TGradientImagePixelType, TOdfPixelType, NOrderL, NrOdfDirections >::spherical_harmonic(), sqrt(), ANNsampStat::stdDev(), stdev(), svd(), mitkPlanarCrossTestClass::TestPlanarCrossPlacement(), mitkPlanarCrossTestClass::TestPlanarCrossPlacementSingleLine(), itk::LocalVariationImageFilter< TInputImage, TOutputImage >::ThreadedGenerateData(), itk::AnalyticalDiffusionQballReconstructionImageFilter< TReferenceImagePixelType, TGradientImagePixelType, TOdfPixelType, NOrderL, NrOdfDirections >::ThreadedGenerateData(), mitk::CorrectorAlgorithm::TobiasHeimannCorrectionAlgorithm(), mitk::SiemensMosaicDicomDiffusionImageHeaderReader::Update(), and itk::AnalyticalDiffusionQballReconstructionImageFilter< TReferenceImagePixelType, TGradientImagePixelType, TOdfPixelType, NOrderL, NrOdfDirections >::Yj().

{
  Vector<T> tmp(v.size());
  for (unsigned int i = 0; i < v.size(); i++)
    tmp[i] = sqrt(v[i]);
        
  return tmp;
}
template<typename T >
Matrix<T> QuadProgPP::sqrt ( const Matrix< T > &  m )

Definition at line 2447 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), QuadProgPP::Matrix< T >::nrows(), and sqrt().

{
  Matrix<T> tmp(m.nrows(), m.ncols());
        
  for (unsigned int i = 0; i < m.nrows(); i++)
    for (unsigned int j = 0; j < m.ncols(); j++)
      tmp[i][j] = sqrt(m[i][j]);
        
  return tmp;
}
template<typename T >
T QuadProgPP::stdev ( const Vector< T > &  v,
bool  sample_correction = false 
) [inline]

Definition at line 645 of file Array.h.

References sqrt(), and var().

{
  return sqrt(var(v, sample_correction));
}
template<typename T >
Vector<T> QuadProgPP::stdev ( const Matrix< T > &  m,
bool  sample_correction = false 
)

Definition at line 2330 of file Array.h.

References sqrt(), and var().

{
  return sqrt(var(m, sample_correction));
}
template<typename T >
Vector<T> QuadProgPP::sum ( const Matrix< T > &  m )

Aggregate functions

Definition at line 2209 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), and QuadProgPP::Matrix< T >::nrows().

{
  Vector<T> tmp((T)0, m.ncols());
  for (unsigned int j = 0; j < m.ncols(); j++)
    for (unsigned int i = 0; i < m.nrows(); i++)
      tmp[j] += m[i][j];
  return tmp;
}
template<typename T >
T QuadProgPP::sum ( const Vector< T > &  v ) [inline]
template<typename T >
void QuadProgPP::svd ( const Matrix< T > &  A,
Matrix< T > &  U,
Vector< T > &  W,
Matrix< T > &  V 
)

Definition at line 1674 of file Array.h.

References dist(), max(), min, QuadProgPP::Matrix< T >::ncols(), QuadProgPP::Matrix< T >::nrows(), QuadProgPP::Matrix< T >::resize(), QuadProgPP::Vector< T >::resize(), sign(), and sqrt().

Referenced by pinv(), and mitk::PlaneFit::ProcessPointSet().

{
  int m = A.nrows(), n = A.ncols(), i, j, k, l, jj, nm;
  const unsigned int max_its = 30;
  bool flag;
  Vector<T> rv1(n);
  U = A;
  W.resize(n);
  V.resize(n, n);
  T anorm, c, f, g, h, s, scale, x, y, z;
  g = scale = anorm = (T)0.0;
        
  // Householder reduction to bidiagonal form
  for (i = 0; i < n; i++)
    {
      l = i + 1;
      rv1[i] = scale * g;
      g = s = scale = (T)0.0;
      if (i < m)
        {
          for (k = i; k < m; k++)
            scale += fabs(U[k][i]);
          if (scale != (T)0.0)
            {
              for (k = i; k < m; k++)
                {
                  U[k][i] /= scale;
                  s += U[k][i] * U[k][i];
                }
              f = U[i][i];
              g = -sign(f) * sqrt(s);
              h = f * g - s;
              U[i][i] = f - g;
              for (j = l; j < n; j++)
                {
                  s = (T)0.0;
                  for (k = i; k < m; k++)
                    s += U[k][i] * U[k][j];
                  f = s / h;
                  for (k = i; k < m; k++)
                    U[k][j] += f * U[k][i];
                }
              for (k = i; k < m; k++)
                U[k][i] *= scale;
            }
        }
      W[i] = scale * g;
      g = s = scale = (T)0.0;
      if (i < m && i != n - 1)
        {
          for (k = l; k < n; k++)
            scale += fabs(U[i][k]);
          if (scale != (T)0.0)
            {
              for (k = l; k < n; k++)
                {
                  U[i][k] /= scale;
                  s += U[i][k] * U[i][k];                                       
                }
              f = U[i][l];
              g = -sign(f) * sqrt(s);
              h = f * g - s;
              U[i][l] = f - g;
              for (k = l; k <n; k++)
                rv1[k] = U[i][k] / h;
              for (j = l; j < m; j++)
                {
                  s = (T)0.0;
                  for (k = l; k < n; k++)
                    s += U[j][k] * U[i][k];
                  for (k = l; k < n; k++)
                    U[j][k] += s * rv1[k];
                }
              for (k = l; k < n; k++)
                U[i][k] *= scale;
            }
        }
      anorm = std::max(anorm, fabs(W[i]) + fabs(rv1[i]));
    }
  // Accumulation of right-hand transformations
  for (i = n - 1; i >= 0; i--)
    {
      if (i < n - 1) 
        {
          if (g != (T)0.0)
            {
              for (j = l; j < n; j++)
                V[j][i] = (U[i][j] / U[i][l]) / g;
              for (j = l; j < n; j++)
                {
                  s = (T)0.0;
                  for (k = l; k < n; k++)
                    s += U[i][k] * V[k][j];
                  for (k = l; k < n; k++)
                    V[k][j] += s * V[k][i];
                }
            }
          for (j = l; j < n; j++)
            V[i][j] = V[j][i] = (T)0.0;
        }
      V[i][i] = (T)1.0;
      g = rv1[i];
      l = i;
    }
  // Accumulation of left-hand transformations
  for (i = std::min(m, n) - 1; i >= 0; i--)
    {
      l = i + 1;
      g = W[i];
      for (j = l; j < n; j++)
        U[i][j] = (T)0.0;
      if (g != (T)0.0)
        {
          g = (T)1.0 / g;
          for (j = l; j < n; j++)
            {
              s = (T)0.0;
              for (k = l; k < m; k++)
                s += U[k][i] * U[k][j];
              f = (s / U[i][i]) * g;
              for (k = i; k < m; k++)
                U[k][j] += f * U[k][i];
            }
          for (j = i; j < m; j++)
            U[j][i] *= g;
        }
      else
        for (j = i; j < m; j++)
          U[j][i] = (T)0.0;
      U[i][i]++;
    }
  // Diagonalization of the bidiagonal form: loop over singular values, and over allowed iterations.
  for (k = n - 1; k >= 0; k--)
    {
      for (unsigned int its = 0; its < max_its; its++)
        {
          flag = true;
          for (l = k; l >= 0; l--) // FIXME: in NR it was l >= 1 but there subscripts start from one
            { // Test for splitting
              nm = l - 1; // Note that rV[0] is always zero
              if ((T)(fabs(rv1[l]) + anorm) == anorm)
                {
                  flag = false;
                  break;
                }
              if ((T)(fabs(W[nm]) + anorm) == anorm)
                break;
            }
          if (flag)
            {
              // Cancellation of rv1[l], if l > 0 FIXME: it was l > 1 in NR
              c = (T)0.0;
              s = (T)1.0;
              for (i = l; i <= k; i++)
                {
                  f = s * rv1[i];
                  rv1[i] *= c;
                  if ((T)(fabs(f) + anorm) == anorm)
                    break;
                  g = W[i];
                  h = dist(f, g);
                  W[i] = h;
                  h = (T)1.0 / h;
                  c = g * h;
                  s = -f * h;
                  for (j = 0; j < m; j++)
                    {
                      y = U[j][nm];
                      z = U[j][i];
                      U[j][nm] = y * c + z * s;
                      U[j][i] = z * c - y * s;
                    }
                }
            }
          z = W[k];
          if (l == k)
            {  // Convergence
              if (z < (T)0.0)
                { // Singular value is made nonnegative
                  W[k] = -z;
                  for (j = 0; j < n; j++)
                    V[j][k] = -V[j][k];
                }
              break;
            }
          if (its == max_its)
            throw std::logic_error("Error svd: no convergence in the maximum number of iterations");
          x = W[l];
          nm = k - 1;
          y = W[nm];
          g = rv1[nm];
          h = rv1[k];
          f = ((y - z) * (y + z) + (g - h) * (g + h)) / (2.0 * h * y);
          g = dist(f, (T)1.0);
          f = ((x - z) * (x + z) + h * ((y / (f + sign(f)*fabs(g))) - h)) / x;
          c = s = (T)1.0; // Next QR transformation
          for (j = l; j <= nm; j++)
            {
              i = j + 1;
              g = rv1[i];
              y = W[i];
              h = s * g;
              g *= c;
              z = dist(f, h);
              rv1[j] = z;
              c = f / z;
              s = h / z;
              f = x * c + g * s;
              g = g * c - x * s;
              h = y * s;
              y *= c;
              for (jj = 0; jj < n; jj++)
                {
                  x = V[jj][j];
                  z = V[jj][i];
                  V[jj][j] = x * c + z * s;
                  V[jj][i] = z * c - x * s;
                }
              z = dist(f, h);
              W[j] = z; 
              if (z != 0) // Rotation can be arbitrary if z = 0
                {
                  z = (T)1.0 / z;
                  c = f * z;
                  s = h * z;
                }
              f = c * g + s * y;
              x = c * y - s * g;
              for (jj = 0; jj < m; jj++)
                {
                  y = U[jj][j];
                  z = U[jj][i];
                  U[jj][j] = y * c + z * s;
                  U[jj][i] = z * c - y * s;
                }
            }
          rv1[l] = (T)0.0;
          rv1[k] = f;
          W[k] = x;
        }
    }   
}
template<typename T >
Matrix<T> QuadProgPP::t ( const Matrix< T > &  a )

Definition at line 2474 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), and QuadProgPP::Matrix< T >::nrows().

Referenced by mitk::VirtualTrackingDevice::AddTool(), mitk::NDITrackingDevice::AddTool(), mitk::ClaronTrackingDevice::AddTool(), ANNkd_leaf::ann_FR_search(), ANNkd_leaf::ann_pri_search(), ANNkd_leaf::ann_search(), annBoxDistance(), mitk::PolygonToRingFilter::BuildPointAndVectorList(), mitk::InterpolateLinesFilter::BuildPointAndVectorList(), mitk::PlaneFit::CalculateCentroid(), mitk::SurfaceDeformationInteractor3D::ColorizeSurface(), itk::NonUniformBSpline< TDimension >::ComputeControlPoints(), mitk::SimpleHistogram::ComputeFromImage(), mitk::Image::ComputeImageStatistics(), vtkMitkVolumeTextureMapper3D::ComputePolygons(), mitk::VolumeCalculator::ComputeVolumeFromImageStatistics(), vtkPointSetSlicer::ContourUnstructuredGridCell(), mitk::TimeSlicedGeometry::CopyTimes(), QmitkControlVisualizationPropertiesView::CreateQtPartControl(), mitkPointSetFileIOTestClass::CreateTestPointSet(), cutPoint(), distance(), mitk::MessageDelegate4< R, T, U, V, W, A >::Execute(), mitk::MessageDelegate3< R, T, U, V, A >::Execute(), mitk::MessageDelegate2< R, T, U, A >::Execute(), mitk::MessageDelegate1< R, T, A >::Execute(), mitk::SurfaceDeformationInteractor3D::ExecuteAction(), mitk::NDITrackingDevice::FreePortHandles(), mitk::UnstructuredGridVtkWriter< VTKWRITER >::GenerateData(), mitk::TrackingDeviceSource::GenerateData(), mitk::SurfaceVtkWriter< VTKWRITER >::GenerateData(), mitk::SurfaceToImageFilter::GenerateData(), mitk::RGBToRGBACastImageFilter::GenerateData(), mitk::ProbeFilter::GenerateData(), mitk::PolygonToRingFilter::GenerateData(), mitk::PlaneFit::GenerateData(), mitk::PicVolumeTimeSeriesReader::GenerateData(), mitk::ParRecFileReader::GenerateData(), mitk::MaskImageFilter::GenerateData(), mitk::ManualSegmentationToSurfaceFilter::GenerateData(), mitk::LabeledImageToSurfaceFilter::GenerateData(), mitk::ImageWriter::GenerateData(), mitk::ImageToSurfaceFilter::GenerateData(), mitk::GeometryClipImageFilter::GenerateData(), mitk::DopplerToStrainRateFilter::GenerateData(), mitk::CylindricToCartesianFilter::GenerateData(), mitk::AngleCorrectByPointFilter::GenerateData(), mitk::PlanarAngle::GenerateHelperPolyLine(), mitk::PlaneFit::GenerateOutputInformation(), mitk::PlanarCircle::GeneratePolyLine(), mitk::Mesh::GetBoundingBoxFromCell(), mitk::PlaneFit::GetCentroid(), mitk::Image::GetChannelData(), mitk::Image::GetCountOfMaxValuedVoxels(), mitk::Image::GetCountOfMaxValuedVoxelsNoRecompute(), mitk::Image::GetCountOfMinValuedVoxels(), mitk::Image::GetCountOfMinValuedVoxelsNoRecompute(), mitk::BaseData::GetGeometry(), mitk::TimeSlicedGeometry::GetGeometry3D(), mitk::Mesh::GetMesh(), mitk::MicroBirdTrackingDevice::GetMicroBirdTool(), mitk::Mesh::GetNewCellId(), mitk::Mesh::GetNumberOfCells(), mitk::PointSet::GetNumberOfSelected(), mitk::PlaneFit::GetPlaneGeometry(), mitk::PlaneFit::GetPlaneNormal(), mitk::PointSet::GetPoint(), mitk::Line< TCoordRep, NPointDimension >::GetPoint(), mitk::NonBlockingAlgorithm::GetPointerParameter(), mitk::Mesh::GetPointIds(), mitk::PointSet::GetPointSet(), mitk::Image::GetScalarValue2ndMax(), mitk::Image::GetScalarValue2ndMaxNoRecompute(), mitk::Image::GetScalarValue2ndMin(), mitk::Image::GetScalarValue2ndMinNoRecompute(), mitk::Image::GetScalarValueMax(), mitk::Image::GetScalarValueMaxNoRecompute(), mitk::Image::GetScalarValueMin(), mitk::Image::GetScalarValueMinNoRecompute(), mitk::PointSet::GetSelectInfo(), mitk::PointSet::GetSize(), mitk::PointSet::GetSpecificationTypeInfo(), mitk::VirtualTrackingDevice::GetSplineChordLength(), QmitkNDIConfigurationWidget::GetToolNamesList(), mitk::UIDGenerator::GetUID(), mitk::Surface::GetVtkPolyData(), mitk::UnstructuredGrid::GetVtkUnstructuredGrid(), mitk::ColorConversions::Hsv2Rgb(), mitk::PointSet::IndexExists(), mitk::TimeSlicedGeometry::InitializeGeometry(), mitk::PlaneFit::InitializePlane(), mitk::PointSet::InsertPoint(), mitk::Image::IsChannelSet(), mitk::BaseData::IsEmpty(), MeshUtil< MeshType, ScalarAccessor >::MeshFromPolyData(), mitk::TimeSlicedGeometry::MSToTimeStep(), itk::NonUniformBSpline< TDimension >::NonUniformBSplineFunctionRecursive(), QmitkIGTExampleView::OnTestTracking(), QmitkTbssView::OutputUnconnectedPointValues(), mitk::MeshMapper2D::Paint(), mitk::Geometry2DDataMapper2D::Paint(), pinv(), mitkPointSetFileIOTestClass::PointSetCompare(), mitk::NDIProtocol::POS3D(), itk::OrientationDistributionFunction< TComponent, NOdfDirections >::PostMultiply(), itk::OrientationDistributionFunction< TComponent, NOdfDirections >::PreMultiply(), print_matrix(), print_vector(), mitk::PlaneFit::ProcessPointSet(), mitk::Line< TCoordRep, NPointDimension >::RectangleLineIntersection(), mitk::UnstructuredGrid::RequestedRegionIsOutsideOfTheBufferedRegion(), mitk::Surface::RequestedRegionIsOutsideOfTheBufferedRegion(), mitk::SlicedData::RequestedRegionIsOutsideOfTheBufferedRegion(), mitk::Mesh::SearchFirstCell(), mitk::Mesh::SearchLine(), mitk::PointSet::SearchPoint(), mitk::Mesh::SearchSelectedCell(), mitk::PointSet::SearchSelectedPoint(), mitk::TimeSlicedGeometry::SetGeometry3D(), mitk::TimeSlicedGeometry::SetImageGeometry(), mitk::ImageStatisticsCalculator::SetImageMask(), mitk::PlaneFit::SetInput(), mitk::ImageStatisticsCalculator::SetMaskingModeToImage(), mitk::Mesh::SetMesh(), mitk::PointSet::SetPoint(), QmitkPointListViewWidget::SetTimeStep(), QmitkPointListModel::SetTimeStep(), QwtScaleWidget::setTitle(), mitk::VirtualTrackingDevice::SetToolSpeed(), QwtAbstractSlider::setUpdateTime(), mitk::Surface::SetVtkPolyData(), mitk::UnstructuredGrid::SetVtkUnstructuredGrid(), QuadProgPP::QuadProg::solve_quadprog(), mitk::VirtualTrackingDevice::TrackTools(), mitk::TimeSlicedGeometry::UpdateInformation(), QmitkVtkLineProfileWidget::UpdateItemModelFromPath(), mitk::SplineVtkMapper3D::UpdateSpline(), QmitkNDIConfigurationWidget::UpdateToolTable(), and ScalarGradientCompute< T >::write().

{
  Matrix<T> tmp(a.ncols(), a.nrows());
  for (unsigned int i = 0; i < a.nrows(); i++)
    for (unsigned int j = 0; j < a.ncols(); j++)
      tmp[j][i] = a[i][j];
        
  return tmp;
}
void QuadProgPP::update_r ( const Matrix< double > &  R,
Vector< double > &  r,
const Vector< double > &  d,
int  iq 
) [inline]

Definition at line 517 of file QuadProg.cpp.

References sum().

Referenced by QuadProgPP::QuadProg::solve_quadprog().

{
  register int i, j;/*, n = d.size();*/
  register double sum;
  
  /* setting of r = R^-1 d */
  for (i = iq - 1; i >= 0; i--)
  {
    sum = 0.0;
    for (j = i + 1; j < iq; j++)
      sum += R[i][j] * r[j];
    r[i] = (d[i] - sum) / R[i][i];
  }
}
void QuadProgPP::update_z ( Vector< double > &  z,
const Matrix< double > &  J,
const Vector< double > &  d,
int  iq 
) [inline]

Definition at line 504 of file QuadProg.cpp.

References QuadProgPP::Vector< T >::size().

Referenced by QuadProgPP::QuadProg::solve_quadprog().

{
  register int i, j, n = z.size();
        
  /* setting of z = H * d */
  for (i = 0; i < n; i++)
  {
    z[i] = 0.0;
    for (j = iq; j < n; j++)
      z[i] += J[i][j] * d[j];
  }
}
template<typename T >
T QuadProgPP::var ( const Vector< T > &  v,
bool  sample_correction = false 
) [inline]

Definition at line 651 of file Array.h.

References QuadProgPP::Vector< T >::size(), and sum().

Referenced by stdev().

{
  T sum = (T)0, ssum = (T)0;
  unsigned int n = v.size();
  for (unsigned int i = 0; i < n; i++)
    {   
      sum += v[i];
      ssum += (v[i] * v[i]);
    }
  if (!sample_correction)
    return (ssum / n) - (sum / n) * (sum / n);
  else
    return n * ((ssum / n) - (sum / n) * (sum / n)) / (n - 1);
}
template<typename T >
Vector<T> QuadProgPP::var ( const Matrix< T > &  m,
bool  sample_correction = false 
)

Definition at line 2307 of file Array.h.

References QuadProgPP::Matrix< T >::ncols(), QuadProgPP::Matrix< T >::nrows(), and sum().

{
  Vector<T> res((T)0, m.ncols());
  unsigned int n = m.nrows();
  double sum, ssum;
  for (unsigned int j = 0; j < m.ncols(); j++)
    {   
      sum = (T)0.0; ssum = (T)0.0;
      for (unsigned int i = 0; i < m.nrows(); i++)
        {
          sum += m[i][j];
          ssum += (m[i][j] * m[i][j]);
        }
      if (!sample_correction)
        res[j] = (ssum / n) - (sum / n) * (sum / n);
      else
        res[j] = n * ((ssum / n) - (sum / n) * (sum / n)) / (n - 1);             
    }
        
  return res;
}
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines