27#ifndef quantlib_general_linear_least_squares_hpp
28#define quantlib_general_linear_least_squares_hpp
47 template <
class xContainer,
class yContainer,
class vContainer>
49 const yContainer &
y,
const vContainer &
v);
51 template<
class xIterator,
class yIterator,
class vIterator>
53 yIterator yBegin, yIterator yEnd,
54 vIterator vBegin, vIterator vEnd);
71 template <
class xIterator,
class yIterator,
class vIterator>
73 xIterator xBegin, xIterator xEnd,
74 yIterator yBegin, yIterator yEnd,
78 template <
class xContainer,
class yContainer,
class vContainer>
inline
85 standardErrors_(
v.size()) {
86 calculate(x.begin(), x.end(),
y.begin(),
y.end(),
v.begin());
89 template<
class xIterator,
class yIterator,
class vIterator>
inline
91 xIterator xBegin, xIterator xEnd,
92 yIterator yBegin, yIterator yEnd,
93 vIterator vBegin, vIterator vEnd)
94 :
a_(
std::distance(vBegin, vEnd), 0.0),
96 residuals_(
std::distance(yBegin, yEnd)),
97 standardErrors_(
a_.size()) {
98 calculate(xBegin, xEnd, yBegin, yEnd, vBegin);
102 template <
class xIterator,
class yIterator,
class vIterator>
104 yIterator yBegin, yIterator yEnd,
111 "sample set need to be of the same size");
118 std::transform(xBegin, xEnd, A.
column_begin(i), *vBegin++);
126 for (i=0; i<m; ++i) {
127 if (w[i] > threshold) {
130 yBegin,
Real(0.0))/w[i];
132 for (
Size j=0; j<m; ++j) {
134 err_[j]+=V[j][i]*V[j][i]/(w[i]*w[i]);
144 const Real multiplier = std::sqrt(chiSq/(
n-2));
146 [=](
Real x) ->
Real { return x * multiplier; });
1-D array used in linear algebra.
1-D array used in linear algebra.
const_iterator end() const
Size size() const
dimension of the array
const_iterator begin() const
general linear least squares regression
const Array & error() const
modeling uncertainty as definied in Numerical Recipes
const Array & residuals() const
const Array & standardErrors() const
standard parameter errors as given by Excel, R etc.
void calculate(xIterator xBegin, xIterator xEnd, yIterator yBegin, yIterator yEnd, vIterator vBegin)
const Array & coefficients() const
GeneralLinearLeastSquares(const xContainer &x, const yContainer &y, const vContainer &v)
Matrix used in linear algebra.
const_column_iterator column_begin(Size i) const
const_column_iterator column_end(Size i) const
Singular value decomposition.
const Array & singularValues() const
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
std::size_t Size
size of a container
Array Sqrt(const Array &v)
ext::shared_ptr< BlackVolTermStructure > v
Global definitions and compiler switches.
singular value decomposition