[R] accuracy of test cases

Robin Hankin r.hankin at soc.soton.ac.uk
Fri Apr 29 12:36:09 CEST 2005


Hi

I have several methods for evaluating a function.  The methods are 
algebraically
identical but use different numerical techniques. The different methods 
work
better (converge faster, etc) in different parts of the function's 
domain.

I am compiling a test suite for a package, and would like to verify 
that the
different methods return approximately identical results.

Toy example follows:


R> f1 <- function(x){ (x-1)*(x+1)}
R> f2 <- function(x){x^2-1}
R> x <- pi+100i
R> abs(f1(x) - f2(x))
[1] 9.298027e-12
R> stopifnot(abs(f1(x)-f2(x)) < 1e-11)

Observe that f1() should be identically equal to f2(); any differences 
are due to
rounding errors (needless to say, the real examples are more complex, 
with
larger errors).

My question is, I am unhappy about the numerical value of the tolerance 
used in the last line.
The tolerance should be as small as possible, but If I make it too 
small, the test may fail
when executed on a machine with different architecture from mine.

How do I deal with this?



--
Robin Hankin
Uncertainty Analyst
Southampton Oceanography Centre
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743




More information about the R-help mailing list