Created
May 9, 2019 03:27
-
-
Save firstfu/42840d489c5010089abf5a28ff98c42a to your computer and use it in GitHub Desktop.
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 tensorflow as tf | |
import pandas as pd | |
import numpy as np | |
from scipy import stats | |
import itertools | |
import matplotlib.pylab as plt | |
# 白努力分配 | |
size = 10000 | |
p = 0.4 | |
data_bern = stats.bernoulli.rvs(size=size, p=p) | |
plt.hist(data_bern) | |
bernDf = pd.DataFrame({'試驗': data_bern}) | |
print('0的機率:', len(bernDf[bernDf['試驗'] == 0])/size) | |
print('1的機率:', len(bernDf[bernDf['試驗'] == 1])/size) | |
rs = [len(list(v)) for k,v in itertools.groupby(data_bern) if k == 1] | |
print('最大連續次數:', max(rs)) | |
print('機率:', max(rs)/size) | |
plt.hist(rs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment