Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
188 changed files
with
10,939 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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')) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
Oops, something went wrong.