[eigen] Documentation for Eigen::{fitHyperplane,linearRegression}
• To: eigen@xxxxxxxxxxxxxxxxxxx
• Subject: [eigen] Documentation for Eigen::{fitHyperplane,linearRegression}
• From: Tilman Vogel <tilman.vogel@xxxxxx>
• Date: Tue, 20 Apr 2010 11:54:44 +0200
• Domainkey-signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=sender:message-id:date:from:user-agent:mime-version:to:subject :x-enigmail-version:content-type:content-transfer-encoding; b=uYv/A3PU4w8Mv4B7UuSTDhyzyZCYOjwfa90kwqPsBvsGZAUpQo/6b6c4GmJTxqZbWK fYH8gouyyqFuQY9nSq5AERXzIdPX2M6jkloyukj9QY104lH0P96zRt99Y9eHx8dwObGa 2frBzCXyi/7FwYeN9V6MHwzd/6nDMYosmqx5k=

```-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

I think, the example in the documentation is incorrect. The parameter
"points" is documented as "the array of pointers to the points on which
to perform the linear regression" and the code reveals that it is used
as such, however, the example does:

Vector3d points[5];
points[0] = Vector3d( 3.02, 6.89, -4.32 );
points[1] = Vector3d( 2.01, 5.39, -3.79 );
points[2] = Vector3d( 2.41, 6.01, -4.01 );
points[3] = Vector3d( 2.09, 5.55, -3.86 );
points[4] = Vector3d( 2.58, 6.32, -4.10 );

Vector3d coeffs; // will store the coefficients a, b, c
linearRegression(
5,
&points,
&coeffs,
1 // the coord to express as a function of
// the other ones. 0 means x, 1 means y, 2 means z.
);

I.e. it passes a pointer to an array of points instead of an array of
pointers to points. Which is formally correct w.r.t. the level of
indirection, but actually, gcc 4.4.1 won't accept it. It can be forced
by doing

Vector3d * p = points;
linearRegression(
5,
&p,
&coeffs,
1 // the coord to express as a function of
// the other ones. 0 means x, 1 means y, 2 means z.
);

but it will cause a segfault as expected.

The example should be fixed to be:

Vector3d * points[5];
points[0] = new Vector3d( 3.02, 6.89, -4.32 );
points[1] = new Vector3d( 2.01, 5.39, -3.79 );
points[2] = new Vector3d( 2.41, 6.01, -4.01 );
points[3] = new Vector3d( 2.09, 5.55, -3.86 );
points[4] = new Vector3d( 2.58, 6.32, -4.10 );

Vector3d coeffs; // will store the coefficients a, b, c
linearRegression(
5,
points,
&coeffs,
1 // the coord to express as a function of
// the other ones. 0 means x, 1 means y, 2 means z.
);

Regards,

Tilman

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.12 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org/

iEYEARECAAYFAkvNeeQACgkQ9ZPu6Yae8lk99gCeO8oeiGJE91/L4KGr0PlyjtHs
Gs8AnjhD/8bmkiFdraFdp3/ZxNbX74tk
=sNGM
-----END PGP SIGNATURE-----

```

 Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/