Skip to content

Instantly share code, notes, and snippets.

@kayhman
Created September 8, 2020 08:23
Show Gist options
  • Save kayhman/f3dfae2eb222462fe426f1b8f982ac76 to your computer and use it in GitHub Desktop.
Save kayhman/f3dfae2eb222462fe426f1b8f982ac76 to your computer and use it in GitHub Desktop.
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-20, 20, 200)
y = np.abs(x)
alpha = 0.2
y_Q = np.where(x > 0, alpha * x, (alpha - 1) * x)
y_logcosh = np.where(x > 0, alpha * np.log(np.cosh(x)), (1 - alpha) * np.log(np.cosh(x)))
plt.plot(x, y_Q, label=f'Q = 0.2')
plt.plot(x, y_logcosh, label=f'Smooth Q=0.2 regression using log_cosh')
plt.legend(loc='upper left')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment