Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 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): |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 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.
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
brownian = @instr begin | |
σ ~ Beta(2, 3) | |
x = zeros(N) | |
for i = 2:N | |
x[i] ~ Normal(x[i-1], σ^2) | |
end | |
end |
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.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)) { |
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 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₄)) |
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
# 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 |