numerical issue in contour.default?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

numerical issue in contour.default?

Thomas Petzoldt
Dear R developers,

I found a small issue while plotting contours of data containing both
"usual" and "very small" numbers. It appeared with both R 3.0.1 and
R-Devel on Windows, and I could reproduce it on Linux. Would it be
possible to solve this before the upcoming release?

Thanks a lot for developing this great software!

Thomas


Example:
########


set.seed(357)
z1 <- matrix(runif(100, -1e-180, 1e-180), nrow = 10)
contour(z1)    # ok

z2 <- matrix(c(runif(50, -1, 1), runif(50, -1e-180, 1e-180)), nrow = 10)
contour(z2)   # Error in contour.default(z) : k != 2 or 4

contour(z2 * 1e20)        # 20 worked, 19 produced error
contour(round(z2, 179))   # rounding to 179 digits works but not 180


> sessionInfo()
R Under development (unstable) (2013-09-11 r63910)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base





--
Dr. Thomas Petzoldt
Technische Universitaet Dresden
Faculty of Environmental Sciences
Institute of Hydrobiology
01062 Dresden, Germany

E-Mail: [hidden email]
http://tu-dresden.de/Members/thomas.petzoldt

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: numerical issue in contour.default?

Duncan Murdoch-2
On 13/09/2013 10:01 AM, Thomas Petzoldt wrote:
> Dear R developers,
>
> I found a small issue while plotting contours of data containing both
> "usual" and "very small" numbers. It appeared with both R 3.0.1 and
> R-Devel on Windows, and I could reproduce it on Linux. Would it be
> possible to solve this before the upcoming release?

I don't see the error in 32 bits, but I do see it in 64 bits.  I think
it's really unlikely this will be fixed before 3.0.2, unless you send a
well tested patch in the next few days.  Code freeze is on Wednesday.

Duncan Murdoch

>
> Thanks a lot for developing this great software!
>
> Thomas
>
>
> Example:
> ########
>
>
> set.seed(357)
> z1 <- matrix(runif(100, -1e-180, 1e-180), nrow = 10)
> contour(z1)    # ok
>
> z2 <- matrix(c(runif(50, -1, 1), runif(50, -1e-180, 1e-180)), nrow = 10)
> contour(z2)   # Error in contour.default(z) : k != 2 or 4
>
> contour(z2 * 1e20)        # 20 worked, 19 produced error
> contour(round(z2, 179))   # rounding to 179 digits works but not 180
>
>
> > sessionInfo()
> R Under development (unstable) (2013-09-11 r63910)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
>
> locale:
> [1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
> [3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
> [5] LC_TIME=German_Germany.1252
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
>
>
>
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: numerical issue in contour.default?

Prof Brian Ripley
On 13/09/2013 15:14, Duncan Murdoch wrote:

> On 13/09/2013 10:01 AM, Thomas Petzoldt wrote:
>> Dear R developers,
>>
>> I found a small issue while plotting contours of data containing both
>> "usual" and "very small" numbers. It appeared with both R 3.0.1 and
>> R-Devel on Windows, and I could reproduce it on Linux. Would it be
>> possible to solve this before the upcoming release?
>
> I don't see the error in 32 bits, but I do see it in 64 bits.  I think
> it's really unlikely this will be fixed before 3.0.2, unless you send a
> well tested patch in the next few days.  Code freeze is on Wednesday.

And not even then: we would not have time to do sufficiently extensive
checking.

Reporting to bugs.r-project.org with a patch would get the process rolling.

>
> Duncan Murdoch
>>
>> Thanks a lot for developing this great software!
>>
>> Thomas
>>
>>
>> Example:
>> ########
>>
>>
>> set.seed(357)
>> z1 <- matrix(runif(100, -1e-180, 1e-180), nrow = 10)
>> contour(z1)    # ok
>>
>> z2 <- matrix(c(runif(50, -1, 1), runif(50, -1e-180, 1e-180)), nrow = 10)
>> contour(z2)   # Error in contour.default(z) : k != 2 or 4
>>
>> contour(z2 * 1e20)        # 20 worked, 19 produced error
>> contour(round(z2, 179))   # rounding to 179 digits works but not 180
>>
>>
>> > sessionInfo()
>> R Under development (unstable) (2013-09-11 r63910)
>> Platform: x86_64-w64-mingw32/x64 (64-bit)
>>
>> locale:
>> [1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
>> [3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
>> [5] LC_TIME=German_Germany.1252
>>
>> attached base packages:
>> [1] stats     graphics  grDevices utils     datasets  methods   base
>>
>>
>>
>>
>>
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel


--
Brian D. Ripley,                  [hidden email]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: numerical issue in contour.default?

Thomas Petzoldt
On 13.09.2013 16:44, Prof Brian Ripley wrote:

> On 13/09/2013 15:14, Duncan Murdoch wrote:
>> On 13/09/2013 10:01 AM, Thomas Petzoldt wrote:
>>> Dear R developers,
>>>
>>> I found a small issue while plotting contours of data containing both
>>> "usual" and "very small" numbers. It appeared with both R 3.0.1 and
>>> R-Devel on Windows, and I could reproduce it on Linux. Would it be
>>> possible to solve this before the upcoming release?
>>
>> I don't see the error in 32 bits, but I do see it in 64 bits.  I think
>> it's really unlikely this will be fixed before 3.0.2, unless you send a
>> well tested patch in the next few days.  Code freeze is on Wednesday.

You are right, I can reproduce it only on 64 bit.

> And not even then: we would not have time to do sufficiently extensive
> checking.

Agreed, so I'll put a workaround in my package for now.

> Reporting to bugs.r-project.org with a patch would get the process rolling.

O.K., I will report it. After a look in the sources I would guess that
it may be in:

src/main/contour-common.h

static int ctr_intersect(double z0, double z1, double zc, double *f)
{
     if ((z0 - zc) * (z1 - zc) < 0.0) {
        *f = (zc - z0) / (z1 - z0);
        return 1;
     }
     return 0;
}


... but you are right, too many things depend on it.

Many thanks for the immediate feedback!

Thomas

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel