Skip to content

Instantly share code, notes, and snippets.

@ev-br
ev-br / mc_integrate_trivial.cc
Created May 28, 2013 09:19
A trivial Monte Carlo integrator. Just a quick-and-dirty example, nothing more.
/************** A simple MC integrator **************/
#include<iostream>
#include<boost/random.hpp>
using namespace std ;
double f(double); // to be integrated
double w(double); // probab. dens.
/************** A simple MC integrator **************/
#include<iostream>
#include<boost/random.hpp>
/************************************************
In order to calculate $\int f(x) dx$ we write
(all integrals are from 0 to $\infty$, but this doesn't matter much)
$$
\int f(x) dx = \int w(x)dx \frac{ \int f/w w(x)dx }{ \int w(x)dx } \;.
$$
import scipy.stats as stats
g = stats.gamma.pdf(8., 3.)
# no consequences for 'regular' distributions
print "\nregular @df=5:", stats.t.pdf(1., df=5)
print "\nregular @df=25:", stats.t.pdf(1., df=25)
print "\nregular @df=5:", stats.t.pdf(1., df=5)
#freeze
@ev-br
ev-br / gist:6447802
Created September 5, 2013 09:10
A slightly tweaked version of the check_moments script by josef-pkt: using the distributions' own `expect` method instead of the statsmodels' one. cf https://github.com/scipy/scipy/pull/2821
'''script to test expect and moments in distributions.stats method
not written as a test, prints results, renamed to prevent nose from running it
'''
import numpy as np
from scipy import stats
#from statsmodels.stats.moment_helpers import mnc2mvsk
@ev-br
ev-br / asympt.py
Last active December 26, 2015 06:49
Subclassing PPoly / BPoly to have custom out-of-bounds behavior. Eg: periodic boundary conditions, custom asymptotics.
from __future__ import division, print_function, absolute_import
import numpy as np
from scipy.interpolate import BPoly, PPoly
class MixinAsympt(object):
def _evaluate(self, x, nu, extrapolate, out):
super(MixinAsympt, self)._evaluate(x, nu, False, out)
below, above = x < self.x[0], x > self.x[-1]
@ev-br
ev-br / gist:7474570
Created November 14, 2013 21:23
low order Gram-Chandler / Edgeworth expansions, coefficients hardcoded
import numpy as np
from numpy.polynomial.hermite_e import HermiteE
from scipy.stats import norm, chi2
from scipy.misc import factorial
import matplotlib.pyplot as plt
def gram_chandler_series(cum):
"""Construct the 4th order Gram-Chandler expansion given cumulants.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ev-br
ev-br / gist:9081651
Created February 18, 2014 22:22
akima / pchip
# -*- coding: utf-8 -*-
# <nbformat>3.0</nbformat>
# <codecell>
from scipy.interpolate import pchip, Akima
import numpy as np
# <codecell>
@ev-br
ev-br / gist:9673884
Last active August 29, 2015 13:57
Hypoth 0 for OG
{
"metadata": {
"name": "Untitled1"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
@ev-br
ev-br / gist:d88bb691095894629efd
Created July 7, 2014 18:27
Therm limit, a la MZ & OG
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{