Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
import pymc
from pymc import gp
from pymc.gp.cov_funs import matern,gaussian
from pylab import *
# Load some data generated from a GP with mean=0, scale=1, amp=1
xdata,ydata = loadtxt('train.txt', unpack=1)
@apatil
apatil / ballast.py
Last active September 24, 2015 03:57
Figures out the mass of your narrowboat and how much ballast you need to add to achieve a desired result.
from __future__ import division
import numpy as np
# A boat is a dict with keys
# mass, center_of_mass, cm_depth, front_depth, back_depth, pitch, length, width
# units are radians (angles), meters (depths and lengths), tons (mass)
# Boats are idealized as rectangular prisms
water_density = 1
import numpy as np
import pylab as pl
import pymc as pm
Tau_test = np.matrix([[ 209.47883244, 10.88057915, 13.80581557],
[ 10.88057915, 213.58694978, 11.18453854],
[ 13.80581557, 11.18453854, 209.89396417]])
C_test = Tau_test.I
# Illustrates why log-sums are better than direct sums for probability integrals
# when probabilities are initially computed on the log scale
import pymc
import numpy
lp_big = numpy.random.normal(loc=0,scale=2,size=1000)
print numpy.log(numpy.mean(numpy.exp(lp_big)))
print pymc.flib.logsum(lp_big)-numpy.log(len(lp_big))