Skip to content

Instantly share code, notes, and snippets.

@matthieubulte
matthieubulte / Removing collinearity via SVD.ipynb
Last active May 26, 2019 15:57
Removing collinearity via SVD (maybe?)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@matthieubulte
matthieubulte / np_par.py
Last active February 2, 2019 04:07
Numpy parallelism
import multiprocessing as mp
import numpy as np
def multiprocessing(f, data, nproc):
chunks = np.array_split(data, nproc)
with mp.Pool(nproc) as ex:
res = ex.map(f, chunks)
return np.concatenate(list(res))
def dosomething(xs):
@matthieubulte
matthieubulte / Tutorial.ipynb
Last active June 2, 2019 18:18
MLSSMC Tutorial
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
def smc(M, steps, prior, potential, proposal_kernel, correction_steps=1, ess_ratio=2):
"""
smc(M, steps, prior, potential, proposal_kernel, correction_steps=1, ess_ratio=2)
Creates a particle approximation of a probability distribution using the Sequential
Monte Carlo (SMC) algorithm with Markov Chain Monte Carlo (MCMC) correction steps using
the Metropolis-Hastings algorithm.
Parameters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
brownian = @instr begin
σ ~ Beta(2, 3)
x = zeros(N)
for i = 2:N
x[i] ~ Normal(x[i-1], σ^2)
end
end
Function.operands = [];
Function.prototype.valueOf = function() {
Function.operands.push(this);
return 3;
}
function mkP(value) {
if (value instanceof Function) return value;
var ops = Function.operands;
Function.operands = [];
if (ops.length >= 2 && (value === 3 * ops.length)) {
function rk43(f, t, x, θ, τ, k₁)
p₁ = (θ) -> 1/6*θ*(6-9θ+4*θ^2)
p₂ = (θ) -> θ^2-2/3*θ^3
p₃ = (θ) -> θ^2-2/3*θ^3
p₄ = (θ) -> 1/6*θ^2*(-3+4θ)
k₂ = f(t + .5τ, x + τ*.5k₁)
k₃ = f(t + .5τ, x + τ*.5k₂)
k₄ = f(t + τ, x + τ*k₃)
k₅ = f(t + τ, x + (1/6)τ*(k₁ + 2k₂ + 2k₃ + k₄))
@matthieubulte
matthieubulte / main.jl
Last active January 23, 2021 17:20
answer to geophf concerns about the rk43 method
# Answer to: https://twitter.com/1HaskellADay/status/875063542784958465
#
# So the Initial Value Problem (IVP) you want to solve seems to be the following
#
# dy/dx = 3*exp(-x) - 0.4*y
# y(x_0) = y_0 with x_0 = 0 and y_0 = 5
#
# You then ask: what is the value of y when x = 3?
#
# This can be computed using the Runge Kutta method by feeding it