Skip to content

Instantly share code, notes, and snippets.

View usptact's full-sized avatar

Vladislavs Dovgalecs usptact

View GitHub Profile
@usptact
usptact / monty.wppl
Last active August 26, 2018 04:31
Agentmodels, WebPPL: Monty Hall Example
// Remove each element in array ys from array xs
var remove = function(xs, ys) {
return _.without.apply(null, [xs].concat(ys));
};
var doors = [1, 2, 3];
// Monty chooses a door that is neither Alice's door
// nor the prize door
var monty = function(aliceDoor, prizeDoor) {
// 4 dice: 4, 6, 8 and 12 sides
// each dice is perfect
var dice = [
Categorical(
{
ps: [1/4, 1/4, 1/4, 1/4],
vs: [0, 1, 2, 3]
}
),
Categorical(
var person = function() {
var is_female = sample(Bernoulli({p: 0.51}))
if (is_female == false) {
return {hgt: sample(Gaussian({mu: 178.0, sigma: 7.7})), is_female: is_female}
} else {
return {hgt: sample(Gaussian({mu: 163.0, sigma: 7.3})), is_female: is_female}
}
}
var is_taller = function(h1, h2) {
//
// Game of Ur
//
var roll = function() {
return flip() + flip() + flip() + flip();
}
var game = function() {
var n = sample(RandomInteger({n: 20}));
@usptact
usptact / zoo
Last active November 20, 2018 10:41
//
// Zoo: Infer prevalence of 3 animals after a zoo visit
//
// Observed: 3 lions, 2 tigers and 1 bear
//
// Questions:
// - Prevalence of each species
// - Probability of seeing a bear next time
//
using System;
using Microsoft.ML.Probabilistic.Models;
namespace twodice
{
class Program
{
static void Main(string[] args)
{
Variable<int> six = Variable.DiscreteUniform(6);
@usptact
usptact / codesign_gdb.md
Created October 25, 2019 01:07 — forked from hlissner/codesign_gdb.md
Codesign gdb on OSX

Note: these instructions are for pre-Sierra MacOS. Sierra and newer users see https://gist.github.com/gravitylow/fb595186ce6068537a6e9da6d8b5b96d by @gravitylow.

If you are getting this in gdb on OSX while trying to run a program:

Unable to find Mach task port for process-id 57573: (os/kern) failure (0x5).
 (please check gdb is codesigned - see taskgated(8))
@usptact
usptact / HelloServlet.java
Created January 22, 2020 21:21
HelloServlet
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet(name = "HelloServlet", urlPatterns = {"hello"}, loadOnStartup = 1)
public class HelloServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
// Two balls in the bag:
// (1) fifty/fifty red (true) or green (false)
// (2) 100% red
//
// Process:
// - pull out the first ball and observe it is red
// - Question: what is the probability the remaining ball is red too?
var model = function() {
var b1 = flip(0.5)
@usptact
usptact / GuassianDensity eval
Created December 31, 2022 02:58
Gaussian Density eval and comparison using Infer.NET
using Microsoft.ML.Probabilistic.Math;
using Vector = Microsoft.ML.Probabilistic.Math.Vector;
class Program
{
static void Main(string[] args)
{
Vector x = Vector.FromArray(new double[] { 0, 1 });
//Vector x = new Vector();
//Vector mean = new Vector(new double[] { 0.1, 1.1 });