Skip to content

Instantly share code, notes, and snippets.

@bennokr
bennokr / fib
Created September 11, 2012 22:16
Fibonacci in Haskell
fib = 0 : scanl (+) 1 fib -- counting revisions?
@bennokr
bennokr / tensor-perceptron.hs
Last active December 11, 2015 01:58
Tensor perceptron
import Tensor -- http://www.volkerschatz.com/haskell/tensor.hs
(+) :: Num a => Tensor a -> Tensor a -> Tensor a
(+) = tenBinOp (+)
(—) :: Num a => Tensor a -> Tensor a -> Tensor a
(—) = tenBinOp (-)
(•) :: Num a => Tensor a -> Tensor a -> Tensor a
(•) = tenBinOp (*)
(×) :: Num a => Tensor a -> Tensor a -> Tensor a
(×) a b = vectorhead $ (contract [(1,2)]) ((transpose . Vector . return) a) b where
@bennokr
bennokr / arcEager.py
Last active August 29, 2015 13:57
Arc-Eager Parsing
class UserClassifier:
""" YOU are the classifier, dude! """
def prepare (this, stack, buff, heads):
return sentence[stack[-1]]+' '+sentence[buff[-1]]
def train(this, pairs):
for i, o in pairs:
print 'remember: ', i, ' is ', o
@bennokr
bennokr / google_from_wsj
Created May 18, 2014 23:14
Unknown word estimation from CBOW
SHOULD CONTAIN CONVERTED ASCII VECTORS FROM https://drive.google.com/file/d/0B7XkCwpI5KDYNlNUTTlSS21pQmM/edit?usp=sharing BUT LESS OF THEM
@bennokr
bennokr / cmu.xml
Last active August 29, 2015 14:01
Centraal Museum Utrecht modecollectie
This file has been truncated, but you can view the full file.
<?xml version="1.0" encoding="UTF-8" ?>
<adlibXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://www.adlibsoft.com/adlibXML.xsd">
<recordList>
<record>
<priref>667</priref><institution.name>Centraal Museum</institution.name><collection>beeldende kunst</collection><collection>stadsgeschiedenis</collection><collection>prenten en tekeningen</collection><collection>kostuums</collection><object_name>prent</object_name><object_name>reproduktie</object_name><title>De modese Waayer</title><creator>Anoniem etser (18e eeuw)</creator><creator.qualifier/><dimension.type>hoogte (met lijstje)</dimension.type><dimension.type>breedte (met lijstje)</dimension.type><dimension.value>15.8</dimension.value><dimension.value>13.2</dimension.value><dimension.unit>cm</dimension.unit><dimension.unit>cm</dimension.unit><techniek.vrije.tekst>fotomechanische reproductie</techniek.vrije.tekst><material>papier</material><object_number>2127</object_number><production.date.start>1800</production.
@bennokr
bennokr / recursive.ipnb
Created June 18, 2014 14:34
Recursive NN test
{
"metadata": {
"name": "",
"signature": "sha256:318a10e455756a3d0f198c56152557074951feccc91cf32902b8e3b5a4601c91"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
@bennokr
bennokr / usage.py
Last active August 29, 2015 14:03
MCFParser usage
from MCFParser import Parser
# https://github.com/heatherleaf/MCFParser.py
grammar = [('f', 'S', ['A'], [[(0,0), (0,1)]]),
('g', 'A', ['A'], [['a', (0,0), 'b'], ['c', (0,1), 'd']]),
('h', 'A', [], [['a', 'b'], ['c', 'd']])]
parser = Parser(grammar, ['S'])
for tree in parser.parse("a a a b b b c c c d d d".split()):
print tree
@bennokr
bennokr / index.html
Last active August 29, 2015 14:05
Gaussian Distribution
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<style>
path { fill: none; stroke: #000; stroke-width: 1px; }
</style>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="https://raw.githubusercontent.com/worrydream/Tangle/master/Tangle.js"></script>
<script type="text/javascript"
@bennokr
bennokr / index.html
Last active August 29, 2015 14:08
2D Gaussian
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<style>
path { fill: none; stroke: red; stroke-width: 1px; }
polygon { fill: red; }
</style>
<script type="text/javascript" src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script type="text/javascript" src="https://rawgit.com/worrydream/Tangle/master/Tangle.js"></script>
@bennokr
bennokr / gamma.js
Last active August 29, 2015 14:14
Beta
// Visit http://www.johndcook.com/stand_alone_code.html for the source of this code and more like it.
// Note that the functions Gamma and LogGamma are mutually dependent.
function gamma
(
x // We require x > 0
)
{
//if (x <= 0.0)