Skip to content

Instantly share code, notes, and snippets.

View darthsuogles's full-sized avatar

Philip Yang darthsuogles

  • @phissenschaft
  • San Francisco Bay Area
View GitHub Profile
@darthsuogles
darthsuogles / theano_chk_expr.py
Last active August 29, 2015 14:09
Checking numerical value of a Theano expression
import inspect # for line number
import re # for extracting debug information
_check_expr_regex = re.compile('THEANO_CHECK_EXPR\(.+\)')
def THEANO_CHECK_EXPR( expr, verbose = False ):
"""
Check the expression
Limited resolution at the line level
"""
@darthsuogles
darthsuogles / hw_pyplot.py
Last active August 29, 2015 14:20
Working with matplotlib
# Do not use ax.set_xticks([]), instead
ax.get_xaxis().set_visible(False);
# When having a bunch of plots in a grid (via subplots or gridspec),
# we can plot the title as the ylabel of the left-most plot.
# http://matplotlib.org/users/text_props.html
ax.set_ylabel('<text_of_the_title>', rotation = 'horizontal', horizontalalignment = 'right');
% Some useful tips
% Ref: http://emacsclub.github.io/html/matlab.html
% There are some other http://emacsclub.github.io/html/index.html
% http://ubcmatlabguide.github.io/html/gettingStarted.html
% Check if a parameter called 'arg1' of a function exists
if ~exist('arg1','var') || isempty(arg1)
disp(arg1)
end
@darthsuogles
darthsuogles / hw_networkx.py
Created May 5, 2015 13:32
How to properly plot a graph in networkx and export to json format.
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
#embedding_coords = nx.spring_layout(G)
embedding_coords = nx.graphviz_layout(G)
#embedding_coords = nx.spectral_layout(G)
#embedding_coords = nx.random_layout(G)
# stored_coords = nx.get_node_aattributes(G, 'embedding')
# for k,v in stored_coords.iteritems():
<!DOCTYPE html>
<meta charset="utf-8">
<title>Votre Titre</title>
<style>
.node circle {
fill: #fff;
stroke: steelblue;
stroke-width: 1.5px;
}
# Recursively reload depedencies
# Ref: https://ipython.org/ipython-doc/dev/interactive/reference.html#dreload
from IPython.lib.deepreload import reload as dreload
# %load_ext autoreload
# %autoreload 2
import numpy as np
import scipy.io as sio
import json # export data for d3 visualization
from mlearn_hclust import hierarchical_clustering
import json # export data for d3 visualization
import numpy as np
import scipy.cluster.hierarchy as hclust
## Compute histogram based on the Wasserstein distance matrix
def build_json_tree(node, parent):
"""
Build a tree for the json format
"""
git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached 2>/dev/null
"""
Find an optimal way to explore the Olympic Park west of Seattle
Ref: http://www.nps.gov/olym/planyourvisit/gettingaround.htm
"""
import z3
# import matplotlib.pyplot as plt
# import seaborn as sns
# sns.set_context("paper") # also: talk, poster, etc.
import OpenEXR, Imath
import numpy as np
import matplotlib.pyplot as plt
def exr_split_channels(exr_fname):
"""
Load a Mitsuba render generated multi-channel OpenEXR file.
Split the channels according to the information stored.
"""
## Load all images