1

2

3

4

5

6

7

马尔可夫链的蒙特卡洛模拟?

8

9

10

11

可以将异或看成是不考虑进位的加法:0 + 0 = 0, 0 + 1 = 1, 1 + 1 = 0

12

13

14

15

16

17

18

19

20

21

22

http://stats.stackexchange.com/questions/41317/how-to-show-operations-on-two-random-variables-each-bernoulli-are-dependent-bu 这里举了一个例子,设X, Y是互相独立的服从0-1分布的两个随机变量,且P(X=1)=P(Y=1)=0.5,那么X+Y和|X-Y|就是两个不相关,却不独立的两个随机变量。


In [2]:
%pylab inline
import numpy as np
points = np.array([[0,0], [1,1], [1,1], [2, 0]])
plt.scatter(points[:, 0])


Populating the interactive namespace from numpy and matplotlib
Out[2]:
<matplotlib.collections.PathCollection at 0x1084944d0>
23

24

25

26

为什么要除n?

27

对称阵的不同特征值对应的特征向量相互正交,那么也就是说对称阵的单位特征向量组成的矩阵是正交阵。 正交阵:$Q^T * Q = I$,也就是说每一个列向量,自己乘自己,是1,和别人乘,是0。 另外还有对角化的关系 这个感觉和SVD有那么点关联,不太确定。

28

29

期望是一阶原点矩,方差是二阶中心矩。

30

31

32

33

34


In [5]:
import numpy as np

# rv is short for random variable
def cal_stats(rv):
    
#     if not rv:
#         raise ValueError("None")
        
    length = len(rv)
    
    if length == 0:
        raise ValueError("length of 0")
    mean = 0
    variance = 0
    # third order origin moment, 三阶原点矩
    third_order = 0
    two_order = 0
    fourth_order = 0
    for x in rv:
        mean += x
        two_order += x ** 2
        third_order += x ** 3
        fourth_order += x ** 4
    else:
        mean /= length
        two_order /= length
        third_order /= length
        fourth_order /= length
        
    mean = mean
    variance = two_order - mean ** 2
    skewness = (third_order - 3 * mean * variance - mean ** 3) / variance ** 1.5
    kurtosis = fourth_order / variance ** 2 - 3
    return (mean, variance, skewness, kurtosis)

# randn sample from normal distribution.
data = []
data.append(np.random.randn(10000))
data.append(2 *np.random.randn(10000))
data.append([x for x in data[0] if x > -0.5])
data.append(np.random.uniform(0, 4, 10000))

stats = []
for l in data:
    stats.append(cal_stats(l))

template = r'$\mu={0:.2f},\ \sigma={1:.2f},\ skewness={2:.2f},\ kurt={3:.2f}$'
infos = []
for stat in stats:
    infos.append(template.format(*stat))

plt.text(1, 0.38, infos[0], bbox=dict(facecolor='red', alpha=0.25))
plt.text(1, 0.35, infos[1], bbox=dict(facecolor='red', alpha=0.25))
plt.hist(data[0], 50, normed=True, facecolor='r', alpha=0.9)
plt.hist(data[1], 80, normed=True, facecolor='g', alpha=0.8)


Out[5]:
(array([ 0.00051292,  0.00051292,  0.        ,  0.        ,  0.00102584,
         0.00051292,  0.00102584,  0.00153876,  0.00359045,  0.00256461,
         0.00307753,  0.00307753,  0.00307753,  0.00410337,  0.00769382,
         0.00923259,  0.01538765,  0.01795226,  0.01641349,  0.02564608,
         0.03180114,  0.03693036,  0.0451371 ,  0.04462418,  0.08155454,
         0.06770565,  0.08719667,  0.09130005,  0.09283881,  0.11694613,
         0.1210495 ,  0.1400276 ,  0.14772142,  0.15797986,  0.16875121,
         0.15695401,  0.19080684,  0.17695795,  0.1851647 ,  0.19747482,
         0.18875515,  0.20106527,  0.19439729,  0.20003943,  0.18978099,
         0.18413886,  0.16157031,  0.16208323,  0.14977311,  0.13746299,
         0.11745905,  0.11438152,  0.10053264,  0.10258432,  0.08770959,
         0.06462812,  0.05847306,  0.04718879,  0.03693036,  0.04565002,
         0.02564608,  0.02154271,  0.01538765,  0.01282304,  0.01384888,
         0.00923259,  0.00769382,  0.00512922,  0.00410337,  0.00307753,
         0.00410337,  0.00256461,  0.        ,  0.00051292,  0.00051292,
         0.00153876,  0.        ,  0.00051292,  0.        ,  0.00051292]),
 array([-7.87721173, -7.68225016, -7.4872886 , -7.29232703, -7.09736547,
        -6.9024039 , -6.70744233, -6.51248077, -6.3175192 , -6.12255763,
        -5.92759607, -5.7326345 , -5.53767293, -5.34271137, -5.1477498 ,
        -4.95278823, -4.75782667, -4.5628651 , -4.36790354, -4.17294197,
        -3.9779804 , -3.78301884, -3.58805727, -3.3930957 , -3.19813414,
        -3.00317257, -2.808211  , -2.61324944, -2.41828787, -2.2233263 ,
        -2.02836474, -1.83340317, -1.63844161, -1.44348004, -1.24851847,
        -1.05355691, -0.85859534, -0.66363377, -0.46867221, -0.27371064,
        -0.07874907,  0.11621249,  0.31117406,  0.50613563,  0.70109719,
         0.89605876,  1.09102033,  1.28598189,  1.48094346,  1.67590502,
         1.87086659,  2.06582816,  2.26078972,  2.45575129,  2.65071286,
         2.84567442,  3.04063599,  3.23559756,  3.43055912,  3.62552069,
         3.82048226,  4.01544382,  4.21040539,  4.40536695,  4.60032852,
         4.79529009,  4.99025165,  5.18521322,  5.38017479,  5.57513635,
         5.77009792,  5.96505949,  6.16002105,  6.35498262,  6.54994419,
         6.74490575,  6.93986732,  7.13482888,  7.32979045,  7.52475202,
         7.71971358]),
 <a list of 80 Patch objects>)
35

36

37

余弦相似度和皮尔逊相关系数几乎就是一个东西?

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

由贝叶斯公式引出极大似然估计,这一页还是很精华的。 所以极大似然估计的假设就是各个参数取值的先验概率相等,服从$(-\infty, \infty)$上的均匀分布

58

59

60

61

62

63

64

65

分别求偏导的行为很自然,但理由呢? 在对一个变量(x)求偏导的时候,其他的变量(比如y)会出现在其求导的结果中,也就是对其他变量做出了限制。

66

67

这里的5相当于超参数,超参数可以解释成无法通过样本来求得的参数。

68

69

70

在r取某个区间范围内,幂律分布(长尾分布)没有均值和方差(应该是说均值和方差为无穷大吧)。 推荐系统往往会谈到幂律分布?

71


In [ ]: