From cc8f5485da933d3e417688d3987af85b21cfbcba Mon Sep 17 00:00:00 2001 From: Thomas Nagler Date: Mon, 26 Oct 2020 14:11:42 +0100 Subject: [PATCH] Patch valgrind (#51) * prevent false positive on valgrind * update CRAN comments * update docs --- DESCRIPTION | 2 +- NEWS.md | 7 +++++++ cran-comments.md | 6 +++--- docs/404.html | 4 ++-- docs/LICENSE-text.html | 4 ++-- docs/authors.html | 4 ++-- docs/index.html | 22 +++++++++++----------- docs/news/index.html | 28 +++++++++++++++++++--------- docs/pkgdown.yml | 4 ++-- docs/reference/dkde1d.html | 8 ++++---- docs/reference/equi_jitter.html | 4 ++-- docs/reference/index.html | 4 ++-- docs/reference/kde1d-package.html | 4 ++-- docs/reference/kde1d.html | 16 ++++++++-------- docs/reference/plot.kde1d.html | 12 ++++++------ inst/include/kde1d/kdefft.hpp | 2 +- inst/include/kde1d/stats.hpp | 8 +++++--- inst/include/kde1d/tools.hpp | 8 ++------ 18 files changed, 81 insertions(+), 66 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b2a06a3..8fd20d2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: kde1d Type: Package Title: Univariate Kernel Density Estimation -Version: 1.0.1 +Version: 1.0.2 Authors@R: c( person("Thomas", "Nagler",, "mail@tnagler.com", role = c("aut", "cre")), person("Thibault", "Vatter",, "thibault.vatter@gmail.com", role = c("aut")) diff --git a/NEWS.md b/NEWS.md index 99a3eb1..c4fbd24 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,10 @@ +# kde1d 1.0.2 + +BUG FIXES + + * Prevent false positive on valgrind. + + # kde1d 1.0.1 DEPENDENCIES diff --git a/cran-comments.md b/cran-comments.md index 99f62be..3ba6bae 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,8 +1,8 @@ -Patch to fix undefined behavior/heap overflow failures detected by the -sanitizers: https://cran.r-project.org/web/checks/check_results_kde1d.html +Patch to prevent possible false positive on valgrind (only on some platforms): https://cran.r-project.org/web/checks/check_results_kde1d.html ## Test environments -* ubuntu 18.04 with valgrind (release) +* ubuntu 18.04 with gcc7 and valgrind (release) +* ubuntu 18.04 clang 9 and valgrind (release) * ubuntu 18.04 with clang ASAN/UBSAN on rocker (devel) * ubuntu 14.04 on travis-ci (release, devel, oldrel) * win-builder (devel, release) diff --git a/docs/404.html b/docs/404.html index ee5a16c..e1a60ba 100644 --- a/docs/404.html +++ b/docs/404.html @@ -67,7 +67,7 @@ kde1d - 1.0.1 + 1.0.2 @@ -123,7 +123,7 @@

Page not found (404)

-

Site built with pkgdown 1.4.1.

+

Site built with pkgdown 1.4.1.9000.

diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index fecd3f4..4ec016a 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -67,7 +67,7 @@ kde1d - 1.0.1 + 1.0.2 @@ -125,7 +125,7 @@

License

-

Site built with pkgdown 1.4.1.

+

Site built with pkgdown 1.4.1.9000.

diff --git a/docs/authors.html b/docs/authors.html index b076654..2d6d5ea 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -67,7 +67,7 @@ kde1d - 1.0.1 + 1.0.2 @@ -132,7 +132,7 @@

Authors

-

Site built with pkgdown 1.4.1.

+

Site built with pkgdown 1.4.1.9000.

diff --git a/docs/index.html b/docs/index.html index 7f4bde4..a7d54fb 100644 --- a/docs/index.html +++ b/docs/index.html @@ -36,7 +36,7 @@ kde1d - 1.0.1 + 1.0.2 @@ -99,7 +99,7 @@

  • the latest development version:
  • +devtools::install_github("tnagler/kde1d@dev")

    @@ -108,8 +108,8 @@

    Unbounded data
    x <- rnorm(100)                    # simulate data
    -fit <- kde1d(x)                    # estimate density
    -dkde1d(0, fit)                     # evaluate density estimate
    +fit <- kde1d(x)                    # estimate density
    +dkde1d(0, fit)                     # evaluate density estimate
     summary(fit)                       # information about the estimate
     plot(fit)                          # plot the density estimate
     curve(dnorm(x), add = TRUE,        # add true density
    @@ -119,8 +119,8 @@ 
    Bounded data, log-linear
    x <- rgamma(100, shape = 1)        # simulate data
    -fit <- kde1d(x, xmin = 0, deg = 1) # estimate density
    -dkde1d(seq(0, 5, by = 1), fit)     # evaluate density estimate
    +fit <- kde1d(x, xmin = 0, deg = 1) # estimate density
    +dkde1d(seq(0, 5, by = 1), fit)     # evaluate density estimate
     summary(fit)                       # information about the estimate
     plot(fit)                          # plot the density estimate
     curve(dgamma(x, shape = 1),        # add true density
    @@ -132,8 +132,8 @@ 
    Discrete data
    x <- rbinom(100, size = 5, prob = 0.5)  # simulate data
     x <- ordered(x, levels = 0:5)           # declare as ordered
    -fit <- kde1d(x)                         # estimate density
    -dkde1d(sort(unique(x)), fit)            # evaluate density estimate
    +fit <- kde1d(x)                         # estimate density
    +dkde1d(sort(unique(x)), fit)            # evaluate density estimate
     summary(fit)                            # information about the estimate
     plot(fit)                               # plot the density estimate
     points(ordered(0:5, 0:5),               # add true density
    @@ -144,9 +144,9 @@ 
    Weighted estimate
    x <- rnorm(100)                         # simulate data
     weights <- rexp(100)                    # weights as in Bayesian bootstrap
    -fit <- kde1d(x, weights = weights)      # weighted fit
    +fit <- kde1d(x, weights = weights)      # weighted fit
     plot(fit)                               # compare with unweighted fit
    -lines(kde1d(x), col = 2)
    +lines(kde1d(x), col = 2)
    @@ -207,7 +207,7 @@

    Dev status

    -

    Site built with pkgdown 1.4.1.

    +

    Site built with pkgdown 1.4.1.9000.

    diff --git a/docs/news/index.html b/docs/news/index.html index f2969b6..d4bf3f6 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -67,7 +67,7 @@ kde1d - 1.0.1 + 1.0.2
    @@ -110,13 +110,22 @@

    Changelog

    Source: NEWS.md +
    +

    +kde1d 1.0.2 Unreleased +

    +

    BUG FIXES

    +
      +
    • Prevent false positive on valgrind.
    • +
    +

    -kde1d 1.0.1 Unreleased +kde1d 1.0.1 2019-11-15

    DEPENDENCIES

      -
    • Removed dependence on qrng package because it was to heavy (qrng <- copula <- gsl, #46).
    • +
    • Removed dependence on qrng (#46).

    BUG FIXES

      @@ -136,10 +145,10 @@

      NEW FEATURES

      • optimal plug-in bandwidth selection for all polynomial degrees (#38).

      • -
      • avoid randomness through simplified, deterministic jittering, see equi_jitter() (#40).

      • +
      • avoid randomness through simplified, deterministic jittering, see equi_jitter() (#40).

      • headers in inst/include can be used as standalone C++ library with convenience wrappers for R (#41).

      • -
      • (several times) faster pkde1d(), qkde1d(), and rkde1d() due to a more clever algorithm for numerical integration (#42).

      • -
      • faster kde1d() thanks to the Fast Fourier Transform (#43).

      • +
      • (several times) faster pkde1d(), qkde1d(), and rkde1d() due to a more clever algorithm for numerical integration (#42).

      • +
      • faster kde1d() thanks to the Fast Fourier Transform (#43).

      BUG FIXES

        @@ -152,7 +161,7 @@

        NEW FEATURE

        BUG FIX

          @@ -170,7 +179,7 @@

        BUG FIXES

          -
        • consistent behavior when dkde1d() and pkde1d() are called with non-ordered input although data are discrete (#19).

        • +
        • consistent behavior when dkde1d() and pkde1d() are called with non-ordered input although data are discrete (#19).

        • fixed bug in computation of kernel density estimates (#20).

        • adapt minimum bw allowed for discrete data to truncated Gaussian kernel (#20).

        @@ -203,6 +212,7 @@

        Contents

        -

        Site built with pkgdown 1.4.1.

        +

        Site built with pkgdown 1.4.1.9000.

        diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 8999c6f..2079fee 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -1,5 +1,5 @@ pandoc: 2.3.1 -pkgdown: 1.4.1 -pkgdown_sha: ~ +pkgdown: 1.4.1.9000 +pkgdown_sha: 61c3999702966dd75267b98ce905df22521ebd11 articles: [] diff --git a/docs/reference/dkde1d.html b/docs/reference/dkde1d.html index 9a347b3..b30442a 100644 --- a/docs/reference/dkde1d.html +++ b/docs/reference/dkde1d.html @@ -70,7 +70,7 @@ kde1d - 1.0.1 + 1.0.2

    @@ -172,12 +172,12 @@

    Details is the length of the numerical argument for the other functions.

    See also

    -

    kde1d()

    +

    Examples

    set.seed(0) # for reproducibility x <- rnorm(100) # simulate some data -fit <- kde1d(x) # estimate density +fit <- kde1d(x) # estimate density dkde1d(0, fit) # evaluate density estimate (close to dnorm(0)) pkde1d(0, fit) # evaluate corresponding cdf (close to pnorm(0))
    #> [1] 0.5008513
    qkde1d(0.5, fit) # quantile function (close to qnorm(0))
    #> [1] -0.001893213
    hist(rkde1d(100, fit)) # simulate
    @@ -201,7 +201,7 @@

    Contents

    -

    Site built with pkgdown 1.4.1.

    +

    Site built with pkgdown 1.4.1.9000.

    diff --git a/docs/reference/equi_jitter.html b/docs/reference/equi_jitter.html index 908695d..f21382a 100644 --- a/docs/reference/equi_jitter.html +++ b/docs/reference/equi_jitter.html @@ -70,7 +70,7 @@ kde1d - 1.0.1 + 1.0.2 @@ -177,7 +177,7 @@

    Contents

    -

    Site built with pkgdown 1.4.1.

    +

    Site built with pkgdown 1.4.1.9000.

    diff --git a/docs/reference/index.html b/docs/reference/index.html index 066f71f..295dcaf 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -67,7 +67,7 @@ kde1d - 1.0.1 + 1.0.2 @@ -174,7 +174,7 @@

    Contents

    -

    Site built with pkgdown 1.4.1.

    +

    Site built with pkgdown 1.4.1.9000.

    diff --git a/docs/reference/kde1d-package.html b/docs/reference/kde1d-package.html index 6f12b05..3df9029 100644 --- a/docs/reference/kde1d-package.html +++ b/docs/reference/kde1d-package.html @@ -72,7 +72,7 @@ kde1d - 1.0.1 + 1.0.2 @@ -158,7 +158,7 @@

    Contents

    -

    Site built with pkgdown 1.4.1.

    +

    Site built with pkgdown 1.4.1.9000.

    diff --git a/docs/reference/kde1d.html b/docs/reference/kde1d.html index f0ec6d4..4a2ac90 100644 --- a/docs/reference/kde1d.html +++ b/docs/reference/kde1d.html @@ -70,7 +70,7 @@ kde1d - 1.0.1 + 1.0.2 @@ -179,7 +179,7 @@

    Details log-transform is used if there is only one boundary (see, Geenens and Wang, 2018); a probit transform is used if there are two (see, Geenens, 2014).

    Discrete variables are handled via jittering (see, Nagler, 2018a, 2018b). -A specific form of deterministic jittering is used, see equi_jitter().

    +A specific form of deterministic jittering is used, see equi_jitter().

    References

    Geenens, G. (2014). Probit transformation for kernel density @@ -201,15 +201,15 @@

    R Statistical Society, Series B, 53, 683–690.

    See also

    -

    dkde1d(), pkde1d(), qkde1d(), rkde1d(), -plot.kde1d(), lines.kde1d()

    +

    Examples

    ## unbounded data x <- rnorm(500) # simulate data fit <- kde1d(x) # estimate density -dkde1d(0, fit) # evaluate density estimate +dkde1d(0, fit) # evaluate density estimate summary(fit) # information about the estimate
    #> kernel density estimate ('kde1d'), log-quadratic #> ----------------------------------------------------------------- #> nobs = 500, bw = 0.71, loglik = -712.05, d.f. = 4.65
    plot(fit) # plot the density estimate
    curve(dnorm(x), @@ -219,7 +219,7 @@

    Examp ## bounded data, log-linear x <- rgamma(500, shape = 1) # simulate data fit <- kde1d(x, xmin = 0, deg = 1) # estimate density -dkde1d(seq(0, 5, by = 1), fit) # evaluate density estimate +dkde1d(seq(0, 5, by = 1), fit) # evaluate density estimate summary(fit) # information about the estimate

    #> kernel density estimate ('kde1d'), log-linear with bounded support (xmin = 0) #> ----------------------------------------------------------------- #> nobs = 500, bw = 0.3, loglik = -450.93, d.f. = 12.89
    plot(fit) # plot the density estimate
    curve(dgamma(x, shape = 1), # add true density @@ -230,7 +230,7 @@

    Examp x <- rbinom(500, size = 5, prob = 0.5) # simulate data x <- ordered(x, levels = 0:5) # declare as ordered fit <- kde1d(x) # estimate density -dkde1d(sort(unique(x)), fit) # evaluate density estimate +dkde1d(sort(unique(x)), fit) # evaluate density estimate summary(fit) # information about the estimate

    #> (jittered) kernel density estimate ('kde1d'), log-quadratic #> ----------------------------------------------------------------- #> nobs = 500, bw = 1.12, loglik = -789.98, d.f. = 10.08
    plot(fit) # plot the density estimate
    points(ordered(0:5, 0:5), # add true density @@ -264,7 +264,7 @@

    Contents

    -

    Site built with pkgdown 1.4.1.

    +

    Site built with pkgdown 1.4.1.9000.

    diff --git a/docs/reference/plot.kde1d.html b/docs/reference/plot.kde1d.html index e79632b..f665fbc 100644 --- a/docs/reference/plot.kde1d.html +++ b/docs/reference/plot.kde1d.html @@ -69,7 +69,7 @@ kde1d - 1.0.1 + 1.0.2 @@ -138,20 +138,20 @@

    Arg

    See also

    -

    kde1d()

    +

    Examples

    ## continuous data x <- rbeta(100, shape1 = 0.3, shape2 = 0.4) # simulate data -fit <- kde1d(x) # unbounded estimate +fit <- kde1d(x) # unbounded estimate plot(fit, ylim = c(0, 4)) # plot estimate
    curve(dbeta(x, 0.3, 0.4), # add true density col = "red", add = TRUE -)
    fit_bounded <- kde1d(x, xmin = 0, xmax = 1) # bounded estimate +)
    fit_bounded <- kde1d(x, xmin = 0, xmax = 1) # bounded estimate lines(fit_bounded, col = "green")
    ## discrete data x <- rpois(100, 3) # simulate data x <- ordered(x, levels = 0:20) # declare variable as ordered -fit <- kde1d(x) # estimate density +fit <- kde1d(x) # estimate density plot(fit, ylim = c(0, 0.25)) # plot density estimate
    points(ordered(0:20, 0:20), # add true density values dpois(0:20, 3), col = "red" @@ -175,7 +175,7 @@

    Contents

    -

    Site built with pkgdown 1.4.1.

    +

    Site built with pkgdown 1.4.1.9000.

    diff --git a/inst/include/kde1d/kdefft.hpp b/inst/include/kde1d/kdefft.hpp index 997d4ac..eca525c 100644 --- a/inst/include/kde1d/kdefft.hpp +++ b/inst/include/kde1d/kdefft.hpp @@ -27,10 +27,10 @@ class KdeFFT private: double bw_; - Eigen::VectorXd bin_counts_; double lower_; double upper_; static constexpr size_t num_bins_{ 400 }; + Eigen::VectorXd bin_counts_; }; //! @param x vector of observations. diff --git a/inst/include/kde1d/stats.hpp b/inst/include/kde1d/stats.hpp index 16dc113..c99dddd 100644 --- a/inst/include/kde1d/stats.hpp +++ b/inst/include/kde1d/stats.hpp @@ -161,7 +161,7 @@ equi_jitter(const Eigen::VectorXd& x) srt(i) = x(perm(i)); // compute contingency table - Eigen::MatrixXd tab(n + 1, 2); + Eigen::MatrixXd tab(n, 2); size_t lev = 0; size_t cnt = 1; for (size_t k = 1; k < n; ++k) { @@ -171,14 +171,16 @@ equi_jitter(const Eigen::VectorXd& x) cnt = 1; } else { cnt++; - if (k == n - 1) + if (k == n - 1) { + tab(lev, 0) = srt(k); tab(lev++, 1) = cnt; + } } } tab.conservativeResize(lev, 2); // add deterministic, conditionally uniorm noise - Eigen::VectorXd noise(n); + Eigen::VectorXd noise = Eigen::VectorXd::Zero(n); size_t i = 0; for (size_t k = 0; k < tab.rows(); ++k) { for (size_t cnt = 1; cnt <= tab(k, 1); ++cnt) diff --git a/inst/include/kde1d/tools.hpp b/inst/include/kde1d/tools.hpp index 00fd3a3..52bebd9 100644 --- a/inst/include/kde1d/tools.hpp +++ b/inst/include/kde1d/tools.hpp @@ -107,13 +107,9 @@ linbin(const Eigen::VectorXd& x, const Eigen::VectorXd& weights) { Eigen::VectorXd gcnts = Eigen::VectorXd::Zero(num_bins + 1); - double rem, lxi, delta; + double delta = (upper - lower) / num_bins; + double rem, lxi; size_t li; - - if (upper <= lower) - throw std::runtime_error("upper != lower"); - - delta = (upper - lower) / num_bins; for (size_t i = 0; i < x.size(); ++i) { lxi = (x(i) - lower) / delta; li = static_cast(lxi);