Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save firstfu/42840d489c5010089abf5a28ff98c42a to your computer and use it in GitHub Desktop.
Save firstfu/42840d489c5010089abf5a28ff98c42a to your computer and use it in GitHub Desktop.
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