Created
May 23, 2017 15:32
-
-
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
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 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