This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy | |
from numpy import log, isnan, isfinite, sin, cos, tan, abs, any, pi | |
import scipy, scipy.stats | |
import pymultinest | |
import json | |
import sys | |
import matplotlib.pyplot as plt | |
numpy.random.seed(1) | |
outputfiles_basename = "mnchains_toy_" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy | |
from numpy import log, log10, sin, cos, tan, arctan, arccos, arcsin, abs, any, pi | |
import sys | |
import matplotlib.pyplot as plt | |
data = numpy.loadtxt(sys.argv[1], | |
dtype=[(colname, 'f') for colname in 'x', 'x_err', 'y', 'y_err', 'cor'], | |
skiprows=1) | |
plt.figure(figsize=(7,7)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# "x" "x_err" "y" "y_err" "cor" | |
10.191 0.125 20.128 0.125 0.731 | |
9.808 0.050 20.286 0.050 0.662 | |
9.700 0.039 20.437 0.039 0.580 | |
9.831 0.065 20.058 0.065 0.720 | |
9.912 0.058 20.194 0.058 0.502 | |
9.861 0.083 19.989 0.083 0.769 | |
9.971 0.060 20.229 0.060 0.563 | |
9.859 0.060 20.164 0.060 0.752 | |
9.720 0.044 20.318 0.044 0.646 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy | |
import matplotlib.pyplot as plt | |
def prob(M): | |
# for M people, compute the probability of having more than 4 with same birthday | |
hits = 0 | |
# number of simulation instances | |
N = 1000 | |
I = numpy.arange(365).reshape((1,-1)) | |
for j in range(N): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def generateTuple(): | |
if numpy.random.uniform() > 0.05: | |
# generate from normal data set, e.g. normal distribution around some values -- here, a line | |
k = 1.16 | |
d = 8.9 | |
x = numpy.random.uniform(6, 12) | |
y = k * (x - 11) + d | |
return numpy.random.norm(x, 1), numpy.random.norm(y, 3) | |
else: | |
# generate from outlier distribution, e.g. uniform distribution over full parameter space |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy | |
from numpy import cos, sin, exp, log, pi, tan, arccos, arcsin, arctan | |
import matplotlib.pyplot as plt | |
# make a quadratic figure | |
plt.figure(figsize=(6, 6)) | |
# generate 400 points between 0 and 1 | |
t = numpy.linspace(0, 1, 40) | |
print 't = ', t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Memoizes a given function, given its code dependencies (loaded modules and | |
additional data files) | |
Example:: | |
import douglasadams | |
def costlyfunction(): | |
# compute answer to the universe and everything | |
return douglasadams.compute_answer() == 42 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy | |
import matplotlib.pyplot as plt | |
import scipy.stats | |
# two gaussian uncertainties with width sigma | |
# at distance delta | |
# what is the probability that they actually have the same value? | |
def compute_bayes(delta, border=5): | |
a = scipy.stats.norm() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import numpy | |
import scipy.stats | |
# http://www.medpagetoday.com/Blogs/TheMethodsMan/52171 | |
def calc_reliability(p, power=0.8, frac_true=0.1): | |
""" | |
Given this p-value, power of the test and fraction of hypotheses that | |
are actually true. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
SYNOPSIS: ./myprog | python console-progress.py | |
example for myprog: | |
#!/bin/bash | |
echo 100 | |
for i in $(seq 1 100) | |
do | |
sleep 1 |
OlderNewer