编程与数学

来源:互联网 发布:手机隐藏录像软件 编辑:程序博客网 时间:2024/06/10 05:20

取模运算

x%y==0

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

if iter % freq == 0:    ...

阈值与双重 if

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

best_valid_loss = np.infimprovement_thresh = 0.95patience, patience_inc = 5000, 2for 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

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

>>>for n in (2, 4, 10, 50, 100, 1000, 100000):>>>     print(n, (1./n)**n)2 2.254 2.4414062510 2.593742460100002350 2.691588029073608100 2.70481382942152851000 2.7169239322355936100000 2.7182682371922975

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

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

# denoising autoencoderdef 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# dropoutdef 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)
0 0
原创粉丝点击