48 template<
typename dtype>
63 m_{ inMatrix.
shape().rows },
64 n_{ inMatrix.
shape().cols },
115 for (
auto i = 0
u; i < std::min(m_, n_); ++i)
119 sInverse(i, i) = 1. / s_[i];
123 pinv_ =
dot(v_,
dot(sInverse, u_.transpose()));
139 if (inInput.
size() != m_)
165 const auto AtA =
dot(At, A);
166 const auto AAt =
dot(A, At);
168 const auto& [sigmaSquaredU, U] =
eig(AAt);
169 const auto& [sigmaSquaredV, V] =
eig(AtA);
172 for (
auto i = 0
u; i < std::min(m_, n_); ++i)
176 s_[i] = std::sqrt(sigmaSquaredV[i]);
188 auto Av = NdArray<double>(m_, 1);
189 for (
auto i = 0
u; i < rank; ++i)
191 for (
auto j = 0
u; j < m_; ++j)
194 for (
auto k = 0
u; k < n_; ++k)
196 sum += A(j, k) * v_(k, i);
201 const auto normalization =
norm(Av).
item();
205 for (
auto j = 0
u;
j < m_; ++
j)
207 u_(j, i) = Av[
j] / normalization;
217 NdArray<double> u_{};
218 NdArray<double> v_{};
219 NdArray<double> s_{};
220 NdArray<double> pinv_{};
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition Error.hpp:37
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition NdArrayCore.hpp:139
size_type size() const noexcept
Definition NdArrayCore.hpp:4604
self_type & reshape(size_type inSize)
Definition NdArrayCore.hpp:4351
self_type transpose() const
Definition NdArrayCore.hpp:4963
size_type numCols() const noexcept
Definition NdArrayCore.hpp:3545
self_type copy() const
Definition NdArrayCore.hpp:2562
value_type item() const
Definition NdArrayCore.hpp:3102
const NdArray< double > & u() const noexcept
Definition svd/svd.hpp:76
const NdArray< double > & s() const noexcept
Definition svd/svd.hpp:98
STATIC_ASSERT_ARITHMETIC(dtype)
static constexpr auto TOLERANCE
Definition svd/svd.hpp:54
NdArray< double > pinv()
Definition svd/svd.hpp:109
SVD(const NdArray< dtype > &inMatrix)
Definition svd/svd.hpp:62
NdArray< double > lstsq(const NdArray< double > &inInput)
Definition svd/svd.hpp:137
const NdArray< double > & v() const noexcept
Definition svd/svd.hpp:87
constexpr auto j
Definition Core/Constants.hpp:42
Definition cholesky.hpp:41
std::pair< NdArray< double >, NdArray< double > > eig(const NdArray< dtype > &inA, double inTolerance=1e-12)
Definition eig.hpp:53
NdArray< double > norm(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition norm.hpp:51
NdArray< dtype > dot(const NdArray< dtype > &inArray1, const NdArray< dtype > &inArray2)
Definition dot.hpp:48
NdArray< dtype > sum(const NdArray< dtype > &inArray, Axis inAxis=Axis::NONE)
Definition sum.hpp:46
NdArray< dtype > zeros(uint32 inSquareSize)
Definition zeros.hpp:48
Shape shape(const NdArray< dtype > &inArray) noexcept
Definition Functions/shape.hpp:42
NdArray< dtypeOut > astype(const NdArray< dtype > inArray)
Definition astype.hpp:45
std::uint32_t uint32
Definition Types.hpp:40