Skip to content

Instantly share code, notes, and snippets.

View davidrichards's full-sized avatar

David Richards davidrichards

View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@davidrichards
davidrichards / demo.py
Created April 1, 2019 22:25
Gather and merge configuration
system_defaults = {}
config_paths = [
Path.home()/'.myconfig',
]
env_config = config_filter(os.environ)
user_config = get_config(*config_paths)
config = d_merge(env_config, user_config, system_defaults)
DROP VIEW IF EXISTS flat_links;
CREATE TEMPORARY VIEW flat_links AS
SELECT
l.id as link_id, title, snippet, link, domain, rank,
link_type, search_engine_name, page_number,
requested_at, num_results_for_query,
num_results, q
FROM link l
LEFT JOIN (
SELECT
@davidrichards
davidrichards / auto_suggest
Created September 15, 2017 15:30
This API was supposed to be turned off two years ago, so no promises it will work for you.
#!/usr/bin/env ruby
require 'json'
require 'yaml'
class AutoSuggest
def self.call(*args)
new(*args).call
end
@davidrichards
davidrichards / C2.ipynb
Last active July 10, 2017 14:19
Bayesian Updates, taken slowly.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@davidrichards
davidrichards / demo.md
Last active June 27, 2017 15:29
Translate two confidence intervals into a mean, a standard deviation, and a histogram of sampled data.
s = Sample.new(5,8) # Uses a default 95% confidence level, drawing 5,000 samples
s.call # Returns a histogram of 5 entries
s.mean # Returns the calculated mean between 5 and 8
s.sample_mean # Returns the mean of the sample data
s.sigma # Returns the standard deviation, calculated from the confidence interval
s1 = Sample.new(5, 8, confidence: 0.8) # Changes the confidence level to 80%

Sample.call(5,8) # Cuts to the chase, just returns the histogram

@davidrichards
davidrichards / example.md
Last active April 28, 2017 20:19
A simple true/false sampling tool for sampling n_times, n trials per epoch, with a given probability of success (defaults to 50%).

Try something twice, with a probability of failure at 10%, record wether the cummulative result was failure. Do that 1 million times, and form a posterior belief about this situation.

TruthSampling.call(n_samples: 1_000_000, trials: 2, probability: 0.1)

Or, here's a basketball example. If I've got a 1/6 free throw average, and I take 4 free throws, what is the chance I make at least one of those 4?

TruthSampling.call(trials: 4, probability: 1/6.0)
{false=>0.48256, true=>0.51744}

This gives me about a 52% chance of making at least one basket.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.