Example #1
0
# Define block partition
blkLen = 25
groupStartLoc = np.arange(0, N, blkLen)

# Run BSBL-BO which exploits the intra-block correlation
# Note: The ECG data is non-sparse. To reconstruct non-sparse signals, you
# need to set the input argument 'prune_gamma' to any non-positive values
# (0, -1, -10, etc), namely turning off this pruning mechanism in SBL. But
# when you reconstruct sparse signals, you can use the default value (1e-2).
#
clf = bsbl.bo(
    verbose=1,
    learn_type=1,
    lambda_init=1e-3,
    r_init=0.96,
    prune_gamma=-1,
    epsilon=1e-8,
    max_iters=16,
)
x1 = clf.fit_transform(Phi, y, blk_start_loc=groupStartLoc)
#
mse_bo = 10 * np.log10((lp.norm(x - x1) ** 2) / lp.norm(x) ** 2)
print("BSBL-BO exit on %d loop" % clf.count)

plt.figure()
plt.plot(x, linewidth=3)
plt.plot(x1, "r-")
plt.title("MSE of BO (directly) is " + str(mse_bo) + "dB")
plt.legend({"Original", "Recovered"})
#========================== Method 1 ======================================
#  Reconstruct the ECG data by BSBL-BO directly  
#==========================================================================

# Define block partition
blkLen = 25
groupStartLoc = np.arange(0,N,blkLen);

# Run BSBL-BO which exploits the intra-block correlation
# Note: The ECG data is non-sparse. To reconstruct non-sparse signals, you
# need to set the input argument 'prune_gamma' to any non-positive values
# (0, -1, -10, etc), namely turning off this pruning mechanism in SBL. But
# when you reconstruct sparse signals, you can use the default value (1e-2).
# 
clf = bsbl.bo(verbose=1, learn_type=1, lambda_init=1e-3, r_init=0.96,
              prune_gamma=-1, epsilon=1e-8, max_iters=16)
x1 = clf.fit_transform(Phi, y, blk_start_loc=groupStartLoc)
#
mse_bo = 10*np.log10((lp.norm(x - x1)**2)/lp.norm(x)**2)
print ('BSBL-BO exit on %d loop' % clf.count)

plt.figure()
plt.plot(x,linewidth=3)
plt.plot(x1,'r-')
plt.title('MSE of BO (directly) is '+ str(mse_bo) + 'dB')
plt.legend({'Original', 'Recovered'})

#=========================== Second Method ==============================
# First recover the signal's coefficients in the DCT domain;
# Then recover the signal using the DCT ceofficients and the DCT basis
#=========================================================================
Example #3
0
y = y_clean + noise

# ======================================================================
#            Algorithm Comparison
# ======================================================================
ind = (np.abs(x) > 0).nonzero()[0]

# 1. Benchmark
supt = ind
x_ls = np.dot(lp.pinv(Phi[:, supt]), y)
x0 = np.zeros(N)
x0[supt] = x_ls
mse_bench = (lp.norm(x - x0) / lp.norm(x)) ** 2

# 2. BSBL-BO
clf = bsbl.bo(learn_lambda=1, learn_type=1, lambda_init=1e-3, epsilon=1e-5, max_iters=100, verbose=1)
x1 = clf.fit_transform(Phi, y, blk_start_loc)
mse_bo = (lp.norm(x - x1) / lp.norm(x)) ** 2

# 3. BSBL-FM
clf = bsbl.fm(learn_lambda=1, learn_type=1, lambda_init=1e-3, epsilon=1e-4, max_iters=100, verbose=1)
x2 = clf.fit_transform(Phi, y, blk_start_loc)
mse_fm = (lp.norm(x - x2) / lp.norm(x)) ** 2

# visualize
plt.figure()
plt.plot(x, linewidth=4)
plt.plot(x0, "g-", linewidth=0.5)
plt.plot(x1, "r-", linewidth=2)
plt.plot(x2, "y-", linewidth=2)
plt.xlabel("Samples")
Example #4
0
y = y_clean + noise

#======================================================================
#            Algorithm Comparison
#======================================================================
ind = (np.abs(x)>0).nonzero()[0]

# 1. Benchmark
supt = ind
x_ls = np.dot(lp.pinv(Phi[:,supt]), y)
x0 = np.zeros(N)
x0[supt] = x_ls
mse_bench = (lp.norm(x - x0)/lp.norm(x))**2

# 2. BSBL-BO
clf = bsbl.bo(learn_lambda=1, learn_type=1, lambda_init=1e-3, 
              epsilon=1e-5, max_iters=100, verbose=1)
x1 = clf.fit_transform(Phi, y, blk_start_loc)
mse_bo = (lp.norm(x - x1)/lp.norm(x))**2

# 3. BSBL-FM
clf = bsbl.fm(learn_lambda=1, learn_type=1, lambda_init=1e-3,
              epsilon=1e-4, max_iters=100, verbose=1)
x2 = clf.fit_transform(Phi, y, blk_start_loc)
mse_fm = (lp.norm(x - x2)/lp.norm(x))**2

# visualize
plt.figure()
plt.plot(x, linewidth=4)
plt.plot(x0, 'g-', linewidth=0.5)
plt.plot(x1, 'r-', linewidth=2)
plt.plot(x2, 'y-', linewidth=2)