Skip to content

Commit

Permalink
figures
Browse files Browse the repository at this point in the history
  • Loading branch information
murphyk committed Oct 28, 2018
1 parent 8e6d39b commit 20c3069
Show file tree
Hide file tree
Showing 188 changed files with 10,939 additions and 36 deletions.
64 changes: 64 additions & 0 deletions examples/activationFunPlot.py
@@ -0,0 +1,64 @@
#!/usr/bin/env python

# Plots various neural net activation functions.

import matplotlib.pyplot as plt
import numpy as np
import os

folder = "/Users/kpmurphy/github/pyprobml/figures"

e = np.exp(1)
x = np.linspace(-4, 4, 1000)
y = e**x / (e**x + 1)
fig, ax = plt.subplots()
ax.plot(x, y)
plt.title('sigmoid function')
plt.show()
plt.savefig(os.path.join(folder, 'sigmoidPlot.pdf'))

y = np.tanh(x)
fig, ax = plt.subplots()
ax.plot(x, y)
plt.title('tanh function')
plt.show()
plt.savefig(os.path.join(folder, 'tanhPlot.pdf'))

y = np.log(1+np.exp(x))
fig, ax = plt.subplots()
ax.plot(x, y)
plt.title('softplus function')
plt.show()
plt.savefig(os.path.join(folder, 'softplusPlot.pdf'))


y = 1.0*(x>0)
fig, ax = plt.subplots()
ax.plot(x, y)
plt.title('Heaviside function')
plt.show()
plt.savefig(os.path.join(folder, 'heavisidePlot.pdf'))

y = np.maximum(0, x)
fig, ax = plt.subplots()
ax.plot(x, y)
plt.title('ReLU function')
plt.show()
plt.savefig(os.path.join(folder, 'reluPlot.pdf'))

lam = 0.5
y = np.maximum(0, x) + lam*np.minimum(0, x)
fig, ax = plt.subplots()
ax.plot(x, y)
plt.title('Leaky ReLU function')
plt.show()
plt.savefig(os.path.join(folder, 'leakyReluPlot.pdf'))

lam = 0.5
y = np.maximum(0, x) + np.minimum(0, lam*(e**x - 1))
fig, ax = plt.subplots()
ax.plot(x, y)
plt.title('ELU function')
plt.show()
plt.savefig(os.path.join(folder, 'eluPlot.pdf'))

4 changes: 2 additions & 2 deletions examples/ggmLassoDemo.py
Expand Up @@ -36,8 +36,8 @@
if prec[i,j]!=0:
G.add_edges_from([(ProteinNames[i],ProteinNames[j])])

#ttl = 'lambda {}, nedges {}'.format(lam, len(G.edges))
#print(ttl)
ttl = 'lambda {}, nedges {}'.format(lam, len(G.edges))
print(ttl)
#plt.title(ttl)
nx.draw_circular(G, edge_color ='blue', node_color ='yellow', with_labels = True, node_size = 3000)
plt.savefig(os.path.join('figures', 'glassoSachsPython%s.pdf' % lam))
Expand Down
39 changes: 39 additions & 0 deletions examples/glasso.py
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
import numpy as np
from sklearn.covariance import GraphLasso
import matplotlib.pyplot as plt
import networkx as nx
import os

#These column names are from http://www-stat.stanford.edu/~tibs/ElemStatLearn/datasets/sachs.info
ProteinNames = ['praf', 'pmek', 'plcg', 'PIP2', 'PIP3','p44/42', 'pakts473', 'PKA', 'PKC', 'P38', 'pjnk']
NCols = len(ProteinNames)

#Import the data and convert to a numpy array
X = open(os.path.join('data', 'sachsCtsHTF.txt'), 'r').read().split()
X = [float(x) for x in X]
X = np.array(X).reshape(-1,NCols)
X -= X.mean(axis=0).reshape(1,-1)
X /= np.sqrt(1000) #same as http://www-stat.stanford.edu/~tibs/ElemStatLearn/datasets/sachs.info

#Regularization parameters
Lambs = [36, 27, 7, 0]

for lam in Lambs:
GL = GraphLasso(lam)
GL.fit(X)

prec = GL.precision_

#Form graph
G = nx.Graph()
G.add_nodes_from(ProteinNames)

for i in range(NCols):
for j in range(i):
if prec[i,j]!=0:
G.add_edges_from([(ProteinNames[i],ProteinNames[j])])

nx.draw_circular(G, edge_color ='blue', node_color ='yellow', with_labels = True, node_size = 3000)
plt.savefig(os.path.join('figures', 'glassoSachs%s.pdf' % lam))

4 changes: 2 additions & 2 deletions examples/iris-scatterplot.py
Expand Up @@ -3,6 +3,6 @@
import os
import seaborn as sns; sns.set(style="ticks", color_codes=True)
iris = sns.load_dataset("iris")
#g = sns.pairplot(iris)
g = sns.pairplot(iris)
g = sns.pairplot(iris, hue="species")
plt.savefig(os.path.join('figures', 'iris-scatterplot.pdf'))
#plt.savefig(os.path.join('figures', 'iris-scatterplot.pdf'))
Binary file added figgen/.DS_Store
Binary file not shown.
Binary file renamed daft/.DS_Store → figgen/daft/.DS_Store
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
73 changes: 73 additions & 0 deletions figgen/daft/SRNN.py
@@ -0,0 +1,73 @@
from matplotlib import rc
import matplotlib.pyplot as plt
rc("font", family="serif", size=12)
rc("text", usetex=True)
#rc("text.latex", preamble=open("macros.tex").read())
#rc('text.latex', preamble="\usepackage{amssymb}\usepackage{amsmath}\usepackage{mathrsfs}")

import os

import imp
daft = imp.load_source('daft', 'daft-080308/daft.py')
#import daft
folder = "/Users/kpmurphy/github/pyprobml/figures"



pgm = daft.PGM([3, 3], origin=[0, 0])

pgm.add_node(daft.Node("x1", r"$x_{t-1}$", 1, 1))
pgm.add_node(daft.Node("z1", r"$z_{t-1}$", 1, 2))
pgm.add_node(daft.Node("x2", r"$x_{t}$", 2, 1))
pgm.add_node(daft.Node("z2", r"$z_{t}$", 2, 2))

pgm.add_edge("z1", "z2", linestyle="-")
pgm.add_edge("z1", "x1", linestyle="-")
pgm.add_edge("z2", "x2", linestyle="-")

pgm.render()
fname = "SSM-simple"
pgm.figure.savefig(os.path.join(folder, "{}.pdf".format(fname)))




pgm = daft.PGM([3, 3], origin=[0, 0])

pgm.add_node(daft.Node("x1", r"$x_{t-1}$", 1, 1))
pgm.add_node(daft.Node("z1", r"$h_{t-1}$", 1, 2.0, shape="rectangle"))
pgm.add_node(daft.Node("x2", r"$x_{t}$", 2, 1))
pgm.add_node(daft.Node("z2", r"$h_{t}$", 2, 2.0, shape="rectangle"))

pgm.add_edge("z1", "z2", linestyle="-")
pgm.add_edge("z1", "x1", linestyle="-")
pgm.add_edge("z2", "x2", linestyle="-")
pgm.add_edge("x1", "z2", linestyle="-")
pgm.add_edge("x1", "x2", linestyle=":")

pgm.render()
fname = "RNN-simple"
pgm.figure.savefig(os.path.join(folder, "{}.pdf".format(fname)))



pgm = daft.PGM([3, 4], origin=[0, 0])

pgm.add_node(daft.Node("x1", r"$x_{t-1}$", 1, 1))
pgm.add_node(daft.Node("z1", r"$z_{t-1}$", 1, 3))
pgm.add_node(daft.Node("h1", r"$h_{t-1}$", 1, 2.0, shape="rectangle"))
pgm.add_node(daft.Node("x2", r"$x_{t}$", 2, 1))
pgm.add_node(daft.Node("z2", r"$z_{t}$", 2, 3))
pgm.add_node(daft.Node("h2", r"$h_{t}$", 2, 2.0, shape="rectangle"))

pgm.add_edge("z1", "h1", linestyle="-")
pgm.add_edge("h1", "h2", linestyle="-")
pgm.add_edge("h1", "x1", linestyle="-")
pgm.add_edge("z2", "h2", linestyle="-")
pgm.add_edge("h2", "x2", linestyle="-")
pgm.add_edge("x1", "h2", linestyle="-")
pgm.add_edge("x1", "x2", linestyle=":")

pgm.render()
fname = "SRNN-simple"
pgm.figure.savefig(os.path.join(folder, "{}.pdf".format(fname)))
18 changes: 12 additions & 6 deletions daft/VRNN.py → figgen/daft/VRNN.py
Expand Up @@ -3,12 +3,13 @@
rc("font", family="serif", size=12)
rc("text", usetex=True)
#rc("text.latex", preamble=open("macros.tex").read())

#rc('text.latex', preamble="\usepackage{amssymb}\usepackage{amsmath}\usepackage{mathrsfs}")

import os

import imp
#daft = imp.load_source('daft', 'daft-080308/daft.py')
import daft
daft = imp.load_source('daft', 'daft-080308/daft.py')
#import daft



Expand Down Expand Up @@ -79,9 +80,14 @@
pgm.add_edge("h2", "s3", linestyle="-")
pgm.add_edge("s1", "s2", linestyle="-.")
pgm.add_edge("s2", "s3", linestyle="-.")
pgm.add_edge("h1", "z1", linestyle="-.")
pgm.add_edge("h2", "z2", linestyle="-.")
pgm.add_edge("h3", "z3", linestyle="-.")

pgm.add_edge("h1", "z1", linestyle="-",)
pgm.add_edge("h2", "z2", linestyle="-")
pgm.add_edge("h3", "z3", linestyle="-")
pgm.add_edge("z1", "s2", linestyle="-")
pgm.add_edge("z2", "s3", linestyle="-")
pgm.add_edge("z1", "h2", linestyle="-")
pgm.add_edge("z2", "h3", linestyle="-")

pgm.render()
folder = "/Users/kpmurphy/github/pyprobml/figures"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 20c3069

Please sign in to comment.