Skip to content

Instantly share code, notes, and snippets.

@sir-deenicus
sir-deenicus / #Probabilistic Programming in the Browser.md
Last active December 29, 2018 18:14
Discrete Probability Monad with F# computation Expressions that runs in Fable.

Discrete Probability Monad with F# computation Expressions that runs in Fable

Copy and paste each part in turn into http://fable.io/repl/. Probabilistic programming part should start around line 220. Should be compatible with almost everything in http://greenteapress.com/wp/think-bayes/

Also provides text histogram plots!

@sir-deenicus
sir-deenicus / cfr.fsx
Created September 13, 2017 23:21
Simple Counter-factual regret minimization example
open Prelude.Common
open System
open Prelude.Math
open Prelude
open SimpleTrees
type Node = {
regretSum : double [] ;
strategySum : double [];
}
@sir-deenicus
sir-deenicus / Least Unique Integer Output
Created September 13, 2017 05:39
Regret Minimization on Least Unique Integer Game
Attempt at Nash
GUESS STRATEGY
Move | Move Probability
---- | ----------------
0 | 0.501
1 | 0.251
2 | 0.125
3 | 0.063
@sir-deenicus
sir-deenicus / rps output
Last active September 13, 2017 05:35
Regret Minimization. Nash Equilibrium for Rock Paper Scissors
STRATEGY VS STATIC ADVERSARY
Move | Move Probability
-------- | ----------------
Rock | 0
Paper | 1
Scissors | 0
STRATEGY VS STATIC ADVERSARY
Player 1 | Player 2 | Prob 1 | Prob 2 | Joint Prob | Player 1 Util | Player 2 Util
@sir-deenicus
sir-deenicus / rps2 output
Last active September 13, 2017 23:55
Regret Minimization on Rock, Paper, Scissors (Games with gifts and no gifts)
LEARNED STRATEGY
Move | Move Probability
---- | ----------------
R | 0
P | 0.999
S | 0
T | 0
LEARNED STRATEGY VS FIXED ADVERSARY
Algeria 5.86 0.93
Angola 5.09 0.88
Argentina 6.39 0.66
Australia 8.67 0.32
Austria 7.73 0.55
Azerbaijan 5.6 0.495
Bangladesh 5.07 1.0
Belgium 7.51 0.33
Brazil 6.52 0.865
Bulgaria 5.73 0.335
open System
open FSharp.Data
type GplusPost = FSharp.Data.JsonProvider<"gplusposttemplate.json">
type GplusSearch = FSharp.Data.JsonProvider<"gplusSearchTemplate.json">
type GplusCommentList = FSharp.Data.JsonProvider<"gplusCommentListTemplate.json">
let googlePlusFunc key url parse (mapItems) (next) takeAtATime maxtake query =
let download token choice =
try
@sir-deenicus
sir-deenicus / hyphenate.fs
Last active January 1, 2016 12:09
Hyphenation algorithm used by Tex.
type HyphTree =
| Node of (int [] option) * Map<char, HyphTree>
| Empty
let insertpattern tree pattern =
let chars = pattern |> Seq.filter (Char.IsNumber >> not) |> Seq.toArray
let points = Text.RegularExpressions.Regex.Split(pattern, "[.a-z]") |> Array.map (fun c -> let b, i = Int32.TryParse c in if b then int i else 0)
let rec bt t = function
| i when i = chars.Length -> Node(Some points, Map.empty)
| i ->
@sir-deenicus
sir-deenicus / jatexgplus.js
Last active December 18, 2015 14:28
This is a very simple chrome plugin that allows latex to render in google plus. Installation is (simple). Download the zipped plugin from google drive [1](exactly same, conveniently packaged), go to extensions, check developer mode, unzip to a folder and click Load Unpacked Extenstion to load the folder [1] clickable link is a comment below.
var injectMathJax = document.createElement('script');
var typeSet = document.createElement('script');
var style=document.createElement('style');
//modified: css https://github.com/christianp/mathjax-bookmarklet/blob/master/bookmarklet.js
style.innerText = '.MathJax .mn {background: inherit;} .MathJax .mi {color: inherit;} .MathJax .mo {background: inherit;}';
injectMathJax.type = 'text/javascript';
injectMathJax.src = 'https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML';
@sir-deenicus
sir-deenicus / worldbank-country-ranking.fs
Last active September 13, 2017 05:05
A hastily constructed script to rank countries according to some criteria and generate an html table.
open FSharp.Data
let data = WorldBankData.GetDataContext()
let scoreArr = [|
"Household final consumption expenditure per capita (constant 2000 US$)", (-7.5, 50000.);
"Intentional homicides (per 100,000 people)", (-20., 1000.);
"Fixed broadband Internet subscribers (per 100 people)", (9.5, 100.);
"Burden of customs procedure, WEF (1=extremely inefficient to 7=extremely efficient)", (6., 7.);
"CPIA transparency, accountability, and corruption in the public sector rating (1=low to 6=high)", (6., 6.);
"GINI index", (-5., 100.);