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 / 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():
% 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_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');
@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
"""