forked from LocalGroupAstrostatistics2015/MCMC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_data.py
31 lines (25 loc) · 822 Bytes
/
make_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import division, print_function
import numpy as np
np.random.seed(1234)
m, b = 0.5, 3.0
mn, mx = 0., 5.
# Generate the dataset for the line fit.
x = np.sort(np.random.uniform(mn, mx, 50))
y = m * x + b
yerr = np.random.uniform(0.1, 0.15, len(x))
y += yerr * np.random.randn(len(yerr))
np.savetxt("linear.csv", np.vstack((x, y, yerr)).T, delimiter=",",
header="x,y,z")
# Generate Poisson dataset.
alpha, beta = 500.0, -2.0
mn, mx = 1., 5.
bins = np.linspace(mn, mx, 20)
samps = []
for i in range(len(bins) - 1):
k = alpha * (0.5*(bins[i+1] + bins[i])) ** beta * (bins[i+1] - bins[i])
samps.append(np.random.uniform(bins[i], bins[i+1], np.random.poisson(k)))
x = np.sort(np.concatenate(samps))
print(len(x))
np.savetxt("poisson.csv", x)