Exemple #1
0
def update_batch_cd1(para, data_v, layer=1):
    eta = para['eta']
    max_bsize = data_v.shape[0]
    if layer == 0: # input layer, otherwise they are binary
        data_h, gibbs_v, gibbs_h = sampling_nb(para, data_v)
    else:
        data_h, gibbs_v, gibbs_h = sampling(para, data_v)
    
    pos_delta_w = np.zeros((para['v_num'], para['h_num']))
    neg_delta_w = np.zeros((para['v_num'], para['h_num']))
    for i in range(max_bsize):
        pos_delta_w += matu.matrix_times(data_v[i], data_h[i])
        neg_delta_w += matu.matrix_times(gibbs_v[i], gibbs_h[i])    
    delta_w_pos = eta * pos_delta_w/np.float(max_bsize)
    delta_w_neg = eta * neg_delta_w/np.float(max_bsize)
    para['w'] += delta_w_pos
    para['w'] -= delta_w_neg
    delta_a = data_v - gibbs_v
    delta_b = data_h - gibbs_h
    delta_a = eta * np.average(delta_a,0)
    delta_b = eta * np.average(delta_b,0)
    para['a'] += delta_a
    para['b'] += delta_b
    #print delta_w_pos.max(), delta_w_neg.max()
    return para
Exemple #2
0
def update_batch_cd1(para, data_v, layer=1):
    eta = para['eta']
    max_bsize = data_v.shape[0]
    if layer == 0:  # input layer, otherwise they are binary
        data_h, gibbs_v, gibbs_h = sampling_nb(para, data_v)
    else:
        data_h, gibbs_v, gibbs_h = sampling(para, data_v)

    pos_delta_w = np.zeros((para['v_num'], para['h_num']))
    neg_delta_w = np.zeros((para['v_num'], para['h_num']))
    for i in range(max_bsize):
        pos_delta_w += matu.matrix_times(data_v[i], data_h[i])
        neg_delta_w += matu.matrix_times(gibbs_v[i], gibbs_h[i])
    delta_w_pos = eta * pos_delta_w / np.float(max_bsize)
    delta_w_neg = eta * neg_delta_w / np.float(max_bsize)
    para['w'] += delta_w_pos
    para['w'] -= delta_w_neg
    delta_a = data_v - gibbs_v
    delta_b = data_h - gibbs_h
    delta_a = eta * np.average(delta_a, 0)
    delta_b = eta * np.average(delta_b, 0)
    para['a'] += delta_a
    para['b'] += delta_b
    #print delta_w_pos.max(), delta_w_neg.max()
    return para
Exemple #3
0
def update_batch_cd1(para, data_v):
    eta = para['eta']
    max_bsize = data_v.shape[0]
    data_h, gibbs_v, gibbs_h = sampling(para, data_v)

    pos_delta_w = np.zeros((para['v_num'], para['h_num']))
    neg_delta_w = np.zeros((para['v_num'], para['h_num']))
    for i in range(max_bsize):
        pos_delta_w += matu.matrix_times(data_v[i], data_h[i])
        neg_delta_w += matu.matrix_times(gibbs_v[i], gibbs_h[i])
    delta_w_pos = eta * pos_delta_w / np.float(max_bsize)
    delta_w_neg = eta * neg_delta_w / np.float(max_bsize)
    para['w'] += delta_w_pos
    para['w'] -= delta_w_neg
    #print delta_w_pos.max(), delta_w_neg.max()
    return para
Exemple #4
0
def update_batch_cd1(para, data_v):
    eta = para['eta']
    max_bsize = data_v.shape[0]
    data_h, gibbs_v, gibbs_h = sampling(para, data_v)
    
    pos_delta_w = np.zeros((para['v_num'], para['h_num']))
    neg_delta_w = np.zeros((para['v_num'], para['h_num']))
    for i in range(max_bsize):
        pos_delta_w += matu.matrix_times(data_v[i], data_h[i])
        neg_delta_w += matu.matrix_times(gibbs_v[i], gibbs_h[i])    
    delta_w_pos = eta * pos_delta_w/np.float(max_bsize)
    delta_w_neg = eta * neg_delta_w/np.float(max_bsize)
    para['w'] += delta_w_pos
    para['w'] -= delta_w_neg
    #print delta_w_pos.max(), delta_w_neg.max()
    return para
Exemple #5
0
def update_unbound_w(w_up, w_down, d_vis):
    bsize = d_vis.shape[0]
    delta_w = 0
    d_hid = ReLU(d_vis, w_up)
    g_vis = ReLU(d_hid, w_down)
    for ib in range(bsize):
        delta_w += matu.matrix_times(d_hid[ib], d_vis[ib] - g_vis[ib])
    delta_w /= np.float(bsize)
    return delta_w, d_hid
Exemple #6
0
def update_unbound_w(w_up, w_down, d_vis):
    bsize = d_vis.shape[0]
    delta_w = 0
    d_hid = ReLU(d_vis, w_up)
    g_vis = ReLU(d_hid, w_down)
    for ib in range(bsize):
        delta_w += matu.matrix_times(d_hid[ib], d_vis[ib]-g_vis[ib])
    delta_w /= np.float(bsize)
    return delta_w, d_hid
Exemple #7
0
def update_unbound_w(w_up, w_down, b_in, b_out, d_vis, layer=1):
    bsize = d_vis.shape[0]
    delta_w = 0
    d_hid = sigmoid_sampling(d_vis, w_up, b_out)
    if layer == 0:
        g_vis = sigmoid(d_hid, w_down, b_in)
    else:
        g_vis = sigmoid_sampling(d_hid, w_down, b_in)
    
    for ib in range(bsize):
        delta_w += matu.matrix_times(d_hid[ib], d_vis[ib]-g_vis[ib])
    delta_w = delta_w/np.float(bsize)
    delta_b = np.average(d_vis[ib]-g_vis[ib], axis=0)
    return delta_w, delta_b, d_hid
Exemple #8
0
def update_unbound_w(w_up, w_down, b_in, b_out, d_vis, layer=1):
    bsize = d_vis.shape[0]
    delta_w = 0
    d_hid = sigmoid_sampling(d_vis, w_up, b_out)
    if layer == 0:
        g_vis = sigmoid(d_hid, w_down, b_in)
    else:
        g_vis = sigmoid_sampling(d_hid, w_down, b_in)

    for ib in range(bsize):
        delta_w += matu.matrix_times(d_hid[ib], d_vis[ib] - g_vis[ib])
    delta_w = delta_w / np.float(bsize)
    delta_b = np.average(d_vis[ib] - g_vis[ib], axis=0)
    return delta_w, delta_b, d_hid