In [1]:
import IPython
import numpy as np
import pandas as pd
from scipy import sparse
from tsa.science import numpy_ext as npx
from sklearn import metrics, cross_validation
from sklearn import linear_model
from tsa import stdout, stderr
from tsa.lib import tabular, datetime_extra, cache
from tsa.lib.timer import Timer
from tsa.models import Source, Document, create_session
from tsa.science import features, models, timeseries
from tsa.science.corpora import MulticlassCorpus
from tsa.science.plot import plt, figure_path, distinct_styles, ticker
from tsa.science.summarization import metrics_dict, metrics_summary
In [60]:
normals = np.random.normal(0, 1, size=100000).reshape(100, 1000)
In [64]:
true_coefs = np.random.gamma(0.05, 3, 1000)
sampled_coefs = np.array([np.random.normal(coef, 2, size=100) for coef in true_coefs]).T
sampled_coefs.shape
Out[64]:
In [65]:
# the idea is that each row in normals is one run from a 100-iteration
# bootstrap, with 1000 coefficients
# so to show (fake) convergence, we want to see where we end up when taking a running mean from first
# iteration to last, for each coefficient. So we want to end up with a table of cumulative means
# row by row, where each row depends on all the rows above it
# brownian = normals.cumsum(axis=0)
# pd.DataFrame(brownian)
cumulative_coefs_means = npx.mean_accumulate(sampled_coefs, axis=0)
cumulative_coefs_means.shape
Out[65]:
In [67]:
for col in range(100): # len(brownian)
plt.plot(cumulative_coefs_means[:, col])
In [56]:
plt.hist(np.random.gamma(0.05, 3, 10000))
Out[56]:
In [ ]: