Skip to content

Instantly share code, notes, and snippets.

import json
class MapReduce:
def __init__(self):
self.data = []
self.intermediate = {}
self.result = []
def emit_intermediate(self, key, value):
self.intermediate.setdefault(key, [])
@weaselj
weaselj / OPA3communityTemplate.py
Created October 19, 2012 14:38
OPA3communityTemplate for Coursera SNA class
# Coursera SNA optional Programming Assignment 3 template
# see this blog post for a nice overview of community detection algorithms
# http://www.r-bloggers.com/summary-of-community-detection-algorithms-in-igraph-0-6/
# load the igraph library
# you may have to install this module if you haven't already
import igraph as ig
# read in the graph in GML format
# it is a sampled collection of pages from a strange set of seed categories:
@weaselj
weaselj / OPA2centralityTemplateIGraph.py
Created October 13, 2012 21:00
OPA2centralityTemplate for Coursera SNA class
# Coursera SNA optional Programming Assignment 2 template
# load the igraph library
# you may have to install this module if you haven't already
import igraph as ig
import numpy as np
# read in the graph in GML format
# it is a sampled collection of pages from a strange set of seed categories:
# Math, Sociology, and Chemistry
@weaselj
weaselj / MonitorAssignment.m
Created October 1, 2012 18:50
MonitorAssignment for Coursera PGM class
function MonitorAssignment( F, names, valNames, E )
% MonitorAssignment( F, names, valNames, E ) - Pretty prints all the
% marginals for an assignment
%
% F contains the struct array of factors
% names contains the variable names
% valNames contains the assignment names for each variable,
% as seen in SAMIAM
% E is an N-by-2 cell array, each row being a variable/value pair.
% Variables are in the first column and values are in the second column.