Linear Regression

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Linear Regression

Yang Ye
Hi,

I suspect there could be a self-contradiction in LinearRegression's code.

in math\linearleastsquaresregression.hpp:

Line 178-181:
    inline LinearRegression::LinearRegression(
        const std::vector<std::vector<Real> >& x,
        const std::vector<Real>& y)
    : reg_(x, y, details::linearFcts(x.size())) { }

v_ is constructed by input x.size()

Line 154-164:
        inline std::vector<boost::function1<Real, std::vector<Real> > >
        linearFcts(Size dims) {
            std::vector<boost::function1<Real, std::vector<Real> > > retVal;
            retVal.push_back(constant<std::vector<Real>, Real>(1.0));

            for (Size i=0; i < dims; ++i) {
                retVal.push_back(LinearFct(i));
            }

            return retVal;
        }


retVal is of x.size() + 1.

Line 102:
        QL_REQUIRE(x.size() >= v.size(), "sample set is too small");

x.size() >= v.size() can not be satisfied.

I would suggest to change line 181 to something like, without validation of x
    : reg_(x, y, details::linearFcts(x[0].size())) { }


Regards,
Yang Ye


------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users