Skip to content

Instantly share code, notes, and snippets.

View chokkan's full-sized avatar

Naoaki Okazaki chokkan

View GitHub Profile
@chokkan
chokkan / logic.ipynb
Last active December 5, 2018 11:30
logic
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@chokkan
chokkan / classification.ipynb
Last active December 19, 2017 18:35
Jupyter notebook for classification.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@chokkan
chokkan / sum.c
Last active December 17, 2015 23:59
A 'buggy' code for calculating the sum of values in an input file.
#include <stdio.h>
int main(int argc, char *argv[])
{
FILE *fp = NULL;
double value, sum = 0;
fp = fopen(argv[1], "r");
if (fp = NULL) {
fprintf(stderr, "failed to open %s\n", argv[1]);
(require 'gud)
(setq gdb-many-windows t)
(setq gdb-use-separate-io-buffer t)
(add-hook
'gdb-mode-hook
'(lambda ()
(gud-tooltip-mode t)
(gud-def gud-break-main "break main" nil "Set breakpoint at main.")
))
@chokkan
chokkan / pcky.py
Created October 24, 2012 17:12
Probabilistic Cocke-Kasami-Younger (PCKY) algorithm
import collections
import math
def build(CNF):
G = collections.defaultdict(list)
for left, right, p in CNF:
G[right].append((left, math.log(p)))
return G
def show_cell(T, i, j):
@chokkan
chokkan / cky.py
Created October 24, 2012 17:10
Cocke-Kasami-Younger (CKY) algorithm
import collections
def build(CNF):
G = collections.defaultdict(list)
for left, right in CNF:
G[right].append(left)
return G
def cky(G, W):
T = [[[] for j in range(len(W)+1)] for i in range(len(W))]
@chokkan
chokkan / viterbi.py
Created October 17, 2012 15:19
Viterbi algorithm on Markov Model
"""
Viterbi algorithm on Markov Model.
Copyright (c) 2012 by Naoaki Okazaki
"""
import json
import math
import operator
import sys
@chokkan
chokkan / hmmtrain.py
Created October 17, 2012 15:18
Maximum Likelihood Estimation (MLE) for Hidden Markov Model (HMM)
"""
Maximum Likelihood Estimation (MLE) for Hidden Markov Model (HMM).
Copyright (c) 2012 by Naoaki Okazaki
"""
import collections
import json
import math
import sys
@chokkan
chokkan / spam_feature.py
Created October 10, 2012 13:42
Feature Extractor for Spam Filtering
import sys
import os
import gzip
def ngram(T, n):
return ['%dgram=%s' % (n, '_'.join(T[i:i+n])) for i in range(len(T)-n+1)]
def process(fo, fi, label):
F = []
for line in fi: