Skip to content

Instantly share code, notes, and snippets.

@notbanker
notbanker / fourth_root_transform.py
Created Jul 6, 2019
Turning exponentially distributed data into normally distributed data
View fourth_root_transform.py
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()
View domino_hacks.py
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 Dec 16, 2019
Context manager to temporarily pandas set chained assignment warning to None,'warn' or 'raise, then revert
View chained.py
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 Mar 23, 2016
Python call to stockfish chess engine
View stockfish.py
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 Mar 21, 2016
Get some random middlegame positions from actual games on www.lichess.org
View lichess.py
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 Nov 24, 2019
Use stockfish engine to output the position evaluation only
View stockfish.sh
#!/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 Jul 6, 2019
Amazing facts about Lambert
View lambert.py
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 Aug 30, 2014
Bayesian calculation for twin Down Syndrome probabilities (Flask app)
View app.py
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 Aug 29, 2014
MCMC for twin diagnosis
View twinsmodel.py
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
View gist:1375bca2e5283c5a4d1f
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
You can’t perform that action at this time.