This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from pylab import plot | |
def cdfplot(data=None, show_plot=True): | |
n_bins = len(unique(data)) | |
counts, bin_edges = np.histogram(data, n_bins, normed=True) | |
ecdf = np.cumsum(counts) | |
ecdf = ecdf/ecdf.max() | |
if show_plot: | |
plot(bin_edges[1:],ecdf) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def tfn(x, fx): | |
""" | |
TFN calculates the T-function of Owen. | |
Adapted from http://people.sc.fsu.edu/~jburkardt/c_src/asa076/asa076.html | |
Author: | |
Original FORTRAN77 version by JC Young, Christoph Minder. | |
C version by John Burkardt. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DATE_TRUNC('week', now()) === STR_TO_DATE(CONCAT(YEARWEEK(now(), 2), ' Sunday'), '%X%V %W') | |
DATE_TRUNC('month', now()) === DATE_FORMAT(now(), '%Y-%m-01') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<style> | |
body{ | |
font-family: sans; | |
padding: 10px; | |
} | |
svg path{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def hdi(frozen_dist, alpha=0.05, **args): | |
""" Highest density interval for a unimodel distribution """ | |
# freeze distribution with given arguments | |
def interval_width(hdi_pt_l): | |
return frozen_dist.ppf(alpha + hdi_pt_l) - frozen_dist.ppf(hdi_pt_l) | |
# find hdi_pt_l that minimizes interval_width | |
hdi_pt_l = fmin(interval_width, 1-alpha, ftol=1e-8, disp=False)[0] | |
# return interval as array([low, high]) | |
return frozen_dist.ppf([hdi_pt_l, alpha + hdi_pt_l]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function UUIDv4() | |
{ | |
$data = openssl_random_pseudo_bytes(16); | |
$data[6] = chr(ord($data[6]) & 0x0f | 0x40); // set version to 0100 | |
$data[8] = chr(ord($data[8]) & 0x3f | 0x80); // set bits 6-7 to 10 | |
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4)); | |
} |