Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!c65g2000hsa.googlegroups.com!not-for-mail
From: Greg Heath <heath@alumni.brown.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Vectorization for Quadratic Polynomial Regression
Date: Wed, 2 Jul 2008 16:02:35 -0700 (PDT)
Organization: http://groups.google.com
Lines: 78
Message-ID: <6df4a42e-3d83-4dd7-9441-c371361dab06@c65g2000hsa.googlegroups.com>
References: <cddc4bd3-1f78-4fad-90d2-a7cde7ec5189@e39g2000hsf.googlegroups.com> 
NNTP-Posting-Host: 69.141.173.117
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1215039755 28132 127.0.0.1 (2 Jul 2008 23:02:35 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Wed, 2 Jul 2008 23:02:35 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: c65g2000hsa.googlegroups.com; posting-host=69.141.173.117; 
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 
Xref: news.mathworks.com comp.soft-sys.matlab:477261


On Jul 2, 2:16=A0pm, "Per Sundqvist" <sun...@fy.chalmers.se> wrote:
> Greg Heath <he...@alumni.brown.edu> wrote in message
>
> <cddc4bd3-1f78-4fad-90d2-a7cde7ec5...@e39g2000hsf.googlegroups.com>...
>
>
>
> > I have an original predictor matrix X0 with
>
> > size(X0) =3D [ m n0]
>
> > I'd like to perform the
>
> > linear-coefficient/quadratic-variable regression
>
> > y =3D X*W + e
>
> > size(X) =3D [ m n]
>
> > n =3D n0*(n0+3)/2
>
> > and X contains the columns of X0,
> > their squares, and their cross products.
>
> > Currently, X is created by the following double loop
>
> > X =3D X0;
> > for i =3D 1:n0-1
> > =A0 =A0 for j=3D i+1:n0
> > =A0 =A0 =A0 =A0 X =3D [ X X0(:,i).*X0(:,j)];
> > =A0 =A0 end
> > end
> > X =3D [X X0.^2];
>
> > Example:
>
> > X0 =3D [ =A01 2 3; 4 5 6]
>
> > X =3D
> > =A0 =A0 =A01 =A0 =A0 2 =A0 =A0 3 =A0 =A0 2 =A0 =A0 3 =A0 =A0 6 =A0 =A0 1=
 =A0 =A0 4 =A0 =A0 9
> > =A0 =A0 =A04 =A0 =A0 5 =A0 =A0 6 =A0 =A020 =A0 =A024 =A0 =A030 =A0 =A016=
 =A0 =A025 =A0 =A036
>
> > Can the double loop be vectorized?
>
> > TIA,
>
> > Greg
>
> Hi,
>
> It seems that you have messed up the formulation of the
> quadratic least square problem. Isnt it(?):
>
> yi=3Dc0+c1*xi+c2*xi.^2

No.

There are multiple variables ( e.g., n0 =3D 3 ) in X0, yielding
n0 original variable columns, n0 variable squared columns
and n0*(n0-1)/2 crossproduct columns in X.

When n0 =3D 3, n =3D 9 and, for size(y) =3D [m 1]
size(W) =3D [n+1 1] =3D [10 1]. For measurement i

yhati =3D    W1*1 + W2*x1i + W3*x2i + W4*x3i +
              W5*x1i*x2i + W6 *x1i*x3i +  W7*x2i*x3i +
              W8*x1i^2 + W9*x2i^2 + W10*x3i^2

 where

W =3D [ones(m,1) X]\y;

Hope this helps.

Greg