chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Using epsilon in test egg


From: Alex Shinn
Subject: Re: [Chicken-users] Using epsilon in test egg
Date: Mon, 28 Jul 2014 11:19:24 +0900

On Sun, Jul 27, 2014 at 10:03 AM, Matt Gushee <address@hidden> wrote:
Hmm, just realized something. The test egg documentation also says:

  "Percentage difference allowed ..."

So if the expected value is 0, then no variance is allowed? If that's
true, then epsilon isn't what I want anyway. I need to allow an
absolute amount of variance that is independent of the values being
tested.

By the way, in general you do _not_ want absolute differences.
The test egg is doing the right thing for general comparisons.
Arguably it may be better to use ULPs (Units in the Last Place),
but they're harder to get at in portable Scheme and not clearly
better.  For more than you ever wanted to know about the subject
see:

http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm

The solution is definitely not to write your own comparison function,
and trust that the test egg is doing the right thing.

-- 
Alex


Anyway, I'd appreciate help in understanding how this is supposed to work ...

On Sat, Jul 26, 2014 at 6:42 PM, Matt Gushee <address@hidden> wrote:
> Hi, folks--
>
> I am working on an application that does a lot of floating-point
> calculations, and I'm having trouble with the test suite. The program
> is based on the imlib2 egg, and it does some fairly simple image
> processing for web applications, so the numbers in question are RGBA
> color values. Internally I am handling all the numbers as floats in
> the range 0-1, because the blending and compositing formulas are much
> more straightforward that way compared to using integers 0-255.
>
> So I have a number of functions that produce lists of numbers like these:
>
>   '(0.323 0.788834 0.12 0.4)
>   '(0 0 0 1.0)
>   '(0.6666666667 0.4 0.562 0.0)
>
> And given the above, a moderate degree of imprecision in the results
> is perfectly acceptable - I haven't yet confirmed this with actual
> images, but I'm thinking as much as 0.5% variance should work fine
> (basically, as long as the colors in the generated images look as
> expected to a casual observer, the result should be acceptable). So of
> course I want the test results to reflect this.
>
> I am using the following procedure to compare number lists:
>
>   (define (list= l1 l2)
>   (and (= (length l1) (length l2))
>        (let loop ((l1* l1) (l2* l2))
>          (cond
>            ((null? l1*) #t)
>            ((= (car l1*) (car l2*)) (loop (cdr l1*) (cdr l2*)))
>            (else #f)))))
>
> And for the tests that use this predicate, I set
>
>   (current-test-epsilon 0.005)
>
> [or 0.002 or 0.001 - it doesn't seem to make any difference]
>
> But I'm finding that certain tests still fail unexpectedly, e.g.
>
>  2.03.10: (parse-color "167,215,51" #f) => '(0.655 0.843 0.200 1.0)  [ FAIL]
>           expected (0.655 0.843 0.2 1.0)
>           but got (0.654901960784314   0.843137254901961 0.2 1.0)
>
> But:
>
>   (/ 0.654901960784314 0.655) => 0.999850321808113
>   (/ 0.843137254901961 0.843) => 1.0001628172028
>
> So it would appear that the epsilon value does not apply to these tests.
>
> I can certainly define a custom equality predicate that will do what I
> need, but this is bugging me. I guess I don't really understand how
> epsilon is supposed to work. The test egg documentation says that
> applies to 'inexact comparisons', but I can't find a definition of
> 'inexact comparison'. I have also read that '=' may be unreliable for
> inexact numbers, but I don't know what else to use. Perhaps 'fp=' from
> the Chicken library? Then I would have to ensure that all numbers are
> expressed as floats, whereas currently my code has a number of cases
> where 1 and 0 are expressed as integers.
>
> So ... do I understand the problem correctly? Any recommendations?
>
> Matt Gushee

_______________________________________________
Chicken-users mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/chicken-users


reply via email to

[Prev in Thread] Current Thread [Next in Thread]