Skip to content

Instantly share code, notes, and snippets.

(define-register A 8)
(define-register X 8)
(define-register Y 8)
(define-register SP 8)
(define-register PC 16)
(define-register RES 8)
(define-register HALT 1)
@LFY
LFY / gist:10175240
Last active August 29, 2015 13:58
Contrastive divergence
from math import *
from random import *
# Basic MCMC--------------------------------------------------------------------
def make_kernel(propscore):
def call(state, score):
return mh_step(state, score, propscore)
return call
@LFY
LFY / bsci.ss
Created August 3, 2012 00:30
Translating between lambda and BSCI calculus
;; Notes on "Learning Programs: A Hierarchical Bayesian Approach"
;; I was confused by the routing terminology and the tree transformation
;; figures in the paper. In particular I was not exactly sure what were the
;; general rules behind translating (S (B * I) I) to the square function.
;; B, C combinators are known as the "Turner combinators."
;; See http://c2.com/cgi/wiki?EssAndKayCombinators
;; where the translations of lambda calculus to "BSCI" calculus are given:
@LFY
LFY / ising-eval.ss
Created July 29, 2012 22:04
Ising on 10 variables, 100k iter - before/after tracing, dead code elimination and allocation removal
;; Original program
(letrec
([eq (factor (x y) (if (= x y) 0.0 (log 0.1)))]
[xs (repeat 10 (lambda () (xrp+init randint-scorer randint randint-prop 0 0 1)))]
[constr (map (lambda (xy) (eq (car xy) (car (cdr xy)))) (bigram xs))])
xs)
;; Performance of this model (100k total iterations, lag = 10k)
;; running stats for (run-shred samples lag prog ALL-OPTS):
@LFY
LFY / gist:1489855
Created December 17, 2011 10:08
BFS on grammars with shift/reset
(import (grammars)
(printing)
(_srfi :1)
(util)
(program)
(delimcc-simple-ikarus))
;; New grammar preprocessing function: lazify-nts, which uses the Scheme
;; procedure representation of nonterminals to return a function (not a tree)
;; that, when called, uses shift to capture the current context and replace it
@LFY
LFY / gist:1399171
Created November 28, 2011 05:02
Scene graphs as terms of algebraic data type
-- Formalism of scene graphs as algebraic data types
{-# LANGUAGE ExistentialQuantification #-}
import Control.Monad
-- Algebraic datatypes for scene graphs
type Id = String
type Matrix = String
@LFY
LFY / gist:1369755
Created November 16, 2011 10:15
Stochastic search trees
;; Stochastic search trees (from Kiselyov and Shan's HANSEI)
(import (delimcc-simple-ikarus)
(printing)
(_srfi :1))
;; the core: stochastic search trees
(define (pv-unit v) (list (list 1.0 `(V ,v))))
(define (dist pvs)
@LFY
LFY / gist:1363596
Created November 14, 2011 09:27
Inside/Outside algorithm specialized to simple example
(import (printing)
(_srfi :1))
(define start-params
'(1/3 1/3 1/3))
(define (likelihood params)
(* (list-ref params 0)
(list-ref params 0)
(list-ref params 1)
@LFY
LFY / gist:1347012
Created November 8, 2011 04:38
Cluster grammar
(program
((abstraction F118 (V11) (cluster V11 2))
(abstraction F117 () (cluster c137 3))
(abstraction F116 (V10) (node V10 (F112) (F112)))
(abstraction F115 (V6 V7 V8 V9)
(node V9 V8 (F112) V7 (F112) V6 (F112) (F112) (F112)))
(abstraction F114 () (node (F112)))
(abstraction F113 (V5) (node V5 (F112)))
(abstraction F112 ()
((lambda (V4) (cluster V4 1))
@LFY
LFY / gist:1272805
Created October 8, 2011 20:11
Scheme generators
(library (generators)
(export
yield->
next-<
begin-<
)
(import (rnrs)
(delimcc-simple-ikarus)
)