Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Round to machine tolerance

$
0
0

I'd like to take a set of predictions and round them to machine tolerance, then calculate a hash from those numbers. The goal is to determine whether a complicated R process which generates those numbers has been altered. Each substantive change to the codebase to the process will generate these numbers, round them them, then compute the hash so identicalness of the process can be easily determined and tracked in a database.

I'm familiar with all.equal(), but using all.equal() would require every set of numbers to be compared with every other set of numbers directly in R--whereas what I'm envisioning the comparison of identicalness to a large set of process versions can be done just based on hashes in a table.

So my question is how would I round a numeric vector in R to a precision exactly comparable to the precision used in all.equal?

i.e., let's name the rounding function that accomplishes what I want machine.round: identical(machine.round(x),machine.round(y)) is TRUE if and only if all.equal(x,y) is TRUE.

what is the definition of machine.round?

#two vectors which are considered equal by all.equal but not by identical
x <- c(.3, .4 - .1, .5 - .2, .6 - .3, .7 - .4)
y <- c(.3, .3, .3, .3, .3)
all.equal(x,y)
identical(x,y)

#two vectors which are considered unequal by all.equal and identical: x2 <- c(.30001, .4 - .1, .5 - .2, .6 - .3, .7 - .4) y2 <- c(.3, .3, .3, .3, .3) all.equal(x2,y2) identical(x2,y2)

I want a function machine.round() that returns TRUE for arguments x and y but FALSE for arguments x2 and y2.


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>