Skip to content

Instantly share code, notes, and snippets.

@jcbozonier
jcbozonier / py.py
Created January 30, 2017 13:39 — forked from anonymous/py.py
Evaluating Walnut and Almond Mix
# The walnut/almond mix ratios we have hypothesized
hypotheses = [[.8, .2],
[.5,.5],
[.2,.8]]
# Evaluate the pdf for each hypothesis
# Note that we only evaluate the hypothesis
# for one nut. If it's 80% we know the
# other must be 20%.
pdf_score = np.array([ss.beta.pdf(hypothesis[0], 1+1, 1+5) for hypothesis in hypotheses])
@jcbozonier
jcbozonier / py.py
Created January 30, 2017 13:38 — forked from anonymous/py.py
Switching from Beta to Dirichlet
hypotheses = [[.8, .2],
[.5,.5],
[.2,.8]]
# Notice how we swapped out the Beta for
# a Dirichlet. The only difference is we
# now pass a list of counts to the pdf
# function. We'll get to why in a bit.
pdf_score = np.array([ss.dirichlet.pdf(hypothesis, [1+1+2, 1+5+3]) for hypothesis in hypotheses])
probabilities = pdf_score/pdf_score.sum()
@jcbozonier
jcbozonier / gist:7da348d57a1dcb8acbfe
Last active August 29, 2015 14:15 — forked from anonymous/gist:f77b3da951681d3d2528
TCP server that streams currently tweeting twitter handles of those around NYC for use via Apache Spark. Code HEAVILY borrowed from http://kmkeen.com/socketserver/ Made to work with Spark by Justin Bozonier
import SocketServer, subprocess, sys
from threading import Thread
from TwitterAPI import TwitterAPI
import json, unidecode
api = TwitterAPI(consumer_key, consumer_secret, access_token_key, access_token_secret)
HOST = 'localhost'
PORT = 9999
#! /usr/bin/env python
import sys
import random
import pymc
import numpy
from dendropy.mathlib import probability as prob
from dendropy.mathlib import statistics as stats
rng = random.Random()
<html>
<head>
<title>Monte Carlo Calculus</title>
<script src="script/monte_carlo.js"></script>
<script>
var lex_this = function(chromosome){
var tokens = [];
chromosome = chromosome.split('').slice(0);
window.ScreeningRoom = window.ScreeningRoom || {};
ScreeningRoom.AjaxHelper = function(){
this.siteRoot = "http://localhost:9292/";
this.restResources = {
"add_viewer": siteRoot + "drafts/addviewer",
"add_opinion": siteRoot + "drafts/addopinion"
};
werewr
require 'date'
class ChoreAssignmentController < ApplicationController
def assign_todays_chore
@users_chore_list.provide_todays_chore_to this
end
def todays_chore_is chore
@assignment = chore
end
void Main()
{
var rootList = new List<Node>(){new Node()}; // only ever one root, I assume.
var childrenAtThisLevel = FillLevel(rootList);
while(childrenAtThisLevel.Count > 0)
childrenAtThisLevel = FillLevel(childrenAtThisLevel);
}
List<Node> FillLevel(List<Node> childrenAtThisLevel)
{
given["a two number addition solver"]
.with("solver", new additionSolver())
.with("number", [1, 2])
.withParametersAs("number")
.when("they are added", this.solver.add)
.itShould("sum them", function () this.result.shouldEqual(number[1] + number[2]))
.itShould("not subtract them", function () this.result.shouldNotBeDumb());
given["a two number addition solver"]
.with("solver", new additionSolver())