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 as np | |
from scipy import linalg | |
def lse(A, b, B, d, cond=None): | |
""" | |
Equality-contrained least squares. | |
The following algorithm minimizes ||Ax - b|| subject to the | |
constrain Bx = d. | |
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
class AlwaysFive: | |
def __iter__(self): | |
while True: | |
yield 5 | |
a = AlwaysFive() | |
it = iter(a) |
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
# ==================================================================================== | |
# = Koala sightings example from Link and Barker 2009. Original WinBUGS model below. = | |
# ==================================================================================== | |
import numpy as np | |
from numpy.ma import masked_array | |
from pymc import * | |
# Prior model weights, derived from Bayes factors | |
pi = (0.016656, 0.052853, 0.045682, 0.087367, 0.091975, 0.221741, 0.19819, |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
''' | |
Gibbs sampler for function: | |
f(x,y) = x x^2 \exp(-xy^2 - y^2 + 2y - 4x) | |
using conditional distributions: | |
x|y \sim Gamma(3, y^2 +4) | |
y|x \sim Normal(\frac{1}{1+x}, \frac{1}{2(1+x)}) | |
''' |
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
""" | |
A random walk Metropolis algorithm with tuning, implemented for a linear model that | |
predicts price as a function of age. | |
""" | |
import numpy as np | |
from scipy.stats import distributions | |
rnorm = np.random.normal |
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
from pymc import * | |
from numpy import array, resize, diag, exp, zeros, prod, concatenate | |
import pdb | |
# Data | |
Releases = array([12,12,10,14,17,21,9,30,25,41,45,79,97,80,62,80,74,74,46,45]) | |
NRCperiods = len(Releases) | |
recdata = resize(( | |
8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4, | |
0,7,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4, |
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
''' | |
Gibbs sampler for function: | |
f(x,y) = x x^2 \exp(-xy^2 - y^2 + 2y - 4x) | |
using conditional distributions: | |
x|y \sim Gamma(3, y^2 +4) | |
y|x \sim Normal(\frac{1}{1+x}, \frac{1}{2(1+x)}) | |
''' |
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
species,eggs,parasite,lat,lon | |
WOTH, 2, 0, -82.32, 25.10 | |
TOSO, 2, 0, -80.56, 26.66 |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.