Skip to content

Instantly share code, notes, and snippets.

View BERENZ's full-sized avatar

Maciej Beręsewicz BERENZ

View GitHub Profile
import numpy as np
import faiss
def search_knn(xq, xb, k, distance_type=faiss.METRIC_L2):
""" wrapper around the faiss knn functions without index """
nq, d = xq.shape
nb, d2 = xb.shape
assert d == d2
@j-martens
j-martens / urbanek-benchmark-25.R
Created July 13, 2015 16:25
MKL Performance Benchmark 2
# Run Simon Urbanek's benchmark v2.5
cat("R version\n")
cat("=========\n")
print(R.version)
if(exists("Revo.version")) {
cat("Revo version")
cat("============")
print(Revo.version)
@dannguyen
dannguyen / iowa-liquor-sales-dataset.readme.md
Last active July 8, 2023 12:27
Cleaning, summing up the State of Iowa Liquor Sales dataset

Iowa Liquor Sales dataset via Socrata/data.iowa.gov

(preliminary exploration)

The state of Iowa has released an 800MB+ dataset of more than 3 million rows showing weekly liquor sales, broken down by liquor category, vendor, and product name, e.g. STRAIGHT BOURBON WHISKIES, Jim Beam Brands, Maker's Mark

This dataset contains the spirits purchase information of Iowa Class “E” liquor licensees by product and date of purchase from January 1, 2014 to current. The dataset can be used to analyze total spirits sales in Iowa of individual products at the store level.

You can view the dataset via Socrata

recode <- function(df, ..., match = c("first", "last")) {
match <- match.arg(match)
cases <- lapply(list(...), as.case)
if (identical(match, "last")) cases <- rev(cases)
n <- nrow(df)
out <- rep(NA, length(n)) # logical will be upcast as needed
# Simple loop-y implementation
@kylebgorman
kylebgorman / autoloess.R
Last active November 28, 2022 16:06
autoloess.R: set the "span" (smoothing) hyperparameter for a LOESS curve so as to minimize AIC_c (includes a cute demonstration)
# autoloess.R: compute loess metaparameters automatically
# Kyle Gorman <gormanky@ohsu.edu>
aicc.loess <- function(fit) {
# compute AIC_C for a LOESS fit, from:
#
# Hurvich, C.M., Simonoff, J.S., and Tsai, C. L. 1998. Smoothing
# parameter selection in nonparametric regression using an improved
# Akaike Information Criterion. Journal of the Royal Statistical
# Society B 60: 271–293.
@mike-lawrence
mike-lawrence / lmer_oneway_Gaussian.R
Created November 16, 2011 13:03
Simulating a mixed effects model with one random effect, one fixed effect. Gaussian and binomial versions.
library(MASS)
library(lme4)
generate_data = function(
n # number of units
, k # number of trials within each condition within each unit
, noise # measurement noise variance
, I # population intercept
, vI # across-units variance of intercepts
, A # population A effect
@bds
bds / SparkLines in R
Created December 30, 2010 14:27
Sample sparkline plot using ggplot
library(ggplot2)
sparkLinePlot <- function(df, plot.file) {
highest <- subset(df, outcomes == max(outcomes))
lowest <- subset(df, outcomes == min(outcomes))
p <- ggplot(df, aes(x=date, y=outcomes)) +
geom_line() +
opts(panel.border = theme_rect(linetype = 0),