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]:
(100, 1000)

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]:
(100, 1000)

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]:
(array([  9.65600000e+03,   2.00000000e+02,   7.30000000e+01,
         3.50000000e+01,   1.50000000e+01,   9.00000000e+00,
         4.00000000e+00,   2.00000000e+00,   4.00000000e+00,
         2.00000000e+00]),
 array([  8.53086214e-73,   1.27039250e+00,   2.54078499e+00,
         3.81117749e+00,   5.08156999e+00,   6.35196249e+00,
         7.62235498e+00,   8.89274748e+00,   1.01631400e+01,
         1.14335325e+01,   1.27039250e+01]),
 <a list of 10 Patch objects>)

In [ ]: