Exemplo n.º 1
0
#Put the W_initial on top of the true W plots
for i in range(N):
    plt.figure(i)
    for j in range(D):
        plt.subplot(D, 1, j + 1)
        plt.plot(W_inital[:, i, j], color='blue')
# plt.show()
S = 1
M = M.T
M = M[None, :, :]
W_inital = np.moveaxis(W_inital, 0, 2)

shifts = shifts[None, :]
true_c = true_c[None, :]

error_initial = substeps.compute_squared_error(W_inital, true_c, shifts, M)
print('error of initial estimate: ' + str(error_initial))

for update in range(10):
    W_updated = substeps.update_W(true_c, M, W_inital, shifts)
    error_updated = substeps.compute_squared_error(W_updated, true_c, shifts,
                                                   M)
    print('error of updated estimate: ' + str(error_updated))
    W_inital = W_updated

#Put the updated W on the plots with initial and true W
for i in range(N):
    plt.figure(i)
    for j in range(D):
        plt.subplot(D, 1, j + 1)
        plt.plot(W_updated[i, j, :], color='purple')
Exemplo n.º 2
0
#Now, we input the M and ORIGINAL W
#AS WELL AS randomly initialized cs and ts (ts small or zero)
#into the coefficent update function to test
#whether the initial cs are updated to get closer to the true cs

S = 1
c = np.random.uniform(c_min, c_max, (S, N))
print('initial c guess:' + str(c))
# delays = np.floor(np.random.uniform(0,5,(S,N))).astype(int)
delays = np.zeros((S, N)).astype(int)
M = M.T
M = M[None, :, :]
W = np.moveaxis(W, 0, 2)

error_updated = np.inf
error_initial = substeps.compute_squared_error(W, c, delays, M)
print('error of initial estimate: ' + str(error_initial))

while abs(error_updated) > 0.05:
    print('true c: ' + str(true_c))
    try:
        updated_c = substeps.update_c(updated_c, M, W, delays)
    except (NameError):
        updated_c = substeps.update_c(c, M, W, delays)
    print('c_est: ' + str(updated_c))

    #Check that the compute_squared_error is working using true cs:

    # print(substeps.compute_squared_error(W,true_c[None,:],delays,M))

    error_updated = substeps.compute_squared_error(W, updated_c, delays, M)
Exemplo n.º 3
0
# M = util.muscle_activity_empirical(T,muscles)

W = substeps.initialize_W(N, D, T)  #size of W is N x D x T

c = substeps.initialize_c(S, N)  #size of c is S x N

error = np.inf

error_threshold = 1e-6

while error > error_threshold:
    last = time.time()
    delays = substeps.update_delay(M, W, c, S)  #size of delays (t) is S x N
    c = substeps.update_c(c, M, W, delays)
    W = substeps.update_W(c, M, W, delays)
    error = substeps.compute_squared_error(W, c, t, M)
    print(time.time() - last)

# class UpdaterObject(object):
# 	def __init__(S,D,M,etc):
# 		self.T = T
# 		self.M = M
# 	def initialize_W(self,):
# 		self.W =

# 		self.c =
# 	def update_c(self):

# 		self.c =

# updaterObject = UpdaterObject(args)
    lines.append(line)

plt.figure(300)
im = plt.imshow(M[0, :, :],
                interpolation='none',
                aspect=T / D,
                cmap='Greys_r',
                vmin=0,
                vmax=amp_max)
pltuls.strip_ticks(ax)
plt.text(0.65, 0.95, 'True M', transform=plt.gcf().transFigure)

error = np.inf

error_threshold = 1e-6
error = substeps.compute_squared_error(W_est, c_est, np.zeros_like(c_est), M)
print('error before starting: ' + str(error))

ims = []
plt.figure(1)
for i in range(N):
    ax = plt.subplot2grid((N, 2), (i, 1))
    im = plt.imshow(W_est[i, :, :],
                    interpolation='none',
                    aspect=T / D,
                    cmap='Greys_r',
                    vmin=0,
                    vmax=amp_max)
    plt.colorbar()
    ims.append(im)
    pltuls.strip_ticks(ax)
Exemplo n.º 5
0
        Theta[i - 1, util.t_shift_to_index(t, T), :, :] = to_fill
        # plt.figure(544)
        # plt.imshow(Theta[i-1,util.t_shift_to_index(t,T),:,:],interpolation='none')
        # raw_input(' ')

# util.test_Theta(Theta)

# error = np.inf

unexp_var_threshold = 1e-5
# R2_diff_threshold = 1e-7
# R2 = np.zeros(2)
SS_tot = substeps.compute_total_sum_squares(M)
print(SS_tot)
SS_res = substeps.compute_squared_error(
    W_est, c_est, np.zeros_like(c_est),
    M)  #*****change this to have actual shifts
print(SS_res)
# R2[1] =  (1. - (SS_res/SS_tot))
R2 = (1. - (SS_res / SS_tot))

# print('R2 before starting: '+str(R2[1]))
print('R2 before starting: ' + str(R2))

ims = []
W_est_axes = []
plt.figure(1)
for i in range(N):
    ax = plt.subplot2grid((N, 2), (i, 1))
    W_est_axes.append(ax)
    im = plt.imshow(W_est[i, :, :],
Exemplo n.º 6
0
W_est = substeps.initialize_W(N,D,T) #size of W is N x D x T
# c_est = substeps.initialize_c(S,N) #size of c is S x N

plt.figure(200)
lines = []
for d in range(D):
    plt.subplot(D,1,d+1)
    plt.ylim([0,2])
    line, = plt.plot(np.sum(W_est*np.moveaxis(true_c[:,:,None],0,2)   ,axis=0)[d,:])
    lines.append(line)

error = np.inf
t = np.zeros_like(true_c).astype(int)

error_threshold = 1e-6
error = substeps.compute_squared_error(W_est,true_c,t,M)
print('error before starting: '+str(error))

ims = []
plt.figure(1)
for i in range(N):
    ax = plt.subplot2grid((N,2),(i,1))
    im = plt.imshow(
        W_est[i,:,:],interpolation='none',
        aspect=T/D,cmap='Greys_r',vmin=0,vmax=1)
    plt.colorbar()
    ims.append(im)
    pltuls.strip_ticks(ax)
plt.show()
# raw_input(' ')
plt.text(0.65,0.95,'Estim. W',transform=plt.gcf().transFigure)