Exemple #1
0
train_weights = True

### Get synthetic y's #################
M = 100

y_vec = np.zeros((T, yd, 1))

L = .3
U = .4

Wz_bar_true = Wz_mu_prior  #np.random.uniform(L,U,size = (d,d+ud+1))
Wr_bar_true = Wr_mu_prior  #np.random.uniform(L,U,size = (d,d+ud+1))
Wp_bar_true = Wp_mu_prior  #np.random.uniform(L,U,size = (d,d+ud+1))
Wy_bar_true = Wy_mu_prior  #np.random.uniform(L,U,size = (d,yd+1))

Wzy, Uzy, bzy = update.extract_W_weights(Wz_bar_true, d, ud)
Wry, Ury, bry = update.extract_W_weights(Wr_bar_true, d, ud)
Wpy, Upy, bpy = update.extract_W_weights(Wp_bar_true, d, ud)
Wyy, _, byy = update.extract_W_weights(Wy_bar_true, d, 0)
#Wyy, _, byy = update.extract_W_weights(Wy_mu_prior, d, 0)
'''
Wzy, Uzy, bzy = update.extract_W_weights(Wz_mu_prior, d, ud)
Wry, Ury, bry = update.extract_W_weights(Wr_mu_prior, d, ud)
Wpy, Upy, bpy = update.extract_W_weights(Wp_mu_prior, d, ud)
Wyy, _, byy = update.extract_W_weights(Wy_mu_prior, d, 0)
'''

for i in range(0, M):
    h = h0
    for t in range(0, T):
        z, r, v, h, y = gen.stoch_GRU_step(np.diag(1 / inv_var), h, u[t, :, 0],
Exemple #2
0
plt.title('Gibbs: T={}, T_check={}, N={}, Var={}'.format(
    T,T_check,N,var))
plt.legend()
plt.show()
'''


M=10000

z_vec = np.zeros((M,d))
r_vec = np.zeros((M,d))
v_vec = np.zeros((M,d))
h_vec = np.zeros((M,d))

if train_weights == True:
    Wz, Uz, bz = update.extract_W_weights(Wz_mu_prior, d, ud)
    Wr, Ur, br = update.extract_W_weights(Wr_mu_prior, d, ud)
    Wp, Up, bp = update.extract_W_weights(Wp_mu_prior, d, ud)


for i in range(0,M):
    h = h0
    for t in range(0,T_check):
        z, r, v, h, y = gen.stoch_GRU_step(np.diag(1/inv_var), h, u[t,:,0],
                                       Wz, Uz, bz.reshape(d),
                                       Wr, Ur, br.reshape(d),
                                       Wp, Up, bp.reshape(d), 0, 0)

    z_vec[i,:] = z
    r_vec[i,:] = r
    v_vec[i,:] = v
Exemple #3
0
'''
Wz_bar_true = np.random.uniform(L,U,size = (d,d+ud+1))
Wr_bar_true = np.random.uniform(L,U,size = (d,d+ud+1))
Wp_bar_true = np.random.uniform(L,U,size = (d,d+ud+1))
#Wy_bar_true = np.random.uniform(L,U,size = (d,yd+1))


Wzy, Uzy, bzy = update.extract_W_weights(Wz_bar_true, d, ud)
Wry, Ury, bry = update.extract_W_weights(Wr_bar_true, d, ud)
Wpy, Upy, bpy = update.extract_W_weights(Wp_bar_true, d, ud)
#Wyy, _, byy = update.extract_W_weights(Wy_bar_true, d, 0)
Wyy, _, byy = update.extract_W_weights(Wy_mu_prior, d, 0)
'''


Wzy, Uzy, bzy = update.extract_W_weights(Wz_mu_prior, d, ud)
Wry, Ury, bry = update.extract_W_weights(Wr_mu_prior, d, ud)
Wpy, Upy, bpy = update.extract_W_weights(Wp_mu_prior, d, ud)
Wyy, _, byy = update.extract_W_weights(Wy_mu_prior, d, 0)



for i in range(0,M):
    h = h0
    for t in range(0,T):
        z, r, v, h, y = gen.stoch_GRU_step(np.diag(1/inv_var), h, u[t,:,0],
                                       Wzy, Uzy, bzy.reshape(d),
                                       Wry, Ury, bry.reshape(d),
                                       Wpy, Upy, bpy.reshape(d),
                                           Sigma_y, Wyy, byy.reshape(yd))
        y_vec[t,:,0] += y
Exemple #4
0
print(Er)
print('Ev')
print(Ev)
print('EWz_bar')
print(np.round(EWz_bar, 4))
print('EWr_bar')
print(np.round(EWr_bar, 4))
print('EWp_bar')
print(np.round(EWp_bar, 4))
print('EWy_bar')
print(np.round(EWy_bar, 4))

#Training Predictions

#Mean weights
Wz, Uz, bz = update.extract_W_weights(EWz_bar, d, ud)
Wr, Ur, br = update.extract_W_weights(EWr_bar, d, ud)
Wp, Up, bp = update.extract_W_weights(EWp_bar, d, ud)
Wy, _, by = update.extract_W_weights(EWy_bar, d, 0)

h = h0
train_y = np.zeros((T, yd))

for j in range(0, T):
    z, r, v, h, yt = gen.stoch_GRU_step_mean(h, u[j, :, 0], Wz, Uz,
                                             bz.reshape(d), Wr, Ur,
                                             br.reshape(d), Wp, Up,
                                             bp.reshape(d), Wy, by.reshape(yd))
    train_y[j, :] = yt

plt.plot(y_full.reshape(end), label='true')
Exemple #5
0
#print(seed)
np.random.seed(60808)

T = 3
d = 3
ud = 2
h0 = .3 * np.ones(d)
u = np.random.uniform(-1, 1, size=(T, ud, 1))
var = .01
inv_var = np.ones(d) * 1 / var

#Initialize weights
Sigma_theta = np.ones((d, d + ud + 1)) * (1 / 3)**2
W_mu_prior = np.random.uniform(-.9, .9, size=(d, d + ud + 1))
W_bar = np.random.normal(W_mu_prior, Sigma_theta)
W, U, b = update.extract_W_weights(W_bar, d, ud)

train_weights = True
'''
W = np.random.uniform(-1,1, size=(d,d))
U = np.random.uniform(-1,1, size=(d,ud))
b = np.random.uniform(-1,1, size = (d,1))
'''

#Initialize h
h = np.zeros((T + 1, d, 1))
h[0, :, 0] = h0
for i in range(1, T + 1):
    h[i, :, 0] = np.random.multivariate_normal(h[i - 1, :, 0],
                                               np.diag(1 / inv_var))
Exemple #6
0
#Generate priors

M = N
h_samples = 0
z_samples = 0
r_samples = 0
v_samples = 0
Wz_bar_samples = 0
Wr_bar_samples = 0
Wp_bar_samples = 0

for n in range(0, M):
    if train_weights == True:
        Wz_bar = np.random.normal(Wz_mu_prior, Sigma_theta)
        Wz, Uz, bz = update.extract_W_weights(Wz_bar, d, ud)

        Wr_bar = np.random.normal(Wr_mu_prior, Sigma_theta)
        Wr, Ur, br = update.extract_W_weights(Wr_bar, d, ud)

        Wp_bar = np.random.normal(Wp_mu_prior, Sigma_theta)
        Wp, Up, bp = update.extract_W_weights(Wp_bar, d, ud)

    h = np.zeros((T + 1, d, 1))
    z = np.zeros((T, d, 1))
    r = np.zeros((T, d, 1))
    v = np.zeros((T, d, 1))
    h[0, :, 0] = h0
    pz = expit(Wz @ h0.reshape(d) + Uz @ u[0, :, :].reshape(ud) +
               bz.reshape(d))
    z[0, :, 0] = np.random.binomial(1, pz)