In [1]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_context("talk")
sns.set_style("whitegrid")
%matplotlib inline
In [2]:
def sigmoid(t):
    return 1. / (1. + np.exp(-t))
In [3]:
theta = np.linspace(-5,5, 100)
plt.plot(theta, np.log(sigmoid(theta)))
plt.xlabel(r"$\theta$")
plt.ylabel(r"$\log(\sigma(\theta))$");
plt.savefig("logsigma.pdf", bbox_inches='tight')
In [4]:
plt.plot(theta, np.log(sigmoid(-theta)))
plt.xlabel(r"$\theta$")
plt.ylabel(r"$\log(\sigma(-\theta))$");
plt.savefig("logsigmaneg.pdf", bbox_inches='tight')
In [5]:
plt.plot(theta, -np.log(sigmoid(-theta)))
plt.xlabel(r"$\theta$")
plt.ylabel(r"$-\log(\sigma(-\theta))$");
plt.savefig("neglogsigmaneg.pdf", bbox_inches='tight')
In [6]:
plt.plot(theta, -np.log(sigmoid(theta)))
# plt.plot(theta, -theta, 'k')
plt.xlabel(r"$\theta$")
plt.ylabel(r"$-\log(\sigma(\theta))$");
plt.savefig("neglogsigma.pdf", bbox_inches='tight')
In [7]:
plt.plot(theta,theta)
plt.xlabel(r"$\theta$")
plt.ylabel(r"$\theta$");
plt.savefig("theta.pdf", bbox_inches='tight')
In [8]:
!open .
In [9]:
plt.plot(theta, theta - np.log(sigmoid(theta)))
plt.xlabel(r"$\theta$")
plt.ylabel(r"$\theta - \log(\sigma(\theta))$");
plt.savefig("obj1.pdf", bbox_inches='tight')
In [10]:
plt.plot(theta, 0 - np.log(sigmoid(-theta)))
plt.xlabel(r"$\theta$")
plt.ylabel(r"$0 - \log(\sigma(-\theta))$");
plt.savefig("obj2.pdf", bbox_inches='tight')
In [13]:
data = [(-1,1), (1,0)]
loss = np.array([np.mean([-y *x * t - np.log(sigmoid(- x * t)) for (x,y) in data]) for t in theta])
plt.plot(theta, loss)
plt.xlabel(r"$\theta$")
plt.ylabel(r"$L(\theta)$");
plt.savefig('totalklloss.pdf', bbox_inches='tight')
In [17]:
data = [(-1,1), (1,0)]
loss = np.array([np.mean([-y *x * t - np.log(sigmoid(- x * t))   for (x,y) in data]) for t in theta])
plt.plot(theta, loss)
plt.xlabel(r"$\theta$")
plt.ylabel(r"$L(\theta)$");
plt.savefig('totalklloss.pdf', bbox_inches='tight')
In [19]:
data = [(-1,1), (1,0)]
loss = np.array([np.mean([-y *x * t - np.log(sigmoid(- x * t)) + 0.1 *t*t for (x,y) in data]) for t in theta])
plt.plot(theta, loss)
plt.xlabel(r"$\theta$")
plt.ylabel(r"$L(\theta) + 0.1 \theta^2$");
plt.savefig('totalklloss_reg.pdf', bbox_inches='tight')