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/PPCI
30 March 2023, 14:15:34 UTC
  • Code
  • Branches (7)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/master
    • refs/tags/0.1.0
    • refs/tags/0.1.1
    • refs/tags/0.1.2
    • refs/tags/0.1.3
    • refs/tags/0.1.4
    • refs/tags/0.1.5
    No releases to show
  • 2ff48c5
  • /
  • R
  • /
  • optimPPclust.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 ...

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
swh:1:cnt:04eae90d38caca6f253dc719ef4dd1667142ea81
origin badgedirectory badge
swh:1:dir:c6ae2e108fe53d5999dfbba677524b290dfe4c66
origin badgerevision badge
swh:1:rev:9ba54159941dcc5730dcfa88b0343c79a74647b1
origin badgesnapshot badge
swh:1:snp:9ace04b2c94432796421fb717e13808d1f8eab89

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: 9ba54159941dcc5730dcfa88b0343c79a74647b1 authored by David Hofmeyr on 08 October 2018, 09:10:10 UTC
version 0.1.3
Tip revision: 9ba5415
optimPPclust.R
#### A modification of R's default optimisation to allow, in particular, verbosity levels used
#### in Hofmeyr and Pavlidis (2017)

### function ppclust.optim() finds the optimal projection vector for clustering using one of the
### objectives in Hofmeyr and Pavlidis (2017)
## arguments:
# v0 = vector. Initial projection vector
# f = function. objective function to be optimised
# df = function. gradient of objective
# X = matrix. dataset being clustered
# params = list. parameters used in f and df
# getb = function. determines the optimal hyperplane orthogonal to a vector v (the value of b in the description of a hyperplane in the paper)
# verbosity = integer. determines the verbosity level of the optimisation. see paper for details
# labels = vector. only used if verbosity > 0. plots of points with different labels are given different colours. the labels are
#           not used to aid the optimisation, only for illustrative purposes
# method = character. describes the objective being used. one of c('MCDC', 'MDH', 'NCutH')
# maxit = integer. maximum number of iterations in optimisation.
# ftol = double. realtive tolerance for termination of optimisation

## output is the optimal projection vector

ppclust.optim <- function(v0, f, df, X, params, getb, verbosity, labels, method, maxit, ftol){
  if(verbosity==0){
    if(method=='MCDC') optim(v0, f, df, X, params, method='BFGS', control = list(fnscale = -1e-4, maxit = maxit, reltol = ftol))
    else optim(v0, f, df, X, params, method='BFGS', control = list(maxit = maxit, reltol = ftol))
  }
  else{
    iter = 0
    if(verbosity==3){
      dirname <- paste(method, ' plots.', format(Sys.time(), "%m_%d_%y_%Ih%Mm%Ss"), sep = '')
      if(method=='MDH') dirname <- paste(dirname, '. alpha=', params$alpha, sep = '')
      dir.create(dirname)
      count <- 0
    }
    if(ncol(X)>2) v2 <- rARPACK::eigs_sym(cov(X), 2)$vectors[,2]
    else v2 <- eigen(cov(X))$vectors[,2]
    v0 <- list(par = v0)
    for(i in 1:30){
      v2 <- v2-v2%*%v0$par*v0$par
      xp <- X%*%cbind(v0$par, v2)
      if(method=='MDH') den <- density(xp[,1], bw = params$h)
      else den <- density(xp[,1])
      if(verbosity==3){
        count <- count + 1
        pdf(paste('~/', dirname, '/', method, ' plot-', count, '.pdf', sep = ''))
      }
      if(is.null(labels)) plot(xp, col = rgb(.5, .5, .5), xlab = '', ylab = '', main = '')
      else plot(xp, col = labels, xlab = '', ylab = '', main = '')
      lines(den$x, min(xp[,2])+.5*den$y/max(den$y)*(max(xp[,2])-min(xp[,2])), lwd = 2)
      if(method=='MDH'){
        s <- sd(xp[,1])
        pen <- den$y + params$C*((den$x<(-params$alpha*s))*(-params$alpha*s-den$x)^2 + (den$x>(params$alpha*s))*(den$x-params$alpha*s)^2)
        lines(den$x, min(xp[,2])+.5*pen/max(den$y)*(max(xp[,2])-min(xp[,2])), lty = 2)
      }
      bcrit <- getb(v0$par, X, params)
      abline(v=bcrit, lwd = 2, col = 2)
      if(verbosity>1){
        SR <- ifelse(is.null(labels), NA, round(success_ratio(xp[,1]<bcrit, labels), 3))
        if(method=='MDH'){
          reldep <- round(md_reldepth(v0$par, X, params), 3)
          denval <- round(f_md(v0$par, X, params), 3)
          title(main = paste('alpha = ', params$alpha, '. density = ', denval, '. relative depth = ', reldep, '. success ratio = ', SR, sep = ''))
        }
        else if(method=='NCutH'){
          NC <- round(f_ncut(v0$par, X, params), 3)
          title(main = paste('normalised cut = ', NC, '. success ratio = ', SR, sep = ''))
        }
        else{
          VR <- round(f_mc(v0$par, X, params), 3)
          title(main = paste('variance ratio = ', VR, '. success ratio = ', SR, sep = ''))
        }
      }
      if(verbosity==3) dev.off()
      if(method=='MCDC') v0 <- optim(v0$par, f, df, X, params, method = 'BFGS', control = list(fnscale = -1e-4, maxit=3, reltol = ftol))
      else v0 <- optim(v0$par, f, df, X, params, method = 'BFGS', control = list(maxit=3, reltol = ftol))
      Sys.sleep(.05)
      v0$par <- v0$par/norm_vec(v0$par)
      iter <- iter + v0$counts[2]
      if(v0$counts[2]==1 || i==30 || iter > maxit) break
    }
    v0
  }
}


back to top

Software Heritage — Copyright (C) 2015–2026, 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— Content policy— Contact— JavaScript license information— Web API