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

Revision bc33a5cb241a7b016597a94077631f761801e04e authored by Wesley Tansey on 22 November 2014, 18:07:00 UTC, committed by Wesley Tansey on 22 November 2014, 18:07:00 UTC
Initial commit of python implementation
1 parent 660f66e
  • Files
  • Changes
  • 078548c
  • /
  • smoothfdr
  • /
  • signal_distributions.py
Raw File Download

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.

  • revision
  • directory
  • content
revision badge
swh:1:rev:bc33a5cb241a7b016597a94077631f761801e04e
directory badge
swh:1:dir:3c3e9c3d5060ebbd60155e3f716573b53cc24433
content badge
swh:1:cnt:f066687b61584ee9958d4bac86befb6e49b95f8b

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.

  • revision
  • directory
  • content
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 ...
signal_distributions.py
import matplotlib
matplotlib.use('Agg')
from matplotlib import cm, colors
import matplotlib.pyplot as plt
import numpy as np
from scipy.stats import norm

def alt1_pdf(x):
    return 0.48 * norm.pdf(x, -2, np.sqrt(1)) + 0.04 * norm.pdf(x, 0, np.sqrt(16)) + 0.48 * norm.pdf(x, 2, np.sqrt(1))

def alt2_pdf(x):
    return 0.4 * norm.pdf(x, -1.25, np.sqrt(2)) + 0.2 * norm.pdf(x, 0, np.sqrt(4)) + 0.4 * norm.pdf(x, 1.25, np.sqrt(2))

def alt3_pdf(x):
    return 0.3 * norm.pdf(x, 0, np.sqrt(0.1)) + 0.4 * norm.pdf(x, 0, np.sqrt(1)) + 0.3 * norm.pdf(x, 0, np.sqrt(9))

def alt4_pdf(x):
    return 0.2 * norm.pdf(x, -3, np.sqrt(0.01)) + 0.3 * norm.pdf(x, -1.5, np.sqrt(0.01)) + 0.3 * norm.pdf(x, 1.5, np.sqrt(0.01)) + 0.2 * norm.pdf(x, 3, np.sqrt(0.01))

def alt1_noisy_pdf(x):
    return 0.48 * norm.pdf(x, -2, np.sqrt(1+1)) + 0.04 * norm.pdf(x, 0, np.sqrt(16+1)) + 0.48 * norm.pdf(x, 2, np.sqrt(1+1))

def alt2_noisy_pdf(x):
    return 0.4 * norm.pdf(x, -1.25, np.sqrt(2+1)) + 0.2 * norm.pdf(x, 0, np.sqrt(4+1)) + 0.4 * norm.pdf(x, 1.25, np.sqrt(2+1))

def alt3_noisy_pdf(x):
    return 0.3 * norm.pdf(x, 0, np.sqrt(0.1+1)) + 0.4 * norm.pdf(x, 0, np.sqrt(1+1)) + 0.3 * norm.pdf(x, 0, np.sqrt(9+1))

def alt4_noisy_pdf(x):
    return 0.2 * norm.pdf(x, -3, np.sqrt(0.01+1)) + 0.3 * norm.pdf(x, -1.5, np.sqrt(0.01+1)) + 0.3 * norm.pdf(x, 1.5, np.sqrt(0.01+1)) + 0.2 * norm.pdf(x, 3, np.sqrt(0.01+1))


def alt1_sample():
    u = np.random.random()
    if u <= 0.48:
        return np.random.normal(-2, np.sqrt(1))
    elif u <= 0.52:
        return np.random.normal(0, np.sqrt(16))
    return np.random.normal(2, np.sqrt(1))

def alt2_sample():
    u = np.random.random()
    if u <= 0.4:
        return np.random.normal(-1.25, np.sqrt(2))
    elif u <= 0.6:
        return np.random.normal(0, np.sqrt(4))
    return np.random.normal(1.25, np.sqrt(2))

def alt3_sample():
    u = np.random.random()
    if u <= 0.3:
        return np.random.normal(0, np.sqrt(0.1))
    elif u <= 0.7:
        return np.random.normal(0, np.sqrt(1))
    return np.random.normal(0, np.sqrt(9))
    
def alt4_sample():
    u = np.random.random()
    if u <= 0.2:
        return np.random.normal(-3, np.sqrt(0.01))
    elif u <= 0.5:
        return np.random.normal(-1.5, np.sqrt(0.01))
    elif u <= 0.8:
        return np.random.normal(1.5, np.sqrt(0.01))
    return np.random.normal(3, np.sqrt(0.01))
    
def test_pdf(x):
    return norm.pdf(x, 3, 1)

def test_sample():
    return np.random.normal(3, 1)

def plot_alts(filename):
    fig, axarr = plt.subplots(2,2)

    x = np.linspace(-6, 6, 1000)

    # Alt 1
    axarr[0,0].plot(x, pdf_alt1(x))
    axarr[0,0].set_title('Case 1')

    # Alt 2
    axarr[1,0].plot(x, pdf_alt2(x))
    axarr[1,0].set_title('Case 2')

    # Alt 3
    axarr[0,1].plot(x, pdf_alt3(x))
    axarr[0,1].set_title('Case 3')

    # Alt 4
    axarr[1,1].plot(x, pdf_alt4(x))
    axarr[1,1].set_title('Case 4')

    plt.savefig(filename, bbox_inches='tight')

if __name__ == '__main__':
    plot_alts('synthetic_alt_densities.pdf')
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

back to top

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— Content policy— Contact— JavaScript license information— Web API