Skip to content

Instantly share code, notes, and snippets.

@superjax
Created February 26, 2019 14:34
Show Gist options
  • Save superjax/37c92fafec24ec86afe32e644af4e225 to your computer and use it in GitHub Desktop.
Save superjax/37c92fafec24ec86afe32e644af4e225 to your computer and use it in GitHub Desktop.
Plots of several tolerant Loss functions used by ceres
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0.001, 5, 0.001)
def Huber(a, d):
x = np.zeros_like(a)
x[a<d] = 0.5 * a[a<d]**2
x[a>=d] = d * (np.abs(a[a>=d]) - 0.5 * d)
return x
def Cauchy(s):
return np.log(1+s)
def ArcTan(s, a):
return a* np.arctan(s / a)
plt.plot(x, Huber(x, 1), label="huber 1")
plt.plot(x, Huber(x, 2), label="huber 2")
plt.plot(x, Cauchy(x), label="cauchy")
plt.plot(x, ArcTan(x, 1), label="arctan")
plt.plot(x, ArcTan(x, 2), label="arctan2")
plt.plot(x, 0.5*x**2, label="squared")
plt.legend()
plt.ylim(0, 5)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment