dim = int(random.random() * Dims) data_mean = np.mean(measurements[dim, :]) # init 100 particles N = 50 P = [] Estimation = [] for i in range(N): x = particles() x.set(random.gauss(data_mean, 0.2), 0.005, 5.0, 1) P.append(x) # gradient g_1 = gradient_1(measurements[dim, :]) g_2 = gradient_2(measurements[dim, :]) g_1_bk = gradient_1_bk(measurements[dim, :]) g_2_bk = gradient_2_bk(measurements[dim, :]) # run motion model for t in range(Length): measurement = measurements[dim, t] for n in range(N): # P[n].motion(motionFCN, v=g_1[t], a=g_2[t], t=1) P[n].motion(motionFCN, v=g_1_bk[t], a=0, t=1) # P[n].motion(motionFCN, v=g_1_bk[t], a=g_2_bk[t], t=1) # evaluation and store
# init 100 particles N = 100 P = [] Estimation = [] for i in range(N): x = particles() x.set(random.gauss(data_mean, 1.0), 0.005, 5.0, 1) P.append(x) g_1_bk = gradient_1_bk(data[dim, :]) g_1_bk = average_gradient(g_1_bk, 3) g_1 = gradient_1(data[dim, :]) g_2 = gradient_2(data[dim, :]) g_2_bk = gradient_2_bk(data[dim, :]) g_1_random = [random.gauss(0.0, 0.1) * .5 for x in range(Length)] print(np.min(g_1_random), np.max(g_1_random)) print(np.min(g_1_bk), np.max(g_1_bk)) # motion with both velocity and acceleration P1 = copy.deepcopy(P) # prog = propagation(P1, motionFCN, data[dim, :], g_1_bk, g_2_bk) prog = propagation(P1, motionFCN, data[dim, :], g_1_bk, None) for t_idx in range(len(data[dim, :])): prog.pred(t_idx)
from matplotlib import pyplot as plt # prepare data & choose arbitary dimension data_path = os.path.join(data_config['root_dir'], data_config['data_name']) data = normalize(readMat(data_path)) Dims, Length = data.shape # Convert acceleration to covariance and weighted g_1 = [] g_2 = [] # init gradient for all data, all channel for k in range(8): g_1.append(gradient_1(data[k, :])) g_2.append(gradient_2(data[k, :])) # convert list to array g_1 = np.asarray(g_1) g_2 = np.asarray(g_2) g_2_update = copy.deepcopy(g_2) # update gradient for k in range(Length): g_2_update[:, k] = update_acceleration(g_2[:, k], covariance_matrix) print("FInish updateing acceleration") print("Total Dimension is {}".format(Dims))