Re: [eigen] inverse unit test |

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]

*To*: eigen@xxxxxxxxxxxxxxxxxxx*Subject*: Re: [eigen] inverse unit test*From*: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>*Date*: Thu, 10 Jun 2010 09:26:50 +0200*Dkim-signature*: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:to:content-type; bh=n3QYm7LjXc1XJPks5QJ2fcokiUjR3xV3X+mYodeJr8w=; b=uS88f/cm/v1Fm7yfapl/SF+CeHIE5RzBMzvlI7NOVAZz/vzIgr/1H2qI5YuZ4Nvqr2 KShaZM3H0SVgE7BlBHy68NTY2GnWQ6GpI8QdPvAF2GPR7gdcpe9usBc7dA9ItZRgSo0w HNdT5YtFyL9dqNz3LC5bgN7BxxXnt+EQBDhlg=*Domainkey-signature*: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; b=vO/GUnHtTkb021+gUIVjgigVbYLEOCcl/bZC02lWnkTmkEGOajgOZtQsrluJ5dsqW6 qlZisQKM4D3HmaEn692fUH7rZxh218ePE1J7iewFhS2TmumOPWxVkY+frys3TXTXdiHB 6CtxsH4df2VWc3C+iw/1IfT3xhlbgbBCHZE3A=

On Thu, Jun 10, 2010 at 9:14 AM, Hauke Heibel <hauke.heibel@xxxxxxxxxxxxxx> wrote:

"close to zero" compared to what? I mean the notion of "close to zero" has to be defined relatively to some reference values. For instance 1 can be considered to be zero if you consider float values in the order of 1e10. This is exactly the purpose of isMuchSmallerThan(x,ref) which could also be called isZeroComparedTo. So no need for an additional isApproxZero.

gael

Granted, the proposed solution is too lax though it is only happening

in the vicinity of zero.

Here is an alternative. Why not introduce another test that is used in

particular for those cases where we want to check against being close

to zero?

static inline bool isApproxZero(const Scalar& x, const

RealScalar& thresh = NumTraits<Scalar>::epsilon())

{

ei_abs(x) < thresh);

}

VERIFY_IS_APPROX_ZERO(something_near_zero)

VERIFY(isApproxZero(something_near_zero))

"close to zero" compared to what? I mean the notion of "close to zero" has to be defined relatively to some reference values. For instance 1 can be considered to be zero if you consider float values in the order of 1e10. This is exactly the purpose of isMuchSmallerThan(x,ref) which could also be called isZeroComparedTo. So no need for an additional isApproxZero.

gael

- Hauke

On Thu, Jun 10, 2010 at 1:05 AM, Benoit Jacob <jacob.benoit.1@xxxxxxxxx> wrote:

> 2010/6/9 Hauke Heibel <hauke.heibel@xxxxxxxxxxxxxx>:

>> Maybe this simple hack is all we need:

>>

>> static inline bool isApprox(const Scalar& x, const Scalar& y, const

>> RealScalar& prec)

>> {

>> return (ei_abs(x - y) <= std::min(ei_abs(x), ei_abs(y)) * prec ||

>> ei_abs(x - y) < NumTraits<Scalar>::epsilon());

>> }

>

> No, that is not correct to do in such generality (at the level of

> isApprox), because it would imply that

>

> isApprox(1e-10, 1e-30) == true

>

> even though these values are very different (one is 1e+20 bigger than

> the other). Our FP fuzzy compares are completely 'relative', they do

> not declare any particular order of magnitude to be 'negligible'.

>

> But you are right: any comparison of the form

>

> VERIFY_IS_APPROX(something_near_zero, something_else_near_zero)

>

> is inherently bogus, since, as you noted, it fails when these values

> are actually exactly zero. The fix is going to look what you suggest

> above, except that it must be local to this unit-test and not

> generalized to isApprox(). In the particular context of the unit test,

> we have a good frame of reference to compare the difference with,

> namely, let's just compare it with 1. So, replace

>

> VERIFY_IS_APPROX(x, y)

>

> by

>

> VERIFY_IS_MUCH_SMALLER_THAN( x-y, 1)

>

> Cheers,

> Benoit

>

>>

>> - Hauke

>>

>> On Thu, Jun 10, 2010 at 12:43 AM, Hauke Heibel

>> <hauke.heibel@xxxxxxxxxxxxxx> wrote:

>>> On MSVC the inverse unit test fails here:

>>>

>>> //Second: a rank one matrix (not invertible, except for 1x1 matrices)

>>> VectorType v3 = VectorType::Random(rows);

>>> MatrixType m3 = v3*v3.transpose(), m4(rows,cols);

>>> m3.computeInverseAndDetWithCheck(m4, det, invertible);

>>> VERIFY( rows==1 ? invertible : !invertible );

>>> VERIFY_IS_APPROX(det, m3.determinant());

>>> m3.computeInverseWithCheck(m4, invertible);

>>> VERIFY( rows==1 ? invertible : !invertible );

>>>

>>> We expect a determinant of 0 since the matrix is not invertible and

>>> then this check fails

>>>

>>> VERIFY_IS_APPROX(det, m3.determinant());

>>>

>>> VERIFY_IS_APPROX will always fail in case one of the two parameters is

>>> zero and in case both values are small it is likely to fail as well

>>> because

>>>

>>> abs(x-y) <= min(abs(x),abs(y)) * 1e-3

>>>

>>> here, we take the minimal value and make it even smaller.

>>>

>>> Here are some nice comparison methods we might try to adapt:

>>> http://www.boost.org/doc/libs/1_32_0/boost/test/floating_point_comparison.hpp

>>>

>>> - Hauke

>>>

>>

>>

>>

>

>

>

**Follow-Ups**:**Re: [eigen] inverse unit test***From:*Manuel Yguel

**References**:**[eigen] inverse unit test***From:*Hauke Heibel

**Re: [eigen] inverse unit test***From:*Hauke Heibel

**Re: [eigen] inverse unit test***From:*Benoit Jacob

**Re: [eigen] inverse unit test***From:*Hauke Heibel

**Messages sorted by:**[ date | thread ]- Prev by Date:
**Re: [eigen] inverse unit test** - Next by Date:
**Re: [eigen] inverse unit test** - Previous by thread:
**Re: [eigen] inverse unit test** - Next by thread:
**Re: [eigen] inverse unit test**

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