PTEMS  0.1.0-dev+git.81fd0e4
PolyTopic Element Method Solver
ptems::ConstrainedLeastSquares< T > Class Template Reference

Class for solving a constrained least squares problem. More...

#include <ptems/linearalgebra.hpp>

Public Member Functions

 ConstrainedLeastSquares (std::size_t rows, std::size_t cols, std::size_t constraints)
 Create the constrained least squares problem: find \(x\in T^n\) which minimises. More...
 
std::size_t ColumnCount () const
 Gets the size of the linear system. More...
 
std::size_t RowCount () const
 Gets the size of the linear system. More...
 
std::size_t ConstraintCount () const
 Gets the size of the linear system. More...
 
T & operator() (std::size_t i, std::size_t j)
 Gets mutable reference to the specified entry of the matrix \(A\). More...
 
T & Constraint (std::size_t i, std::size_t j)
 Gets mutable reference to the specified entry of the constraint matrix \(C\). More...
 
std::vector< T > & Solve (std::vector< T > &rhs, const std::vector< T > &constraintRHS)
 Solves the constrained least squares problem. More...
 

Detailed Description

template<typename T>
class ptems::ConstrainedLeastSquares< T >

Class for solving a constrained least squares problem.

The constrained least squares problem is to find \(x\in T^n\) which minimises

\[\Vert Ax - b \Vert^2\]

subject to the constraints

\[Cx = d\]

where \(A\in T^{m\times n}\), \(C\in T^{p\times n}\), \(x\in T^m\) and \(d\in T^p\).

Template Parameters
TThe type of the entries of the least squares system

Constructor & Destructor Documentation

◆ ConstrainedLeastSquares()

template<typename T >
ptems::ConstrainedLeastSquares< T >::ConstrainedLeastSquares ( std::size_t  rows,
std::size_t  cols,
std::size_t  constraints 
)
inline

Create the constrained least squares problem: find \(x\in T^n\) which minimises.

\[\Vert Ax - b \Vert^2\]

subject to the constraints

\[Cx = d\]

where \(A\in T^{m\times n}\), \(C\in T^{p\times n}\), \(x\in T^m\) and \(d\in T^p\).

Parameters
rowsNumber of rows ( \(m\)) in the matrix
colsNumber of columns ( \(n\)) in the matrix
constraintsNumber of constraints ( \(p\))

Member Function Documentation

◆ ColumnCount()

template<typename T >
std::size_t ptems::ConstrainedLeastSquares< T >::ColumnCount ( ) const
inline

Gets the size of the linear system.

◆ Constraint()

template<typename T >
T& ptems::ConstrainedLeastSquares< T >::Constraint ( std::size_t  i,
std::size_t  j 
)
inline

Gets mutable reference to the specified entry of the constraint matrix \(C\).

Note
This method can only be called before Solve() is called
Exceptions
std::out_of_rangeIf the row or column index is greater or equal to the number or constraints or columns, respectively
std::logic_errorIf Solve() has been called already
Parameters
iThe row index of the entry to get
jThe column index of the entry to get
Returns
Mutable reference to the constraint matrix entry

◆ ConstraintCount()

template<typename T >
std::size_t ptems::ConstrainedLeastSquares< T >::ConstraintCount ( ) const
inline

Gets the size of the linear system.

◆ operator()()

template<typename T >
T& ptems::ConstrainedLeastSquares< T >::operator() ( std::size_t  i,
std::size_t  j 
)
inline

Gets mutable reference to the specified entry of the matrix \(A\).

Note
This method can only be called before Solve() is called
Exceptions
std::out_of_rangeIf the row or column index is greater or equal to the number or rows or columns, respectively
std::logic_errorIf Solve() has been called already
Parameters
iThe row index of the entry to get
jThe column index of the entry to get
Returns
Mutable reference to the matrix entry

◆ RowCount()

template<typename T >
std::size_t ptems::ConstrainedLeastSquares< T >::RowCount ( ) const
inline

Gets the size of the linear system.

◆ Solve()

template<typename T >
std::vector<T>& ptems::ConstrainedLeastSquares< T >::Solve ( std::vector< T > &  rhs,
const std::vector< T > &  constraintRHS 
)
inline

Solves the constrained least squares problem.

Exceptions
std::invalid_argumentIf rhs.size() != number of columns, or constraintRHS.size() != number of constraints
Warning
LU factorisation is performed the first time Solve() is called, and the result is cached, overriding the original matrix. As such, the matrix entries cannot be changed after calling Solve().
Parameters
rhsThe mutable vector containing \(b\) which is updated with \(x\) on return
constraintRHSThe right hand side vector \(d\) for the constraints
Returns
Reference to rhs

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