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/kussell-lab/mcorr
23 January 2022, 09:11:33 UTC
  • Code
  • Branches (5)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/2019natmethods
    • refs/heads/2021biorxiv
    • refs/heads/dev
    • refs/heads/master
    • refs/heads/x
    No releases to show
  • 49f3972
  • /
  • mean_var.go
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:12786acc101a7bdeebb369b03fbe9910ad2c0e32
origin badgedirectory badge Iframe embedding
swh:1:dir:49f3972863e4fd2ec7eb3ce02ee39148436165a5
origin badgerevision badge
swh:1:rev:30891abb239f54c493e3d27596a93050022024b4
origin badgesnapshot badge
swh:1:snp:bc0e5aa6513599be660f007d7b46ba12cce5b7e5
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: 30891abb239f54c493e3d27596a93050022024b4 authored by Mingzhi Lin on 23 August 2017, 14:12:22 UTC
add mcorr-recom-genes
Tip revision: 30891ab
mean_var.go
package mcorr

import (
	"math"
)

// MeanVar is for calculate mean and variance in the increment way.
type MeanVar struct {
	N             int     // number of values.
	M1            float64 // first moment.
	Dev           float64
	NDev          float64
	M2            float64 // second moment.
	BiasCorrected bool
}

// NewMeanVar return a new MeanVar.
func NewMeanVar() *MeanVar {
	return &MeanVar{}
}

// Add adds a value.
func (m *MeanVar) Add(v float64) {
	if m.N < 1 {
		m.M1 = 0
		m.M2 = 0
	}

	m.N++
	n0 := m.N
	m.Dev = v - m.M1
	m.NDev = m.Dev / float64(n0)
	m.M1 += m.NDev
	m.M2 += float64(m.N-1) * m.Dev * m.NDev
}

// Mean returns the mean result.
func (m *MeanVar) Mean() float64 {
	return m.M1
}

// Variance returns the variance.
func (m *MeanVar) Variance() float64 {
	if m.N < 2 {
		return math.NaN()
	}

	if m.BiasCorrected {
		return m.M2 / float64(m.N-1)
	}

	return m.M2 / float64(m.N)
}

// Append add another result.
func (m *MeanVar) Append(m2 *MeanVar) {
	if m.N == 0 {
		m.N = m2.N
		m.M1 = m2.M1
		m.Dev = m2.Dev
		m.NDev = m2.NDev
		m.M2 = m2.M2
	} else {
		if m2.N > 0 {
			total1 := m.M1 * float64(m.N)
			total2 := m2.M1 * float64(m2.N)
			newMean := (total1 + total2) / float64(m.N+m2.N)
			delta1 := m.Mean() - newMean
			delta2 := m2.Mean() - newMean
			sm := (m.M2 + m2.M2) + float64(m.N)*delta1*delta1 + float64(m2.N)*delta2*delta2
			m.M1 = newMean
			m.M2 = sm
			m.N = m.N + m2.N
		}
	}
}

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