54template<
class Array>
class Svd;
147 template<
class OtherArray>
228 if (!computeSvd())
return false;
248 norm_ = bidiag(U_, D_, F_);
251 if (withV_) { compV();}
253 if (nrowU() < ncolV())
254 { rightEliminate(D_, F_, nrowU(), V_, withV_, norm_);}
256 if (withU_) { compU();}
258 bool error = diag(D_, F_, U_, V_, withU_, withV_, norm_);
278 int last_iter = M.beginCols() + std::min(M.sizeCols(), M.sizeRows()) -1;
303 if ((iter <
last_iter)||(M.sizeCols()>M.sizeRows()))
315 norm = std::max(std::abs(D[iter])+std::abs(
F[iter]),
norm);
327 V_.resize(U_.cols());
329 int niter = (ncolV()>nrowU()) ? (nrowU()) : (ncolV()-1);
331 for (
int iter=
niter+2; iter<=ncolV(); iter++)
364 for (
int i=
iter2;
i <= ncolV(); ++
i)
379 V_(
Range(2,ncolV(), 0),1) =0.0;
380 V_(1,
Range(2,ncolV(), 0)) =0.0;
388 int niter = D_.size();
389 int ncol = std::min(nrowU(), ncolU());
406 P[iter] = 1.0 + beta;
415 for (
int i=
iter1;
i <= nrowU(); ++
i)
429 U_.col(
Range(1,iter-1, 0), iter) = 0.0;
460 if (std::abs(
z)+
tol ==
tol)
break;
483 for (
int k=
nrow+1; k <D.end(); k++)
494 if (std::abs(
z)+
tol ==
tol)
break;
515 for (
int end=D.lastIdx(); end>=D.begin(); --end)
518 for (iter=1; iter<=
MAX_ITER; iter++)
522 if (std::abs(
F[end-1])+
tol ==
tol) {
F[end-1] = 0.0;
break;}
526 if (std::abs(D[end])+
tol ==
tol)
529 rightEliminate(D,
F, end-1, V,
withV,
tol);
626 if (iter >= 30) {
error =
true;}
636 { V(
i,end) = -V(
i,end);}
642 for (
int i=end+1;
i<=D.lastIdx();
i++)
In this file, we define Array2DDiagonal class.
In this file, we define Array2DSquare class.
A Array2DVector is a one dimensional horizontal container.
In this file we implement the functors for performing operations on Array2D arrays.
In this file we define Givens methods used by the Algebra classes.
In this file we define the Housholder methods used by the Algebra classes.
In this file we define the interface class ISvd.
void swap(int i, int j)
swap two elements: only for vectors and points
Derived & resize(Range const &I, Range const &J)
resize the array.
void swapCols(int pos1, int pos2)
Swapping two columns.
String const & error() const
get the last error message.
Compute the Singular Value Decomposition of an array.
ArrayD D_
Diagonal array of the singular values.
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
The class Svd compute the Singular Value Decomposition of a Array with the Golub-Reinsch Algorithm.
ISvd< Svd< Array > > Base
Svd(Array const &A, bool ref=false, bool withU=true, bool withV=true)
Default constructor.
hidden::Traits< Array >::Col ColVector
static bool diag(ArrayDiagonalX &D, VectorX &F, Array &U, ArraySquareX &V, bool withU=true, bool withV=true, Real const &tol=Arithmetic< Real >::epsilon())
Computing the diagonalization of a bi-diagonal matrix.
hidden::Traits< Array >::Row RowVector
bool computeSvd()
Svd main steps.
void compV()
Compute V (if withV_ is true)
void compU()
Compute U (if withU_ is true)
VectorX F_
Values of the Sub-diagonal.
Svd(ArrayBase< OtherArray > const &A, bool withU=true, bool withV=true)
constructor with other kind of array/expression
bool runImpl()
run the Svd
Svd & operator=(const Svd &S)
Operator = : overwrite the Svd with S.
virtual ~Svd()
destructor.
static void rightEliminate(ArrayDiagonalX &D, VectorX &F, int const &nrow, ArraySquareX &V, bool withV=true, Real const &tol=Arithmetic< Real >::epsilon())
right eliminate the element on the subdiagonal of the row nrow
Index sub-vector region: Specialization when the size is unknown.
void rightGivens(ArrayBase< TContainer2D > &M, int j1, int j2, typename TContainer2D::Type const &cosinus, typename TContainer2D::Type const &sinus)
Apply Givens rotation.
void applyLeftHouseholderVector(ArrayBase< Lhs > const &M, ExprBase< Rhs > const &v)
left multiplication by a Householder vector.
void applyRightHouseholderVector(ArrayBase< Lhs > const &M, ExprBase< Rhs > const &v)
right multiplication by a Householder vector.
Real house(ArrayBase< Vector > &x)
Compute the Householder vector v of a vector x.
Real dot(ExprBase< Container1D1 > const &x, ExprBase< Container1D2 > const &y)
Compute the dot product.
Type sign(Type const &x, Type const &y=Type(1))
template sign value sign(x) * y: Type should be an integral type
Real norm(Real const &x, Real const &y)
Computation of sqrt(x^2 + y^2) without underflow or overflow.
double Real
STK fundamental type of Real values.
The namespace STK is the main domain space of the Statistical ToolKit project.
TRange< UnknownSize > Range
Arithmetic properties of STK fundamental types.
traits class for the algebra methods.