View linear_algebra_game.py
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
# Supporting code for this blog article: | |
# https://thirld.com/blog/2018/05/17/linear-algebra-solves-a-childhood-mystery/ | |
# | |
# License: public domain. | |
import itertools | |
import numpy as np | |
def pretty_print_matrix(name, M): |
View gist:f4a7a32cae69ba5380fd
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
# Utils for handling files in ~/Downloads: | |
DOWNLOADS_DIR="$HOME/Downloads" | |
function lsdl() { | |
ls --color -1 -t "$DOWNLOADS_DIR" |head |nl | |
} | |
function cpdl() { | |
if [ "a$1" == 'a-h' ] || [ "a$1" == 'a--help' ]; then |
View PCFG.scala
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
import com.cra.figaro.language._ | |
import com.cra.figaro.library._ | |
import com.cra.figaro.library.compound._ | |
import com.cra.figaro.algorithm.sampling._ | |
import scala.math | |
object Node extends Enumeration { | |
type Node = Value |
View mk_slideshow.sh
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
#!/bin/bash | |
# Takes all images given as parameters, and makes a video slideshow out of them. | |
# Note that the images are ordered lexicographically, regardless of the order in | |
# which they are given. | |
# Output Parameters: | |
SLIDE_SECONDS=4 | |
SIZE_WIDTH=640 | |
SIZE_HEIGHT=480 |
View anagrams.py
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
#!/usr/bin/env python | |
# Find anagram groups in the given dictionary file. | |
# | |
# Example usage: ./anagrams.py /usr/share/dict/words | |
# | |
# The input file must have one word per line. We do not do any | |
# preprocessing, like lowercasing or removing punctuation. | |
# | |
# The output (stdout) contains one anagram group per line. |
View slam.blog
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
////////////////////////////////////////////////////////////////////////////// | |
// Dynamics model: | |
// Car parameters: | |
random Real car_a ~ DontCare(); | |
random Real car_b ~ DontCare(); | |
random Real car_h ~ DontCare(); | |
random Real car_L ~ DontCare(); | |
// Initial car pose: |
View gist:c0d5b0aab44c5e26f6ca
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
Error Examples | |
../example/galaxy.blog | |
../example/infinite-GMM.blog | |
../example/aircraft-position.blog | |
../example/solutions/simple-aircraft.blog | |
../example/sybil-attack-exp3.blog | |
../example/general-fixed-fun.blog | |
../example/balls/id-uncert-det.blog | |
../example/balls/id-uncert-noisy.blog | |
../example/multivar-gaussian-random-params/random-mu-fixed-sigma.blog |
View gist:21268389f11efd1a8cf6
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
../example/galaxy.blog | |
../example/galaxy.blog::108.7: Number expression expecting implicit set | |
../example/infinite-GMM.blog | |
java.lang.IllegalArgumentException: The mean given is not a valid row vector. It has dimensions 2 by 1. at blog.distrib.MultivarGaussian.setParams(MultivarGaussian.java:89) at blog.distrib.MultivarGaussian.setParams(MultivarGaussian.java:70) at blog.model.DistribSpec.initCPD(DistribSpec.java:260) at blog.model.DistribSpec.compile(DistribSpec.java:192) at blog.model.DependencyModel.compile(DependencyModel.java:202) at blog.model.RandomFunction.compile(RandomFunction.java:127) at blog.model.Model.compile(Model.java:531) at blog.Main.setup(Main.java:472) at blog.Main.main(Main.java:152) Error initializing CPD at 21: couldn't instantiate class class blog.distrib.MultivarGaussian Encountered 1 errors in compilation phase. | |
../example/aircraft-position.blog | |
../example/aircraft-position.blog::26.7: Number expression expecting implicit set (no location): Symbol "B1" is neither a variable in th |
View gist:cb3fb12f9ba3ab56da67
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
////////////////////////////////////////////////////////////////////////////// | |
// BLOG use case: Want some burn-in samples at the beginning of the run. | |
model = new Model.fromFile("burglary.blog") | |
evidence = new Evidence() | |
evidence.addFromFile("burglary.evi") | |
queries = new List() | |
sampler = new blog.sample.MHSampler(model, evidence, queries) | |
engine = new blog.engine.SamplingEngine(sampler) | |
// Burn-in: Since no queries are set yet, no results are recorded. |
View benchmark
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
import java.util.Random; | |
public class Benchmark { | |
public Benchmark() { | |
rng = new Random(); | |
hasLower = false; | |
hasUpper = false; | |
} | |
public void setParams(Double lower, Double upper) { |
NewerOlder