Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

https://github.com/cran/rstpm2
16 March 2023, 11:13:04 UTC
  • Code
  • Branches (20)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/master
    • refs/tags/1.2.2
    • refs/tags/1.3.1
    • refs/tags/1.3.2
    • refs/tags/1.3.4
    • refs/tags/1.4.0
    • refs/tags/1.4.1
    • refs/tags/1.4.2
    • refs/tags/1.4.4
    • refs/tags/1.4.5
    • refs/tags/1.5.0
    • refs/tags/1.5.1
    • refs/tags/1.5.2
    • refs/tags/1.5.5
    • refs/tags/1.5.6
    • refs/tags/1.5.7
    • refs/tags/1.5.8
    • refs/tags/1.5.9
    • refs/tags/1.6.1
    • refs/tags/1.6.2
    No releases to show
  • 4c2255a
  • /
  • tests
  • /
  • testthat
  • /
  • test_vuniroot.R
Raw File Download
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
origin badgecontent badge Iframe embedding
swh:1:cnt:9b6a23a47c23a32969863656cbbbffb77785c3a0
origin badgedirectory badge Iframe embedding
swh:1:dir:f10096d0aa097e87998d52971f958c4568774957
origin badgerevision badge
swh:1:rev:936fa1723eb80b0f9d4b12a1e50e5c542b549b35
origin badgesnapshot badge
swh:1:snp:6a0ac420dcf26f4ce7b9c8b5d3c5816f5620bd13
Citations

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
  • revision
  • snapshot
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Tip revision: 936fa1723eb80b0f9d4b12a1e50e5c542b549b35 authored by Mark Clements on 03 March 2021, 16:10:02 UTC
version 1.5.2
Tip revision: 936fa17
test_vuniroot.R
library(rstpm2)

## for coping with weird test behaviour from CRAN and R-devel
.CRAN <- FALSE
## pstpm2+frailty models are slow
slow <- FALSE

expect_eps <- function(expr, value, eps=1e-7)
    expect_lt(max(abs(expr-value)),eps)

context("vuniroot")
##
test_that("examples", {
    ## some platforms hit zero exactly on the first step:
    ## if so the estimated precision is 2/3.
    f <- function (x, a) x - a
    xmin <- vuniroot(f, lower=c(0, 0), upper=c(1,1), tol = 0.0001, a = c(1/3,2/3))
    expect_eps(xmin$root, c(1/3,2/3), 1e-10)
    ## handheld calculator example: fixed point of cos(.):
    expect_eps(vuniroot(function(x) cos(x) - x, lower = -pi, upper = pi, tol = 1e-9)$f.root,
               0, 1e-10)
    expect_eps(vuniroot(function(x) x*(x^2-1) + .5, lower = -2, upper = 2,
            tol = 0.0001)$f.root, 0, 1e-5)
    expect_eps(vuniroot(function(x) x*(x^2-1) + .5, lower = -2, upper = 2,
                        tol = 1e-10)$f.root, 0, 1e-10)
    ## Find the smallest value x for which exp(x) > 0 (numerically):
    expect_eps((r <- vuniroot(function(x) 1e80*exp(x) - 1e-300, cbind(-1000, 0), tol = 1e-15))$root,
               -745.133219101941, 1e-5)
    ##--- vuniroot() with new interval extension + checking features: --------------
    f1 <- function(x) (121 - x^2)/(x^2+1)
    f2 <- function(x) exp(-x)*(x - 12)
    expect_error(vuniroot(f1, cbind(0,10)),
                 "f[(][)] values at end points not of opposite sign")
    expect_error(vuniroot(f1, cbind(0,2)),
                 "f[(][)] values at end points not of opposite sign")
    ## where as  'extendInt="yes"'  simply first enlarges the search interval:
    u1 <- vuniroot(f1, cbind(0,10),extendInt="yes")
    u2 <- vuniroot(f2, cbind(0,2), extendInt="yes")
    expect_eps(u1$root, 11, 1e-4)
    expect_eps(u2$root, 12, 1e-5)
    ## The *danger* of interval extension:
    ## No way to find a zero of a positive function, but
    ## numerically, f(-|M|) becomes zero :
    expect_error(vuniroot(exp, cbind(0,2), extendInt="yes"),
                 "did not succeed extending the interval endpoints for f[(]lower[)] [*] f[(]upper[)] <= 0")
    ## Nonsense example (must give an error):
    expect_error(vuniroot(function(x) 1, cbind(0,1), extendInt="yes"),
                 "no sign change found in 1000 iterations")
    ## Convergence checking :
    sinc <- function(x) ifelse(x == 0, 1, sin(x)/x)
    expect_warning(vuniroot(sinc, cbind(0,5), extendInt="yes", maxiter=4),
                   "_NOT_ converged in 4 iterations")
    ## now with  check.conv=TRUE, must signal a convergence error :
    expect_error(vuniroot(sinc, cbind(0,5), extendInt="yes", maxiter=4, check.conv=TRUE),
                   "_NOT_ converged in 4 iterations")
    ## Weibull cumulative hazard (example origin, Ravi Varadhan):
    cumhaz <- function(t, a, b) b * (t/b)^a
    froot <- function(x, u, a, b) cumhaz(x, a, b) - u
    set.seed(12345)
    n <- 10
    u <- -log(runif(n))
    a <- 1/2
    b <- 1
    ## Find failure times
    ru <- vuniroot(froot, u=u, a=a, b=b, interval= cbind(rep(1.e-14,n), rep(1e4,n)),
                   extendInt="yes")$root
    ru2 <- vuniroot(froot, u=u, a=a, b=b, interval= cbind(rep(0.01,n), rep(10,n)),
                    extendInt="yes")$root
    expect_eps(ru, ru2, 1e-4)
    r1 <- vuniroot(froot, u= 0.99, a=a, b=b, interval= cbind(0.01, 10),
                   extendInt="up")
    expect_eps(0.99, cumhaz(r1$root, a=a, b=b), 1e-8)
    expect_error(vuniroot(froot, u= 0.99, a=a, b=b, interval= cbind(0.1, 10), extendInt="down"),
                 "no sign change found in 1000 iterations")
})

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Contact— JavaScript license information— Web API

back to top