Skip to content

Instantly share code, notes, and snippets.

@notbanker
notbanker / fourth_root_transform.py
Created July 6, 2019 19:34
Turning exponentially distributed data into normally distributed data
import matplotlib.pyplot as plt
import numpy as np
x = np.random.exponential(size=5000)
y = [ pow(x_,0.2654) for x_ in x]
plt.hist(y,bins=51)
plt.show()
def running_on_local():
return not running_on_domino()
def running_on_domino():
return ( domino_run_id() is not None )
@notbanker
notbanker / chained.py
Last active March 10, 2024 17:51
Context manager to temporarily pandas set chained assignment warning to None,'warn' or 'raise, then revert
import pandas as pd
class ChainedAssignent:
""" Context manager to temporarily set pandas chained assignment warning. Usage:
with ChainedAssignment():
blah
with ChainedAssignment('error'):
@notbanker
notbanker / stockfish.py
Created March 23, 2016 15:49
Python call to stockfish chess engine
import subprocess
from lib.common.dominoUtil import running_on_local
from lib.config import PROJECT_PATH
import time
import psutil
import os
import numpy as np
def _recommended_threads():
return psutil.cpu_count()-2
@notbanker
notbanker / lichess.py
Created March 21, 2016 21:31
Get some random middlegame positions from actual games on www.lichess.org
import json
import urllib2
import time
import pandas as pd
def fen_examples( max_users = 3, max_games_per_user=10, sleep_time = 15 ):
""" Grab some real game positions from the middle of actual games, and the result """
users = users_in_team( team='coders' )
records = list()
for user in users[ :max_users ]:
@notbanker
notbanker / stockfish.sh
Last active November 24, 2019 16:03
Use stockfish engine to output the position evaluation only
#!/usr/bin/env bash
# Call stockfish engine on mac and return only the evaluation score
# Usage stockfish.sh 'r1b2rk1/4qppp/2pp4/pp6/3Bn3/PB3Q1P/1PP2PP1/3R1RK1' 5 mac 12 1024
# Usage stockfish.sh 'r1b2rk1/4qppp/2pp4/pp6/3Bn3/PB3Q1P/1PP2PP1/3R1RK1' 5 mac 12 1024
# Assumes the stockfish binary is called 'stockfish_'+binary
fen=$1
seconds=${2:-3}
binary=${3:-mac}
threads=${4:-12}
@notbanker
notbanker / lambert.py
Last active July 6, 2019 19:54
Amazing facts about Lambert
lambert_facts = ['Lambert was born the son of a tailor, and was expected by his father to continue in that profession.',
'Lamberts early fight for his education is a remarkable story---he had to sell drawings and writings to his classmates to buy candles for night study,',
'Lambert produced fundamental discoveries in cartography, despite being self-educated.', 'Lambert influenced hygrometry, pyrometry, pure mathematics and statistics.',
'Lambert was more famous as a philosopher than as a mathematician.', 'The Lambert projection is still in use in cartography.',
'Lambert was the first person to prove that pi is irrational.', 'Proofs that it is impossible to square the circle leaned on insights from Lambert.',
'Lambert found a series solution to the trinomial equation, by hand calculation.', 'Lamberts technique for solving general series reversion techniques was a forerunner to the Langrange Inversion Theorem.',
'Lambert discovered an
@notbanker
notbanker / app.py
Created August 30, 2014 02:38
Bayesian calculation for twin Down Syndrome probabilities (Flask app)
from flask import Flask, request, url_for
from scipy.optimize import bisect
import math
import numpy as np
app = Flask(__name__)
app.secret_key = 'Whatever'
@app.route('/')
def index():
@notbanker
notbanker / twinsmodel.py
Created August 29, 2014 20:39
MCMC for twin diagnosis
from pymc import Model, MCMC, deterministic, stochastic, Normal, Bernoulli, Beta, distributions
import numpy as np
def twinModelVars( p_identical = 0.5, p_down = 0.01, measurement = 2.5, measurementPrecision = 2.0 ):
""" Stylized model for twin Down Syndrome likelihood after a blood sample is taken from mother
containing a mixture of indicators from each foetus
:param p_identical: (Prior) probability of identical twins versus fraternal (0.1 for population)
:param p_down: (Prior) probability of Down Syndrome
:param measurement: Measured marker value
@notbanker
notbanker / gist:1375bca2e5283c5a4d1f
Created August 29, 2014 20:39
MCMC for twin diagnosis
from pymc import Model, MCMC, deterministic, stochastic, Normal, Bernoulli, Beta, distributions
import numpy as np
def twinModelVars( p_identical = 0.5, p_down = 0.01, measurement = 2.5, measurementPrecision = 2.0 ):
""" Stylized model for twin Down Syndrome likelihood after a blood sample is taken from mother
containing a mixture of indicators from each foetus
:param p_identical: (Prior) probability of identical twins versus fraternal (0.1 for population)
:param p_down: (Prior) probability of Down Syndrome
:param measurement: Measured marker value