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
/* The API controller | |
Exports 3 methods: | |
* post - Creates a new thread | |
* list - Returns a list of threads | |
* show - Displays a thread and its posts | |
*/ | |
var Thread = require('../models/thread.js'); | |
var Post = require('../models/post.js'); |
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
Three files are included: | |
1. `weighted_majority.py`: the weighted majority algorithm | |
2. `main.py`: the main program which takes a specific beta value and make a list of plots | |
3. `experiment.sh`: bash script that experiments on a list of beta values. This is a good entry of this gist. |
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
function [] = n_armed_testbed(nB,nA,nP,sigma) | |
% | |
% Generates the 10-armed bandit testbed. | |
% | |
% Inputs: | |
% nB: the number of bandits | |
% nA: the number of arms | |
% nP: the number of plays (times we will pull a arm) | |
% sigma: the standard deviation of the return from each of the arms | |
% |
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
from __future__ import division | |
from itertools import groupby | |
from collections import Counter | |
texts = [('spam', ['FREE', 'online', '!!!']), | |
('safe', ['results', 'repository','online']), | |
('spam', ['FREE','online','results','FREE', '!!!']), | |
('spam', ['!!!', 'registration','FREE','!!!']), | |
('safe', ['conference', 'online', 'registration', 'conference']), | |
('safe', ['conference', 'results', 'repository', 'rsults'])] |
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
from __future__ import division | |
from collections import Counter, defaultdict | |
import operator | |
A = 'A'; H = 'H' | |
STATES = ['alpha', 'beta']; OBS = [A, H] | |
#given a list of training data, list of (sts, obs) pairs, | |
#derive the HMM model parameters |
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
from __future__ import division | |
class Data (): | |
def __init__ (self, data, prev={}): | |
#prev is used to determined the alpha value in the MAP parameter estimation | |
self.d = data; | |
self.prev = prev | |
def filter (self, **kwargs): | |
return Data(filter(lambda row: reduce (lambda acc, (field, value): acc and (row [field] == value), kwargs.items (), True), |
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
%% ----------------------------------------------------------- | |
%% The EM part! | |
%% ----------------------------------------------------------- | |
function [means, stds, P] = em (X, K) | |
%input: | |
%% X, the data points | |
%% K, the component number | |
[N, featureNumber] = size (X); |
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
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
circle, | |
path { | |
cursor: pointer; | |
} | |
circle { |
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
##Usage: | |
# with profiler_manager(): | |
# do want you want | |
from contextlib import contextmanager | |
import cProfile, pstats, StringIO | |
@contextmanager | |
def profiler_manager(): | |
pr = cProfile.Profile() |
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
""" | |
The CYK parsing algorithm | |
""" | |
from collections import defaultdict | |
from itertools import product | |
import texttable #needs to be installed, can be accessed at http://foutaise.org/code/texttable/ | |
def _print_tabel(table, nrow, ncol): | |
"""Utility function to print to dynamic programming table""" | |
t = texttable.Texttable() |
OlderNewer