Skip to content

Instantly share code, notes, and snippets.

@bbbales2
Created May 23, 2017 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbbales2/3e2eae3b4b5f52e71225a8be60c289f2 to your computer and use it in GitHub Desktop.
Save bbbales2/3e2eae3b4b5f52e71225a8be60c289f2 to your computer and use it in GitHub Desktop.
Comparison of lots of data vs. not much data for a bad fit
#%%
import matplotlib.pyplot as plt
import pystan
import numpy
model_code = """
data {
int<lower=1> N; // Number of single samples
vector[N] t;
vector[N] y;
}
parameters {
real<lower=0.0> sigma;
real a;
real b;
}
model {
y ~ normal(a * t + b, sigma);
}
"""
sm = pystan.StanModel(model_code = model_code)
#%%
N = 100
x = numpy.linspace(0, 10.0, N)
y = x*x + 5.0 * numpy.random.randn(N)
plt.plot(y)
plt.show()
print "Not much data"
print sm.sampling({'N' : N, 't' : x, 'y' : y})
N = 10000
x = numpy.linspace(0, 10.0, N)
y = x*x + 5.0 * numpy.random.randn(N)
plt.plot(y)
plt.show()
print "Lots of data"
print sm.sampling({'N' : N, 't' : x, 'y' : y})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment