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/tansey/smoothfdr
05 April 2024, 22:39:35 UTC
  • Code
  • Branches (1)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/master
    No releases to show
  • 8306d99
  • /
  • R
  • /
  • ADMM_cholcache.R
Raw File Download Save again
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:aa69199d149d9899c29deef8fd6ccbced148daa4
origin badgedirectory badge
swh:1:dir:601afeb022bee3e7471f0b8dcff84a62082afdb4
origin badgerevision badge
swh:1:rev:c5b693d0a66e83c9387433b33c0eab481bd4a763
origin badgesnapshot badge
swh:1:snp:7bb11892490e1dc1b1ff3be1d93f489dadb3e857

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: c5b693d0a66e83c9387433b33c0eab481bd4a763 authored by Wesley Tansey on 08 May 2020, 15:42:20 UTC
Fixed bug in easy that created too large a support for the alternative distribution
Tip revision: c5b693d
ADMM_cholcache.R
# Fits the weighted fused lasso by ADMM where D is the discrete difference operator on a graph
# D is a sparse matrix of class 'dgCMatrix' [package "Matrix"]

fit_graphfusedlasso_cholcache = function(y, lambda, D, chol_factor = NULL, weights=NULL, initial_values = NULL, iter_max = 10000, rel_tol = 1e-4, alpha=1.0, inflate=2, adaptive=FALSE) {
	require(Matrix)
	
	n = length(y)
	m = nrow(D)
	a = 2*lambda # step-size parameter
		
	if(missing(weights)) {
		weights = rep(1, n)
	}
	
	# Check if we need a Cholesky decomp of system involving graph Laplacian
	if(missing(chol_factor)) {
		L = Matrix::crossprod(D)
		chol_factor = Matrix::Cholesky(L + Matrix::Diagonal(n))
	}

	# Initialize primal and dual variables from warm start
	if(missing(initial_values)) {
		x = rep(0, n) # likelihood term
		z = rep(0, n) # slack variable for likelihood
		r = rep(0, m) # penalty term
		s = rep(0, m) # slack variable for penalty
		u_dual = rep(0,n) # scaled dual variable for constraint x = z
		t_dual = rep(0,m) # scaled dual variable for constraint r = s
	} else {
		x = initial_values$x
		z = initial_values$z
		r = initial_values$r
		s = initial_values$s
		t_dual = initial_values$t_dual
		u_dual = initial_values$u_dual
	}
	
	primal_trace = NULL
	dual_trace = NULL
	converged = FALSE
	counter = 0
	while(!converged & counter < iter_max) {
		
		# Update x
		x = {weights * y + a*(z - u_dual)}/{weights + a}
		x_accel = alpha*x + (1-alpha)*z
		
		# Update constraint term r
		arg = s - t_dual
		if(adaptive) {
			local_lambda = 1/{1+(lambda)*abs(arg)}  # Minimax-concave penalty instead?
		} else {
			local_lambda = lambda
		}
		r = softthresh(arg, local_lambda/a)
		r_accel = alpha*r + (1-alpha)*s
		
		# Projection to constraint set
		arg = x_accel + u_dual + Matrix::crossprod(D, r_accel + t_dual)
		z_new = drop(Matrix::solve(chol_factor, arg))
		s_new = as.numeric(D %*% z_new)
		dual_residual_u = a*(z_new - z)
		dual_residual_t = a*(s_new - s)
		z = z_new
		s = s_new
		
		# Dual update
		primal_residual_x = x_accel - z
		primal_residual_r = r_accel - s
		u_dual = u_dual + primal_residual_x
		t_dual = t_dual + primal_residual_r
		
		# Check convergence
		primal_resnorm = sqrt(mean(c(primal_residual_x, primal_residual_r)^2))
		dual_resnorm = sqrt(mean(c(dual_residual_u, dual_residual_t)^2))
		if(dual_resnorm < rel_tol && primal_resnorm < rel_tol) {
			converged=TRUE
		}
		primal_trace = c(primal_trace, primal_resnorm)
		dual_trace = c(dual_trace, dual_resnorm)
		counter = counter+1
		
		# Update step-size parameter based on norm of primal and dual residuals
		if(primal_resnorm > 5*dual_resnorm) {
			a = inflate*a
			u_dual = u_dual/inflate
			t_dual = t_dual/inflate
		} else if(dual_resnorm > 5*primal_resnorm) {
			a = a/inflate
			u_dual = inflate*u_dual
			t_dual = inflate*t_dual
		}
	}
	list(x=x, r=r, z=z, s=s, u_dual=u_dual, t_dual=t_dual,
		primal_trace = primal_trace, dual_trace=dual_trace, counter=counter)
}

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