# LCR and Cost for varying Sigmas [Exercise 911.0]ΒΆ

Out:

/Users/wbr8/homedata/projects/lmlib-branches/reto-doc/examples-teaching/mse/fig-solution/fig-solution-exercise-cr-sigma.py:28: RuntimeWarning: divide by zero encountered in true_divide
cr = np.divide(J1, J0)


import matplotlib.pyplot as plt
import numpy as np
import numpy.matlib
import lmlib as lm
from lmlib.utils.generator import gen_wgn

# --- Generating Test signal ---
K = [10, 100]

J0_0 = 0 # noise-free error
J1_0 = 10 # noise-free error

sigmas = np.arange(0, 1, 0.01)

J0 = [k*sigmas + J0_0 for k in K]
J1 = [k*sigmas + J1_0 for k in K]

cr = np.divide(J1, J0)
lcr = np.log(cr)

# ----------------  Plot  -----------------
fig = plt.figure(figsize=(5,5))

fig.suptitle('LCR vs. noise for K='+str(K) , fontsize=12)

axs.plot(sigmas, J0[0], lw=1.0, c='tab:blue', label='$J_0(y+Y)$')
axs.plot(sigmas, J0[1], lw=1.0, c='tab:blue',   ls='--', label='$J_0(y+Y)$')
axs.plot(sigmas, J1[0], lw=1.0, c='k', label='$J_1(y+Y)$')
axs.plot(sigmas, J1[1], lw=1.0, c='k',   ls='--', label='$J_1(y+Y)$')
axs.set( ylabel='cost')
axs.grid(True)
axs.legend(loc='upper right')

axs = fig.add_subplot(3, 1, (2), sharex=axs)
axs.plot(sigmas, cr[0], label='CR', c='tab:orange')
axs.plot(sigmas, cr[1], label='CR', ls='--', c='tab:orange')
axs.axhline(y=0, c='k', lw=1.0, ls='--')
axs.legend(loc='lower right')
axs.set_ylim([-10, 10])

axs = fig.add_subplot(3, 1, (3), sharex=axs)
axs.plot(sigmas, lcr[0], label='LCR',  c='tab:purple')
axs.plot(sigmas, lcr[1], label='LCR', ls='--', c='tab:purple')
axs.axhline(y=0, c='k', lw=1.0, ls='--')
axs.legend(loc='lower right')
axs.set( xlabel='$\mathrm{sigma}^2$')
axs.set_ylim([-4, 4])