编程与数学

1. 内积与均值

  • iaibi :就是内积
  • 1ni :就是均值

2. position & walker

注意理解这两个英文单词所对应的数学含义:

多元高斯概率密度函数:

p(x⃗ )exp(12(x⃗ μ⃗ )TΣ1(x⃗ μ⃗ ))

def lnprob(x, mu, icov):
    diff = x - mu
    return -np.dot(diff, icov.dot(diff))/2

It is important that the first argument of the probability function x is the position of a single walker (a N-dimensional numpy array).

3. 取模运算

x%y==0

取模运算表达一种周期或者频率(frequency)的意义,

if iter % freq == 0:
    ...

4. 阈值与双重 if

比如,如果这次的改进较上次优化了 %5 以上,则:

best_valid_loss = np.inf
improvement_thresh = 0.95
patience, patience_inc = 5000, 2
for iter in range(n_iters):
    ... 
    if this_valid_loss < best_valid_loss:
        if this_valid_loss < best_valid_loss * improvement_thresh:
            patience = max(patience, iter*patience_inc)
        best_valid_loss = this_valid_loss

5. e=limn(1+1n)n 的收敛性

>>>for n in (2, 4, 10, 50, 100, 1000, 100000):
>>>     print(n, (1./n)**n)
2 2.25
4 2.44140625
10 2.5937424601000023
50 2.691588029073608
100 2.7048138294215285
1000 2.7169239322355936
100000 2.7182682371922975

6. 随机性的实现——各种分布的抽样

二项分布生成掩码,实现对原始数据随机的选择(屏蔽)。

# denoising autoencoder
def get_corrupted_input(self, input, corruption_level):
    mask = self.theano_rng.binomial(n=1,
            p=1-corruption_level,
            size=input.shape, 
            dtype=theano.config.floatX)
    return mask*input
# dropout
def dropout_layer(layer, p_dropout):
    mask = theano_rng.binomial(n=1,
            p=1-p_dropout,
            size=layer.shape,
            dtype=theano.config.floatX)
    return layer*mask

正太分布或者均匀分布(参数由相关定理保证)实现对权值的初始化:

if not W:
    init_W = numpy.asarray(
            numpy_rng.uniform(
                low= -4*numpy.sqrt(6./(n_in+n_out),
                high=4*numpy.sqrt(6./(n_in+n_out)),
                size=(n_in, n_out))
            ),
            dtype=theano.config.floatX
        )
    W = theano.shared(value=init_W, name='W', borrow=True)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

五道口纳什

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值